gyoku 1.1.1 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdaf80a00de09a2fcb18c9dd5ef5b0bcd1491437
4
- data.tar.gz: 8ef2ffc7a90fac372189b3968aed3003bde0f7c4
3
+ metadata.gz: 5907f34dc0f3b33599c65e59b4fdaa4ccf1878c0
4
+ data.tar.gz: 3929d2f06c095e3375b37b88822afef27cfee219
5
5
  SHA512:
6
- metadata.gz: 26ed05f6ae3fde1a51daf47727454a8b279d5041846662608229a1ea2e82c7a0952101fb0a7828e1878df0df23e675001928d0fbdb702d657d242cb4f1369603
7
- data.tar.gz: ccf273c1e402883e71570be64ad57ab7ea0a46e0c8abf7b22d952785a35baa49b0c6fbd6c0db1e6d8d701e711fcec5a0f206c5530d7eb157a3aa40bca5324280
6
+ metadata.gz: 8aa20c9179c8283096c66a64c10ca3b2802ac6e316de1118c0ef77c6b5f331622592fc4ba6d69d5e7e16b89d4d1eb03666140f4d32e8c0b1d68328bf743cdc3c
7
+ data.tar.gz: a0e9cdb56e8d91767e697b199185041928441f832c17c350dbcd523216c7e22a3f835f2cd4474e1a7bef8ee18957d57cdb69688fb29e1d106847e25c181e73e1
@@ -4,5 +4,6 @@ rvm:
4
4
  - 1.9.2
5
5
  - 1.9.3
6
6
  - 2.0.0
7
+ - 2.1
7
8
  - jruby-19mode
