summaryrefslogtreecommitdiffhomepage
path: root/test/workbook/tc_defined_name.rb
diff options
context:
space:
mode:
authorJonathan Tron <[email protected]>2014-02-26 14:14:38 +0100
committerJonathan Tron <[email protected]>2014-02-26 14:14:38 +0100
commit4400e233c0d0ab57652619a0d3eaa0cec4e9c358 (patch)
tree957c211991bba2ffd5d99b77141b1cb03b5317df /test/workbook/tc_defined_name.rb
parent9f8b707ff24b97bca7701e4f361e055fe41e5fd0 (diff)
downloadcaxlsx-4400e233c0d0ab57652619a0d3eaa0cec4e9c358.tar.gz
caxlsx-4400e233c0d0ab57652619a0d3eaa0cec4e9c358.zip
Do not put Axlsx::DefinedName#name in serialized_attributes (fixes #285)
When using serialized_attributes both attribute's name and value are camelcased, in `Axlsx::DefinedName` the values starts with `_xmln` which is then transformed in `Xmln`. The fix proposed on #285 does not work because then other `Axlsx::DefinedName` attributes name are no more camelcased (`localSheetId` become `local_sheet_id` for instance). As proposed by @randym in #285, this commit only make a special case of the name and let the other attributes go through serialized_attributes. Adding a test on it revealed a wrong test which would have catched similar error but was not because of value returned by `doc.xpath`.
Diffstat (limited to 'test/workbook/tc_defined_name.rb')
-rw-r--r--test/workbook/tc_defined_name.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/test/workbook/tc_defined_name.rb b/test/workbook/tc_defined_name.rb
index b16b3346..4da31eb8 100644
--- a/test/workbook/tc_defined_name.rb
+++ b/test/workbook/tc_defined_name.rb
@@ -1,14 +1,14 @@
require 'tc_helper'
class TestDefinedNames < Test::Unit::TestCase
- def setup
+ def setup
@dn = Axlsx::DefinedName.new('Sheet1!A1:A1')
end
def test_initialize
assert_equal('Sheet1!A1:A1', @dn.formula)
end
-
+
def test_string_attributes
%w(short_cut_key status_bar help description custom_menu comment).each do |attr|
assert_raise(ArgumentError, 'only strings allowed in string attributes') { @dn.send("#{attr}=", 1) }
@@ -29,13 +29,21 @@ class TestDefinedNames < Test::Unit::TestCase
assert_nothing_raised { @dn.local_sheet_id = 1 }
end
+ def test_do_not_camelcase_value_for_name
+ @dn.name = '_xlnm._FilterDatabase'
+ doc = Nokogiri::XML(@dn.to_xml_string)
+ assert_equal(doc.xpath("//definedName[@name='_xlnm._FilterDatabase']").size, 1)
+ assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
+ end
+
def test_to_xml_string
assert_raise(ArgumentError, 'name is required for serialization') { @dn.to_xml_string }
@dn.name = '_xlnm.Print_Titles'
@dn.hidden = true
doc = Nokogiri::XML(@dn.to_xml_string)
- assert(doc.xpath("//definedName[@name='_xlnm.Print_Titles']"))
- assert(doc.xpath("//definedName[@hidden='true']"))
+ assert_equal(doc.xpath("//definedName[@name='_xlnm.Print_Titles']").size, 1)
+ assert_equal(doc.xpath("//definedName[@hidden='true']").size, 1)
assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
end
+
end