xmlhasher 1.0.4 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/test_helper.rb DELETED
@@ -1,22 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
-
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ])
11
- SimpleCov.start
12
-
13
- require 'test/unit'
14
- require 'xmlhasher'
15
-
16
- def fixture_path
17
- File.expand_path('../fixtures', __FILE__)
18
- end
19
-
20
- def fixture(file)
21
- File.new(fixture_path + '/' + file)
22
- end
@@ -1,250 +0,0 @@
1
- require 'test_helper'
2
-
3
- class XmlhasherTest < Test::Unit::TestCase
4
-
5
- def test_string_parsing_no_tranformation
6
- hash = {
7
- :InstitutionDetail =>
8
- {
9
- :address =>
10
- {
11
- :"ns2:address1" => "100 Main Street",
12
- :"ns2:city" => "Anytown",
13
- :"ns2:country" => "USA",
14
- :"ns2:postalCode" => "94043",
15
- :"ns2:state" => "CA"
16
- },
17
- :currencyCode => "ANG",
18
- :emailAddress => "CustomerCentralBank@intuit.com",
19
- :homeUrl => "http://www.example.com",
20
- :institutionId => "100000",
21
- :institutionName => "CCBank",
22
- :keys =>
23
- {
24
- :key =>
25
- [
26
- {
27
- :description => "2",
28
- :displayFlag => "true",
29
- :displayOrder => "1",
30
- :instructions => "2",
31
- :mask => "false",
32
- :name => "Banking Userid",
33
- :status => "Active",
34
- :valueLengthMax => "100",
35
- :valueLengthMin => "1"},
36
- {
37
- :description => "2",
38
- :displayFlag => "false",
39
- :displayOrder => "2",
40
- :instructions => "2",
41
- :mask => "true",
42
- :name => "Banking Password",
43
- :status => "Active",
44
- :valueLengthMax => "100",
45
- :valueLengthMin => "1"
46
- }
47
- ]
48
- },
49
- :locale => {
50
- :language => "en"
51
- },
52
- :phoneNumber => "123-456-7890",
53
- :xmlns => "http://schema.intuit.com/platform/fdatafeed/account/v1",
54
- :"xmlns:ns2" => "http://schema.intuit.com/platform/fdatafeed/common/v1"
55
- },
56
- }
57
- result = XmlHasher::Parser.new.parse(fixture('institution.xml').read)
58
- assert_equal hash, result
59
- end
60
-
61
- def test_string_parsing_with_tranformation
62
- options = {
63
- :snakecase => true,
64
- :ignore_namespaces => true
65
- }
66
- hash = {
67
- :institution_detail =>
68
- {
69
- :address =>
70
- {
71
- :address1 => "100 Main Street",
72
- :city => "Anytown",
73
- :country => "USA",
74
- :postal_code => "94043",
75
- :state => "CA"
76
- },
77
- :currency_code => "ANG",
78
- :email_address => "CustomerCentralBank@intuit.com",
79
- :home_url => "http://www.example.com",
80
- :institution_id => "100000",
81
- :institution_name => "CCBank",
82
- :keys =>
83
- {
84
- :key =>
85
- [
86
- {
87
- :description => "2",
88
- :display_flag => "true",
89
- :display_order => "1",
90
- :instructions => "2",
91
- :mask => "false",
92
- :name => "Banking Userid",
93
- :status => "Active",
94
- :value_length_max => "100",
95
- :value_length_min => "1"},
96
- {
97
- :description => "2",
98
- :display_flag => "false",
99
- :display_order => "2",
100
- :instructions => "2",
101
- :mask => "true",
102
- :name => "Banking Password",
103
- :status => "Active",
104
- :value_length_max => "100",
105
- :value_length_min => "1"
106
- }
107
- ]
108
- },
109
- :locale =>
110
- {
111
- :language => "en"
112
- },
113
- :phone_number => "123-456-7890"
114
- }
115
- }
116
- result = XmlHasher::Parser.new(options).parse(fixture('institution.xml').read)
117
- assert_equal hash, result
118
- end
119
-
120
- def test_stream_parsing_with_tranformation
121
- options = {
122
- :snakecase => true,
123
- :ignore_namespaces => true
124
- }
125
- hash = {:institution_detail =>
126
- {:address =>
127
- {:address1 => "100 Main Street",
128
- :city => "Anytown",
129
- :country => "USA",
130
- :postal_code => "94043",
131
- :state => "CA"},
132
- :currency_code => "ANG",
133
- :email_address => "CustomerCentralBank@intuit.com",
134
- :home_url => "http://www.example.com",
135
- :institution_id => "100000",
136
- :institution_name => "CCBank",
137
- :keys =>
138
- {:key =>
139
- [{:description => "2",
140
- :display_flag => "true",
141
- :display_order => "1",
142
- :instructions => "2",
143
- :mask => "false",
144
- :name => "Banking Userid",
145
- :status => "Active",
146
- :value_length_max => "100",
147
- :value_length_min => "1"},
148
- {:description => "2",
149
- :display_flag => "false",
150
- :display_order => "2",
151
- :instructions => "2",
152
- :mask => "true",
153
- :name => "Banking Password",
154
- :status => "Active",
155
- :value_length_max => "100",
156
- :value_length_min => "1"}]},
157
- :locale => {:language => "en"},
158
- :phone_number => "123-456-7890"}}
159
- result = XmlHasher::Parser.new(options).parse(fixture('institution.xml'))
160
- assert_equal hash, result
161
- end
162
-
163
- def test_escaped_characters
164
- xml = %[<tag>&amp;</tag>]
165
- expected = {:tag => '&'}
166
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
167
- end
168
-
169
- def test_simple_tag
170
- xml = %[<tag>content</tag>]
171
- expected = {:tag => 'content'}
172
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
173
- end
174
-
175
- def test_ignore_attributes_if_has_content
176
- xml = %[<tag a1='1' a2='2'>content</tag>]
177
- expected = {:tag => 'content'}
178
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
179
- end
180
-
181
- def test_attributes
182
- xml = %[<tag a1='1' a2='2'></tag>]
183
- expected = {:tag => {:a1 => '1', :a2 => '2'}}
184
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
185
- end
186
-
187
- def test_attributes_and_children
188
- xml = %[<tag a1='1' a2='2'><tag2>content</tag2></tag>]
189
- expected = {:tag => {:a1 => '1', :a2 => '2', :tag2 => 'content'}}
190
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
191
- end
192
-
193
- def test_array_detection
194
- xml = %[<tag><tag2 attr='1' /><tag2 attr='2' /></tag>]
195
- expected = {:tag => {:tag2 => [{:attr => '1'}, {:attr => '2'}]}}
196
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
197
- end
198
-
199
- def test_array_detection_with_mixed_children
200
- xml = %[<tag><tag2 attr='1' /><tag3>content</tag3><tag2 attr='2' /></tag>]
201
- expected = {:tag => {:tag2 => [{:attr => '1'}, {:attr => '2'}], :tag3 => 'content'}}
202
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
203
- end
204
-
205
- def test_single_child
206
- xml = %[<tag><tag2 attr='1' /></tag>]
207
- expected = {:tag => {:tag2 => {:attr => '1'}}}
208
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
209
- end
210
-
211
- def test_snakecasing_attributes
212
- options = {
213
- :snakecase => true,
214
- }
215
- xml = %[<tag attr-1='1'></tag>]
216
- expected = {:tag => {:attr_1 => '1'}}
217
- assert_equal expected, XmlHasher::Parser.new(options).parse(xml)
218
- end
219
-
220
- def test_snakecasing_elements
221
- options = {
222
- :snakecase => true,
223
- }
224
- xml = %[<my-tag><MyTag2>content</MyTag2></my-tag>]
225
- expected = {:my_tag => {:my_tag2 => 'content'}}
226
- assert_equal expected, XmlHasher::Parser.new(options).parse(xml)
227
- end
228
-
229
- def test_snakecasing_string_elements
230
- options = {
231
- :snakecase => true,
232
- :string_keys => true
233
- }
234
- xml = %[<my-tag><MyTag2>content</MyTag2></my-tag>]
235
- expected = {'my_tag' => {'my_tag2' => 'content'}}
236
- assert_equal expected, XmlHasher::Parser.new(options).parse(xml)
237
- end
238
-
239
- def test_empty_tag
240
- xml = %[<tag></tag>]
241
- expected = {:tag => nil}
242
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
243
- end
244
-
245
- def test_cdata_value
246
- xml = %[<title><![CDATA[Midhir uploaded a photo.]]></title>]
247
- expected = {:title => "Midhir uploaded a photo."}
248
- assert_equal expected, XmlHasher::Parser.new.parse(xml)
249
- end
250
- end
@@ -1,41 +0,0 @@
1
- require 'test_helper'
2
-
3
- class XmlhasherTest < Test::Unit::TestCase
4
-
5
- def test_configure_settings_all_on
6
- configurable = XmlHasher.configure do |config|
7
- config.snakecase = true
8
- config.ignore_namespaces = true
9
- config.string_keys = true
10
- end
11
- assert_equal true, configurable.instance_variable_get(:'@snakecase')
12
- assert_equal true, configurable.instance_variable_get(:'@ignore_namespaces')
13
- assert_equal true, configurable.instance_variable_get(:'@string_keys')
14
- end
15
-
16
- def test_configure_settings_all_off
17
- configurable = XmlHasher.configure do |config|
18
- config.snakecase = false
19
- config.ignore_namespaces = false
20
- config.string_keys = false
21
- end
22
- assert_equal false, configurable.instance_variable_get(:'@snakecase')
23
- assert_equal false, configurable.instance_variable_get(:'@ignore_namespaces')
24
- assert_equal false, configurable.instance_variable_get(:'@string_keys')
25
- end
26
-
27
- def test_parser
28
- parser = XmlHasher.parser
29
- assert_equal XmlHasher::Parser, parser.class
30
- result = parser.parse(fixture('institution.xml').read)
31
- assert_not_empty result
32
- assert_equal Hash, result.class
33
- end
34
-
35
- def test_parse
36
- result = XmlHasher.parse(fixture('institution.xml').read)
37
- assert_not_empty result
38
- assert_equal Hash, result.class
39
- end
40
-
41
- end