8
- - rbx
9
+ - rbx-2
@@ -1,3 +1,7 @@
1
+ ## 1.2.0 (2014-09-18)
2
+
3
+ * Feature: [#44](https://github.com/savonrb/gyoku/pull/44) support for sorting via :order! with a string key
4
+
1
5
  ## 1.1.1 (2014-01-02)
2
6
 
3
7
  * Feature: [#38](https://github.com/savonrb/gyoku/pull/38) support for building nested Arrays
@@ -66,7 +66,7 @@ module Gyoku
66
66
  # Defaults to return the actual keys of the Hash if no :order! key could be found.
67
67
  # Raises an ArgumentError in case the :order! Array does not match the Hash keys.
68
68
  def self.order(hash)
69
- order = hash[:order!]
69
+ order = hash[:order!] || hash.delete('order!')
70
70
  hash_without_order = hash.reject { |key, value| key == :order! }
71
71
  order = hash_without_order.keys unless order.kind_of? ::Array
72
72
 
@@ -1,5 +1,5 @@
1
1
  module Gyoku
2
2
 
3
- VERSION = "1.1.1"
3
+ VERSION = "1.2.0"
4
4
 
5
5
  end
@@ -21,7 +21,7 @@ module Gyoku
21
21
  xml_key = xml_key.split(":").last
22
22
  end
23
23
 
24
- xml_key = key_converter(options).call(xml_key) if Symbol === key
24
+ xml_key = key_converter(options, xml_key).call(xml_key) if Symbol === key
25
25
 
26
26
  if !unqualified && qualify?(options) && !xml_key.include?(":")
27
27
  xml_key = "#{options[:namespace]}:#{xml_key}"
@@ -33,8 +33,17 @@ module Gyoku
33
33
  private
34
34
 
35
35
  # Returns the formula for converting Symbol keys.
36
- def key_converter(options)
37
- key_converter = options[:key_converter] || :lower_camelcase
36
+ def key_converter(options, xml_key)
37
+ defined_key = options[:key_to_convert]
38
+ if (defined_key != nil) && (defined_key == xml_key)
39
+ key_converter = options[:key_converter]
40
+ elsif defined_key != nil
41
+ key_converter = :lower_camelcase
42
+ elsif (options[:except] == xml_key)
43
+ key_converter = :lower_camelcase
44
+ else
45
+ key_converter = options[:key_converter] || :lower_camelcase
46
+ end
38
47
  FORMULAS[key_converter]
39
48
  end
40
49
 
@@ -7,56 +7,56 @@ describe Gyoku::Array do
7
7
  array = [{ :name => "adam" }, { :name => "eve" }]
8
8
  result = "<user><name>adam</name></user><user><name>eve</name></user>"
9
9
 
10
- to_xml(array, "user").should == result
10
+ expect(to_xml(array, "user")).to eq(result)
11
11
  end
12
12
 
13
13
  it "returns the XML for an Array of different Objects" do
14
14
  array = [:symbol, "string", 123]
15
15
  result = "<value>symbol</value><value>string</value><value>123</value>"
16
16
 
17
- to_xml(array, "value").should == result
17
+ expect(to_xml(array, "value")).to eq(result)
18
18
  end
19
19
 
20
20
  it "defaults to escape special characters" do
21
21
  array = ["<tag />", "adam & eve"]
22
22
  result = "<value>&lt;tag /&gt;</value><value>adam &amp; eve</value>"
23
23
 
24
- to_xml(array, "value").should == result
24
+ expect(to_xml(array, "value")).to eq(result)
25
25
  end
26
26
 
27
27
  it "does not escape special characters when told to" do
28
28
  array = ["<tag />", "adam & eve"]
29
29
  result = "<value><tag /></value><value>adam & eve</value>"
30
30
 
31
- to_xml(array, "value", false).should == result
31
+ expect(to_xml(array, "value", false)).to eq(result)
32
32
  end
33
33
 
34
34
  it "adds attributes to a given tag" do
35
35
  array = ["adam", "eve"]
36
36
  result = '<value active="true">adam</value><value active="true">eve</value>'
37
37
 
38
- to_xml(array, "value", :escape_xml, :active => true).should == result
38
+ expect(to_xml(array, "value", :escape_xml, :active => true)).to eq(result)
39
39
  end
40
40
 
41
41
  it "adds attributes to duplicate tags" do
42
42
  array = ["adam", "eve"]
43
43
  result = '<value id="1">adam</value><value id="2">eve</value>'
44
44
 
45
- to_xml(array, "value", :escape_xml, :id => [1, 2]).should == result
45
+ expect(to_xml(array, "value", :escape_xml, :id => [1, 2])).to eq(result)
46
46
  end
47
47
 
48
48
  it "skips attribute for element without attributes if there are fewer attributes than elements" do
49
49
  array = ["adam", "eve", "serpent"]
50
50
  result = '<value id="1">adam</value><value id="2">eve</value><value>serpent</value>'
51
51
 
52
- to_xml(array, "value", :escape_xml, :id => [1, 2]).should == result
52
+ expect(to_xml(array, "value", :escape_xml, :id => [1, 2])).to eq(result)
53
53
  end
54
54
 
55
55
  it "handles nested Arrays" do
56
56
  array = [["one", "two"]]
57
57
  result = "<value><element>one</element><element>two</element></value>"
58
58
 
59
- to_xml(array, "value").should == result
59
+ expect(to_xml(array, "value")).to eq(result)
60
60
  end
61
61
  end
62
62
 
@@ -5,41 +5,66 @@ describe Gyoku::Hash do
5
5
  describe ".to_xml" do
6
6
  describe "returns SOAP request compatible XML" do
7
7
  it "for a simple Hash" do
8
- to_xml(:some => "user").should == "<some>user</some>"
8
+ expect(to_xml(:some => "user")).to eq("<some>user</some>")
9
9
  end
10
10
 
11
11
  it "for a nested Hash" do
12
- to_xml(:some => { :new => "user" }).should == "<some><new>user</new></some>"
12
+ expect(to_xml(:some => { :new => "user" })).to eq("<some><new>user</new></some>")
13
+ end
14
+
15
+ context "with key_converter" do
16
+ it "expect all keys change" do
17
+ expect(to_xml({:some => { :new => "user" }}, {key_converter: :camelcase})).to eq("<Some><New>user</New></Some>")
18
+ end
19
+
20
+ it "and key_to_convert option should change only key" do
21
+ hash = {:some => { :new => "user", :age => 20 }}
22
+ options = {key_converter: :camelcase, key_to_convert: "some"}
23
+ result = "<Some><new>user</new><age>20</age></Some>"
24
+ expect(to_xml(hash, options)).to eq(result)
25
+
26
+ hash = {:some => { :new => "user", :age => 20 }}
27
+ options = {key_converter: :camelcase, key_to_convert: "new"}
28
+ result = "<some><New>user</New><age>20</age></some>"
29
+ expect(to_xml(hash, options)).to eq(result)
30
+ end
31
+
32
+ it "with except option, dont convert this key" do
33
+ hash = {:some => { :new => "user", :age => 20 }}
34
+ options = {key_converter: :camelcase, except: "some"}
35
+ result = "<some><New>user</New><Age>20</Age></some>"
36
+ expect(to_xml(hash, options)).to eq(result)
37
+ end
13
38
  end
14
39
 
15
40
  it "for a Hash with multiple keys" do
16
- to_xml(:all => "users", :before => "whatever").should include(
41
+ expect(to_xml(:all => "users", :before => "whatever")).to include(
17
42
  "<all>users</all>",
18
43
  "<before>whatever</before>"
19
44
  )
20
45
  end
21
46
 
22
47
  it "for a Hash containing an Array" do
23
- to_xml(:some => ["user", "gorilla"]).should == "<some>user</some><some>gorilla</some>"
48
+ expect(to_xml(:some => ["user", "gorilla"])).to eq("<some>user</some><some>gorilla</some>")
24
49
  end
25
50
 
26
51
  it "for a Hash containing an Array of Hashes" do
27
- to_xml(:some => [{ :new => "user" }, { :old => "gorilla" }]).
28
- should == "<some><new>user</new></some><some><old>gorilla</old></some>"
52
+ expect(to_xml(:some => [{ :new => "user" }, { :old => "gorilla" }])).
53
+ to eq("<some><new>user</new></some><some><old>gorilla</old></some>")
29
54
  end
30
55
  end
31
56
 
32
57
  it "converts Hash key Symbols to lowerCamelCase" do
33
- to_xml(:find_or_create => "user").should == "<findOrCreate>user</findOrCreate>"
58
+ expect(to_xml(:find_or_create => "user")).to eq("<findOrCreate>user</findOrCreate>")
34
59
  end
35
60
 
36
61
  it "does not convert Hash key Strings" do
37
- to_xml("find_or_create" => "user").should == "<find_or_create>user</find_or_create>"
62
+ expect(to_xml("find_or_create" => "user")).to eq("<find_or_create>user</find_or_create>")
38
63
  end
39
64
 
40
65
  it "converts DateTime objects to xs:dateTime compliant Strings" do
41
- to_xml(:before => DateTime.new(2012, 03, 22, 16, 22, 33)).
42
- should == "<before>2012-03-22T16:22:33+00:00</before>"
66
+ expect(to_xml(:before => DateTime.new(2012, 03, 22, 16, 22, 33))).
67
+ to eq("<before>2012-03-22T16:22:33+00:00</before>")
43
68
  end
44
69
 
45
70
  it "converts Objects responding to to_datetime to xs:dateTime compliant Strings" do
@@ -48,7 +73,7 @@ describe Gyoku::Hash do
48
73
  DateTime.new(2012, 03, 22, 16, 22, 33)
49
74
  end
50
75
 
51
- to_xml(:before => singleton).should == "<before>2012-03-22T16:22:33+00:00</before>"
76
+ expect(to_xml(:before => singleton)).to eq("<before>2012-03-22T16:22:33+00:00</before>")
52
77
  end
53
78
 
54
79
  it "calls to_s on Strings even if they respond to to_datetime" do
@@ -57,78 +82,94 @@ describe Gyoku::Hash do
57
82
  DateTime.new(2012, 03, 22, 16, 22, 33)
58
83
  end
59
84
 
60
- to_xml(:name => singleton).should == "<name>gorilla</name>"
85
+ expect(to_xml(:name => singleton)).to eq("<name>gorilla</name>")
61
86
  end
62
87
 
63
88
  it "properly serializes nil values" do
64
- to_xml(:some => nil).should == '<some xsi:nil="true"/>'
89
+ expect(to_xml(:some => nil)).to eq('<some xsi:nil="true"/>')
65
90
  end
66
91
 
67
92
  it "creates self-closing tags for Hash keys ending with a forward slash" do
68
- to_xml("self-closing/" => nil).should == '<self-closing/>'
93
+ expect(to_xml("self-closing/" => nil)).to eq('<self-closing/>')
69
94
  end
70
95
 
71
96
  it "calls to_s on any other Object" do
72
97
  [666, true, false].each do |object|
73
- to_xml(:some => object).should == "<some>#{object}</some>"
98
+ expect(to_xml(:some => object)).to eq("<some>#{object}</some>")
74
99
  end
75
100
  end
76
101
 
77
102
  it "defaults to escape special characters" do
78
103
  result = to_xml(:some => { :nested => "<tag />" }, :tag => "<tag />")
79
- result.should include("<tag>&lt;tag /&gt;</tag>")
80
- result.should include("<some><nested>&lt;tag /&gt;</nested></some>")
104
+ expect(result).to include("<tag>&lt;tag /&gt;</tag>")
105
+ expect(result).to include("<some><nested>&lt;tag /&gt;</nested></some>")
81
106
  end
82
107
 
83
108
  it "does not escape special characters for keys marked with an exclamation mark" do
84
109
  result = to_xml(:some => { :nested! => "<tag />" }, :tag! => "<tag />")
85
- result.should include("<tag><tag /></tag>")
86
- result.should include("<some><nested><tag /></nested></some>")
110
+ expect(result).to include("<tag><tag /></tag>")
111
+ expect(result).to include("<some><nested><tag /></nested></some>")
87
112
  end
88
113
 
89
114
  it "preserves the order of Hash keys and values specified through :order!" do
90
115
  hash = { :find_user => { :name => "Lucy", :id => 666, :order! => [:id, :name] } }
91
116
  result = "<findUser><id>666</id><name>Lucy</name></findUser>"
92
- to_xml(hash).should == result
117
+ expect(to_xml(hash)).to eq(result)
93
118
 
94
119
  hash = { :find_user => { :mname => "in the", :lname => "Sky", :fname => "Lucy", :order! => [:fname, :mname, :lname] } }
95
120
  result = "<findUser><fname>Lucy</fname><mname>in the</mname><lname>Sky</lname></findUser>"
96
- to_xml(hash).should == result
121
+ expect(to_xml(hash)).to eq(result)
122
+ end
123
+
124
+ it "preserves the order of Hash keys and values specified through 'order!' (as a string key)" do
125
+ hash = { :find_user => { :name => "Lucy", :id => 666, 'order!' => [:id, :name] } }
126
+ result = "<findUser><id>666</id><name>Lucy</name></findUser>"
127
+ expect(to_xml(hash)).to eq(result)
128
+
129
+ hash = { :find_user => { :mname => "in the", :lname => "Sky", :fname => "Lucy", 'order!' => [:fname, :mname, :lname] } }
130
+ result = "<findUser><fname>Lucy</fname><mname>in the</mname><lname>Sky</lname></findUser>"
131
+ expect(to_xml(hash)).to eq(result)
132
+ end
133
+
134
+ it "uses :order! symbol values for ordering but leaves the string key 'order!' if both are present" do
135
+ hash = { :find_user => { :name => "Lucy", :id => 666, 'order!' => 'value', :order! => [:id, :name, 'order!'] } }
136
+ result = "<findUser><id>666</id><name>Lucy</name><order>value</order></findUser>"
137
+ expect(to_xml(hash)).to eq(result)
97
138
  end
98
139
 
99
140
  it "raises if the :order! Array is missing Hash keys" do
100
141
  hash = { :name => "Lucy", :id => 666, :order! => [:name] }
101
- lambda { to_xml(hash) }.should raise_error(ArgumentError, "Missing elements in :order! [:id]")
142
+ expect { to_xml(hash) }.to raise_error(ArgumentError, "Missing elements in :order! [:id]")
102
143
  end
103
144
 
104
145
  it "raises if the :order! Array contains missing Hash keys" do
105
146
  hash = { :by_name => { :first_name => "Lucy", :last_name => "Sky", :order! => [:first_name, :middle_name, :last_name] } }
106
- lambda { to_xml(hash) }.should raise_error(ArgumentError, "Spurious elements in :order! [:middle_name]")
147
+ expect { to_xml(hash) }.to raise_error(ArgumentError, "Spurious elements in :order! [:middle_name]")
107
148
  end
108
149
 
109
150
  it "adds attributes to Hash keys specified through :attributes!" do
110
151
  hash = { :find_user => { :person => "Lucy", :attributes! => { :person => { :id => 666 } } } }
111
152
  result = '<findUser><person id="666">Lucy</person></findUser>'
112
- to_xml(hash).should == result
153
+ expect(to_xml(hash)).to eq(result)
113
154
 
114
155
  hash = { :find_user => { :person => "Lucy", :attributes! => { :person => { :id => 666, :city => "Hamburg" } } } }
115
- to_xml(hash).should include('id="666"', 'city="Hamburg"')
156
+ expect(to_xml(hash)).to include('id="666"', 'city="Hamburg"')
116
157
  end
117
158
 
118
159
  it "adds attributes to duplicate Hash keys specified through :attributes!" do
119
160
  hash = { :find_user => { :person => ["Lucy", "Anna"], :attributes! => { :person => { :id => [1, 3] } } } }
120
161
  result = '<findUser><person id="1">Lucy</person><person id="3">Anna</person></findUser>'
121
- to_xml(hash).should == result
162
+ expect(to_xml(hash)).to eq(result)
122
163
 
123
164
  hash = { :find_user => { :person => ["Lucy", "Anna"], :attributes! => { :person => { :active => "true" } } } }
124
165
  result = '<findUser><person active="true">Lucy</person><person active="true">Anna</person></findUser>'
125
- to_xml(hash).should == result
166
+ expect(to_xml(hash)).to eq(result)
126
167
  end
127
168
 
128
169
  it "skips attribute for element without attributes if there are fewer attributes than elements" do
129
170
  hash = { :find_user => { :person => ["Lucy", "Anna", "Beth"], :attributes! => { :person => { :id => [1, 3] } } } }
130
171
  result = '<findUser><person id="1">Lucy</person><person id="3">Anna</person><person>Beth</person></findUser>'
131
- to_xml(hash).should == result
172
+ expect(to_xml(hash)).to eq(result)
132
173
  end
133
174
 
134
175
  it "adds attributes to self-closing tags" do
@@ -137,7 +178,7 @@ describe Gyoku::Hash do
137
178
  :attributes! => { "category/" => { :id => 1 } }
138
179
  }
139
180
 
140
- to_xml(hash).should == '<category id="1"/>'
181
+ expect(to_xml(hash)).to eq('<category id="1"/>')
141
182
  end
142
183
 
143
184
  it "recognizes @attribute => value along :attributes!" do
@@ -147,7 +188,7 @@ describe Gyoku::Hash do
147
188
  :@id => 1
148
189
  }
149
190
  }
