simplify_api 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simplify_api/simplify_api.rb +1 -1
- data/lib/simplify_api/version.rb +1 -1
- data/spec/simplify_api_spec.rb +34 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d5c993f71e29fbaa2e17f68e43de75d08c4a13b42bb05e0b7b52f3a076de633
|
4
|
+
data.tar.gz: a6e03c193ac868b30165c4319c2c1a587531baf45c39b970c7b0011a4b1d0978
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 513ca3a6d2e76ec876a0ed9983476d6f8c04cefa11f640c5e5ec6699ba1dc58f9a09c4b5e328689c6f6d049948d34d3d28abb022fd96284c854a94530e808775
|
7
|
+
data.tar.gz: 7891192f811ad08bc06619e5e27d8eb0ad9ea65aac4dc7bf0d623e33d0fedbdaa9984631f2239a27aaab885959da2ad6d03c8c860bb4511f98b665d1ffe7286b
|
data/lib/simplify_api/version.rb
CHANGED
data/spec/simplify_api_spec.rb
CHANGED
@@ -92,8 +92,6 @@ describe SimplifyApi do
|
|
92
92
|
"English",
|
93
93
|
"German" ]
|
94
94
|
}))
|
95
|
-
|
96
|
-
puts "JSON: #{json_value}"
|
97
95
|
subject = Test.new(json_value)
|
98
96
|
|
99
97
|
expect(subject.name).to eq "John Doe"
|
@@ -102,4 +100,38 @@ describe SimplifyApi do
|
|
102
100
|
expect(subject.languages).to have(2).languages
|
103
101
|
end
|
104
102
|
end
|
103
|
+
|
104
|
+
describe "with nested classes" do
|
105
|
+
before(:all) do
|
106
|
+
class Location
|
107
|
+
include SimplifyApi
|
108
|
+
attribute :title, String, mandatory: true
|
109
|
+
attribute :address, String
|
110
|
+
attribute :city, String
|
111
|
+
end
|
112
|
+
|
113
|
+
class User
|
114
|
+
include SimplifyApi
|
115
|
+
attribute :name, String, mandatory: true
|
116
|
+
attribute :locations, [Location]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should instatiate nested classes from JSON" do
|
121
|
+
json_value = JSON.parse(%q({
|
122
|
+
"name": "John Doe",
|
123
|
+
"locations": [
|
124
|
+
{ "title": "Home", "address": "Elm Street", "city": "New York" },
|
125
|
+
{ "title": "Office", "address": "White House Street", "city": "Washington DC" }
|
126
|
+
]
|
127
|
+
}))
|
128
|
+
subject = User.new(json_value)
|
129
|
+
|
130
|
+
expect(subject.name).to eq "John Doe"
|
131
|
+
expect(subject.locations).to have(2).locations
|
132
|
+
expect(subject.locations[0].class).to be Location
|
133
|
+
expect(subject.locations[0].title).to eq "Home"
|
134
|
+
expect(subject.locations[1].title).to eq "Office"
|
135
|
+
end
|
136
|
+
end
|
105
137
|
end
|