150
- to_xml(hash).should == '<category id="1">users</category>'
191
+ expect(to_xml(hash)).to eq('<category id="1">users</category>')
151
192
  end
152
193
 
153
194
  it "recognizes @attribute => value along :attributes! in selfclosed tags" do
@@ -156,7 +197,7 @@ describe Gyoku::Hash do
156
197
  :@id => 1
157
198
  }
158
199
  }
159
- to_xml(hash).should == '<category id="1"/>'
200
+ expect(to_xml(hash)).to eq('<category id="1"/>')
160
201
  end
161
202
 
162
203
  it ":@attribute => value takes over :attributes!" do
@@ -172,7 +213,7 @@ describe Gyoku::Hash do
172
213
  }
173
214
  }
174
215
  # attribute order is undefined
175
- ['<category id="1" type="admins"/>','<category type="admins" id="1"/>'].should include to_xml(hash)
216
+ expect(['<category id="1" type="admins"/>','<category type="admins" id="1"/>']).to include to_xml(hash)
176
217
 
177
218
  # with symbols
178
219
  hash = {
@@ -186,7 +227,7 @@ describe Gyoku::Hash do
186
227
  }
187
228
  }
188
229
  }
189
- ['<category id="1" type="admins"/>','<category type="admins" id="1"/>'].should include to_xml(hash)
230
+ expect(['<category id="1" type="admins"/>','<category type="admins" id="1"/>']).to include to_xml(hash)
190
231
  end
191
232
 
192
233
  it "recognizes :content! => value as tag content" do
@@ -195,7 +236,7 @@ describe Gyoku::Hash do
195
236
  :content! => "users"
196
237
  }
197
238
  }
198
- to_xml(hash).should == "<category>users</category>"
239
+ expect(to_xml(hash)).to eq("<category>users</category>")
199
240
  end
200
241
 
201
242
  it "recognizes :content! => value as tag content with value Fixnum" do
@@ -204,7 +245,7 @@ describe Gyoku::Hash do
204
245
  :content! => 666
205
246
  }
206
247
  }
207
- to_xml(hash).should == "<category>666</category>"
248
+ expect(to_xml(hash)).to eq("<category>666</category>")
208
249
  end
209
250
 
210
251
  it "recognizes :content! => value as tag content with value true" do
@@ -213,7 +254,7 @@ describe Gyoku::Hash do
213
254
  :content! => true
214
255
  }
215
256
  }
216
- to_xml(hash).should == "<category>true</category>"
257
+ expect(to_xml(hash)).to eq("<category>true</category>")
217
258
  end
218
259
 
219
260
  it "recognizes :content! => value as tag content with value false" do
@@ -222,7 +263,7 @@ describe Gyoku::Hash do
222
263
  :content! => false
223
264
  }
224
265
  }
225
- to_xml(hash).should == "<category>false</category>"
266
+ expect(to_xml(hash)).to eq("<category>false</category>")
226
267
  end
227
268
 
228
269
  it "recognizes :content! => value as tag content with value DateTime" do
@@ -231,7 +272,7 @@ describe Gyoku::Hash do
231
272
  :content! => DateTime.new(2012, 03, 22, 16, 22, 33)
232
273
  }
233
274
  }
234
- to_xml(hash).should == "<before>2012-03-22T16:22:33+00:00</before>"
275
+ expect(to_xml(hash)).to eq("<before>2012-03-22T16:22:33+00:00</before>")
235
276
  end
236
277
 
237
278
  it "ignores :content! if self-closing mark present" do
@@ -240,14 +281,14 @@ describe Gyoku::Hash do
240
281
  :content! => "users"
241
282
  }
242
283
  }
243
- to_xml(hash).should == "<category/>"
284
+ expect(to_xml(hash)).to eq("<category/>")
244
285
  end
245
286
 
246
287
  it "recognizes array of attributes" do
247
288
  hash = {
248
289
  "category" => [{:@name => 'one'}, {:@name => 'two'}]
249
290
  }
250
- to_xml(hash).should == '<category name="one"></category><category name="two"></category>'
291
+ expect(to_xml(hash)).to eq('<category name="one"></category><category name="two"></category>')
251
292
 
252
293
  # issue #31.
253
294
  hash = {
@@ -255,7 +296,7 @@ describe Gyoku::Hash do
255
296
  'foo' => { :@foo => 'foo' },
256
297
  'bar' => { :@bar => 'bar', 'baz' => { } },
257
298
  }
258
- to_xml(hash).should == '<foo foo="foo"></foo><bar bar="bar"><baz></baz></bar>'
299
+ expect(to_xml(hash)).to eq('<foo foo="foo"></foo><bar bar="bar"><baz></baz></bar>')
259
300
  end
260
301
 
261
302
  it "recognizes array of attributes with content in each" do
@@ -263,10 +304,10 @@ describe Gyoku::Hash do
263
304
  "foo" => [{:@name => "bar", :content! => 'gyoku'}, {:@name => "baz", :@some => "attr", :content! => 'rocks!'}]
264
305
  }
265
306
 
266
- [
307
+ expect([
267
308
  '<foo name="bar">gyoku</foo><foo name="baz" some="attr">rocks!</foo>',
268
309
  '<foo name="bar">gyoku</foo><foo some="attr" name="baz">rocks!</foo>'
269
- ].should include to_xml(hash)
310
+ ]).to include to_xml(hash)
270
311
  end
271
312
 
272
313
  it "recognizes array of attributes but ignores content in each if selfclosing" do
@@ -274,17 +315,17 @@ describe Gyoku::Hash do
274
315
  "foo/" => [{:@name => "bar", :content! => 'gyoku'}, {:@name => "baz", :@some => "attr", :content! => 'rocks!'}]
275
316
  }
276
317
 
277
- [
318
+ expect([
278
319
  '<foo name="bar"/><foo name="baz" some="attr"/>',
279
320
  '<foo name="bar"/><foo some="attr" name="baz"/>'
280
- ].should include to_xml(hash)
321
+ ]).to include to_xml(hash)
281
322
  end
282
323
 
283
324
  it "recognizes array of attributes with selfclosing tag" do
284
325
  hash = {
285
326
  "category/" => [{:@name => 'one'}, {:@name => 'two'}]
286
327
  }
287
- to_xml(hash).should == '<category name="one"/><category name="two"/>'
328
+ expect(to_xml(hash)).to eq('<category name="one"/><category name="two"/>')
288
329
  end
289
330
 
290
331
  context "with :element_form_default set to :qualified and a :namespace" do
@@ -292,7 +333,7 @@ describe Gyoku::Hash do
292
333
  hash = { :first => { "first_name" => "Lucy" }, ":second" => { :":first_name" => "Anna" }, "v2:third" => { "v2:firstName" => "Danie" } }
293
334
  result = to_xml hash, :element_form_default => :qualified, :namespace => :v1
294
335
 
295
- result.should include(
336
+ expect(result).to include(
296
337
  "<v1:first><v1:first_name>Lucy</v1:first_name></v1:first>",
297
338
  "<second><firstName>Anna</firstName></second>",
298
339
  "<v2:third><v2:firstName>Danie</v2:firstName></v2:third>"
@@ -303,7 +344,7 @@ describe Gyoku::Hash do
303
344
  hash = { :array => [ :first => "Lucy", :second => "Anna" ]}
304
345
  result = to_xml hash, :element_form_default => :qualified, :namespace => :v1
305
346
 
306
- result.should include("<v1:array>", "<v1:first>Lucy</v1:first>", "<v1:second>Anna</v1:second>")
347
+ expect(result).to include("<v1:array>", "<v1:first>Lucy</v1:first>", "<v1:second>Anna</v1:second>")
307
348
  end
308
349
  end
309
350
 
@@ -322,7 +363,7 @@ describe Gyoku::Hash do
322
363
 
323
364
  to_xml(hash)
324
365
 
325
- hash.should == {
366
+ expect(hash).to eq({
326
367
  :persons => {
327
368
  :first => "Lucy",
328
369
  :second => "Anna",
@@ -332,14 +373,14 @@ describe Gyoku::Hash do
332
373
  :countries => [:de, :us],
333
374
  :order! => [:countries, :persons],
334
375
  :attributes! => { :countries => { :array => true } }
335
- }
376
+ })
336
377
  end
337
378
  end
338
379
 
339
380
  it "doesn't modify original hash parameter by deleting its attribute keys" do
340
381
  hash = { :person => {:name => "Johnny", :surname => "Bravo", :"@xsi:type" => "People"} }
341
382
  to_xml(hash)
342
- hash.should == {:person=>{:name=>"Johnny", :surname=>"Bravo", :"@xsi:type"=>"People"}}
383
+ expect(hash).to eq({:person=>{:name=>"Johnny", :surname=>"Bravo", :"@xsi:type"=>"People"}})
343
384
  end
344
385
 
345
386
  def to_xml(hash, options = {})
@@ -4,36 +4,57 @@ describe Gyoku::XMLKey do
4
4
 
5
5
  describe ".create" do
6
6
  it "removes exclamation marks from the end of a String" do
7
- create("value!").should == "value"
7
+ expect(create("value!")).to eq("value")
8
8
  end
9
9
 
10
10
  it "removes forward slashes from the end of a String" do
11
- create("self-closing/").should == "self-closing"
11
+ expect(create("self-closing/")).to eq("self-closing")
12
12
  end
13
13
 
14
14
  it "does not convert snake_case Strings" do
15
- create("lower_camel_case").should == "lower_camel_case"
15
+ expect(create("lower_camel_case")).to eq("lower_camel_case")
16
16
  end
17
17
 
18
18
  it "converts snake_case Symbols to lowerCamelCase Strings" do
19
- create(:lower_camel_case).should == "lowerCamelCase"
20
- create(:lower_camel_case!).should == "lowerCamelCase"
19
+ expect(create(:lower_camel_case)).to eq("lowerCamelCase")
20
+ expect(create(:lower_camel_case!)).to eq("lowerCamelCase")
21
+ end
22
+
23
+ context "with key_converter" do
24
+ it "convert symbol to the specified type" do
25
+ expect(create(:some_text, {key_converter: :camelcase})).to eq("SomeText")
26
+ expect(create(:some_text, {key_converter: :upcase})).to eq("SOME_TEXT")
27
+ expect(create(:some_text, {key_converter: :none})).to eq("some_text")
28
+ end
29
+
30
+ it "when key_to_convert is defined, convert only this key" do
31
+ options = {key_converter: :camelcase, key_to_convert: 'somekey'}
32
+ expect(create(:some_key, options)).to eq("someKey")
33
+
34
+ options = {key_converter: :camelcase, key_to_convert: 'some_key'}
35
+ expect(create(:some_key, options)).to eq("SomeKey")
36
+ end
37
+
38
+ it "when except is defined, dont convert this key" do
39
+ options = {key_converter: :camelcase, except: 'some_key'}
40
+ expect(create(:some_key, options)).to eq("someKey")
41
+ end
21
42
  end
22
43
 
23
44
  context "with :element_form_default set to :qualified and a :namespace" do
24
45
  it "adds the given namespace" do
25
46
  key = create :qualify, :element_form_default => :qualified, :namespace => :v1
26
- key.should == "v1:qualify"
47
+ expect(key).to eq("v1:qualify")
27
48
  end
28
49
 
29
50
  it "does not add the given namespace if the key starts with a colon" do
30
51
  key = create ":qualify", :element_form_default => :qualified, :namespace => :v1
31
- key.should == "qualify"
52
+ expect(key).to eq("qualify")
32
53
  end
33
54
 
34
55
  it "adds a given :namespace after converting the key" do
35
56
  key = create :username, :element_form_default => :qualified, :namespace => :v1, :key_converter => :camelcase
36
- key.should == "v1:Username"
57
+ expect(key).to eq("v1:Username")
37
58
  end
38
59
  end
39
60
  end
@@ -5,31 +5,31 @@ describe Gyoku::XMLValue do
5
5
  describe ".create" do
6
6
  context "for DateTime objects" do
7
7
  it "returns an xs:dateTime compliant String" do
8
- create(DateTime.new(2012, 03, 22, 16, 22, 33)).should == "2012-03-22T16:22:33+00:00"
8
+ expect(create(DateTime.new(2012, 03, 22, 16, 22, 33))).to eq("2012-03-22T16:22:33+00:00")
9
9
  end
10
10
  end
11
11
 
12
12
  context "for Date objects" do
13
13
  it "returns an xs:date compliant String" do
14
- create(Date.new(2012, 03, 22)).should == "2012-03-22"
14
+ expect(create(Date.new(2012, 03, 22))).to eq("2012-03-22")
15
15
  end
16
16
  end
17
17
 
18
18
  context "for Time objects" do
19
19
  it "returns an xs:time compliant String" do
20
- create(Time.local(2012, 03, 22, 16, 22, 33)).should == "16:22:33"
20
+ expect(create(Time.local(2012, 03, 22, 16, 22, 33))).to eq("16:22:33")
21
21
  end
22
22
  end
23
23
 
24
24
  it "returns the String value and escapes special characters" do
25
- create("string").should == "string"
26
- create("<tag>").should == "&lt;tag&gt;"
27
- create("at&t").should == "at&amp;t"
28
- create('"quotes"').should == "&quot;quotes&quot;"
25
+ expect(create("string")).to eq("string")
26
+ expect(create("<tag>")).to eq("&lt;tag&gt;")
27
+ expect(create("at&t")).to eq("at&amp;t")
28
+ expect(create('"quotes"')).to eq("&quot;quotes&quot;")
29
29
  end
30
30
 
31
31
  it "returns the String value without escaping special characters" do
32
- create("<tag>", false).should == "<tag>"
32
+ expect(create("<tag>", false)).to eq("<tag>")
33
33
  end
34
34
 
35
35
  it "returns an xs:dateTime compliant String for Objects responding to #to_datetime" do
@@ -38,16 +38,16 @@ describe Gyoku::XMLValue do
38
38
  DateTime.new 2012, 03, 22, 16, 22, 33
39
39
  end
40
40
 
41
- create(singleton).should == "2012-03-22T16:22:33+00:00"
41
+ expect(create(singleton)).to eq("2012-03-22T16:22:33+00:00")
42
42
  end
43
43
 
44
44
  it "calls Proc objects and converts their return value" do
45
45
  object = lambda { DateTime.new 2012, 03, 22, 16, 22, 33 }
46
- create(object).should == "2012-03-22T16:22:33+00:00"
46
+ expect(create(object)).to eq("2012-03-22T16:22:33+00:00")
47
47
  end
48
48
 
49
49
  it "calls #to_s unless the Object responds to #to_datetime" do
50
- create("value").should == "value"
50
+ expect(create("value")).to eq("value")
51
51
  end
52
52
  end
53
53
 
@@ -29,15 +29,40 @@ describe Gyoku do
29
29
  hash = { :id => 1 }
30
30
  xml = Gyoku.xml(hash, :element_form_default => :qualified)
31
31
 
32
- xml.should == "<id>1</id>"
32
+ expect(xml).to eq("<id>1</id>")
33
33
  end
34
34
 
35
35
  it "accepts a key_converter for the Hash keys" do
36
+ hash = { :user_name => "finn", :pass_word => "secret" }
37
+ xml = Gyoku.xml(hash, {key_converter: :upcase})
38
+
39
+ expect(xml).to include("<USER_NAME>finn</USER_NAME>")
40
+ expect(xml).to include("<PASS_WORD>secret</PASS_WORD>")
41
+ end
42
+
43
+ it "don't converts Strings keys" do
36
44
  hash = { :user_name => "finn", "pass_word" => "secret" }
37
- xml = Gyoku.xml(hash, :key_converter => :upcase)
45
+ xml = Gyoku.xml(hash, {key_converter: :upcase})
46
+
47
+ expect(xml).to include("<USER_NAME>finn</USER_NAME>")
48
+ expect(xml).to include("<pass_word>secret</pass_word>")
49
+ end
50
+
51
+ it "when defined key_to_convert only convert this key" do
52
+ hash = { user_name: "finn", pass_word: "secret" }
53
+ options = {key_converter: :upcase, key_to_convert: 'user_name'}
54
+ xml = Gyoku.xml(hash, options)
55
+
56
+ expect(xml).to include("<USER_NAME>finn</USER_NAME>")
57
+ expect(xml).to include("<passWord>secret</passWord>")
58
+ end
59
+
60
+ it "accepts key_converter for nested hash" do
61
+ hash = { user: { user_name: "finn", pass_word: "secret" }}
62
+ xml = Gyoku.xml(hash, {key_converter: :upcase})
38
63
 
39
- xml.should include("<USER_NAME>finn</USER_NAME>")
40
- xml.should include("<pass_word>secret</pass_word>")
64
+ expect(xml).to include("<USER><USER_NAME>finn</USER_NAME>")
65
+ expect(xml).to include("<PASS_WORD>secret</PASS_WORD></USER>")
41
66
  end
42
67
 
43
68
  it "does not modify the original Hash" do
@@ -52,7 +77,7 @@ describe Gyoku do
52
77
  original_hash = hash.dup
53
78
 
54
79
  Gyoku.xml(hash)
55
- original_hash.should == hash
80
+ expect(original_hash).to eq(hash)
56
81
  end
57
82
  end
58
83
 
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gyoku
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-03 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.1.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Gyoku translates Ruby Hashes to XML
@@ -58,9 +58,9 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
- - .gitignore
62
- - .rspec
63
- - .travis.yml
61
+ - ".gitignore"
62
+ - ".rspec"
63
+ - ".travis.yml"
64
64
  - CHANGELOG.md
65
65
  - Gemfile
66
66
  - MIT-LICENSE
@@ -89,17 +89,17 @@ require_paths:
89
89
  - lib
90
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - '>='
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
101
  rubyforge_project: gyoku
102
- rubygems_version: 2.1.11
102
+ rubygems_version: 2.2.2
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: Translates Ruby Hashes to XML