rest_model 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/README.md +37 -19
- data/examples/update_attributes/embeds_many.rb +14 -0
- data/examples/update_attributes/embeds_one.rb +14 -0
- data/examples/update_attributes/has_many.rb +17 -0
- data/examples/update_attributes/has_one.rb +17 -0
- data/examples/update_attributes/simple.rb +10 -0
- data/lib/rest_model/key/association.rb +17 -2
- data/lib/rest_model/version.rb +1 -1
- data/lib/rest_model.rb +1 -0
- data/spec/integration/embeds_many_spec.rb +55 -35
- data/spec/integration/embeds_one_spec.rb +25 -23
- data/spec/integration/has_many_spec.rb +19 -17
- data/spec/integration/property_spec.rb +35 -39
- data/spec/integration/summarization_spec.rb +9 -7
- data/spec/integration/update_attributes_spec.rb +40 -0
- data/spec/support/examples.rb +6 -6
- metadata +21 -14
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,19 +1,37 @@
|
|
1
1
|
# RestModel
|
2
2
|
|
3
|
-
|
3
|
+
[ THE INTERNETS ]
|
4
4
|
|
5
|
-
|
5
|
+
/\ ||
|
6
|
+
|| ||
|
7
|
+
|| \/
|
8
|
+
#resource .new
|
9
|
+
.resources #update_attributes
|
10
|
+
|
11
|
+
Your < RestModel
|
12
|
+
|
13
|
+
#to_source .from_source
|
14
|
+
|| /\
|
15
|
+
|| ||
|
16
|
+
\/ ||
|
17
|
+
|
18
|
+
SOURCE
|
19
|
+
|
20
|
+
|
21
|
+
### Map _from a data source_ to instances of your model class.
|
22
|
+
|
23
|
+
### Map _to RESTful responses_ from these model instances.
|
6
24
|
|
7
25
|
## Usage
|
8
26
|
|
9
|
-
###
|
27
|
+
### Source hash to model instances
|
10
28
|
|
11
29
|
Given you have:
|
12
30
|
|
13
31
|
input = {
|
14
32
|
"result" => [
|
15
33
|
{
|
16
|
-
"id" => 1938713897398,
|
34
|
+
"id" => "1938713897398",
|
17
35
|
"login" => "jsmith180",
|
18
36
|
"username" => "John Smith",
|
19
37
|
"personal_info" => {
|
@@ -22,7 +40,7 @@ Given you have:
|
|
22
40
|
}
|
23
41
|
},
|
24
42
|
{
|
25
|
-
"id" => 92171987391873,
|
43
|
+
"id" => "92171987391873",
|
26
44
|
"login" => "john_appleseed",
|
27
45
|
"username" => "John Appleseed",
|
28
46
|
"personal_info" => {
|
@@ -33,19 +51,19 @@ Given you have:
|
|
33
51
|
]
|
34
52
|
}
|
35
53
|
|
36
|
-
And you want to transform this
|
54
|
+
And you want to transform this in some instances of a `class User; attr_accessor :id, :login, :name, :birth; end`
|
37
55
|
|
38
56
|
With RestModel you can parse the input to instances of `User`:
|
39
57
|
|
40
|
-
users = User.
|
58
|
+
users = User.from_source(input, start_key: 'result') # starts looking hash from 'result' key
|
41
59
|
|
42
60
|
Just define your `User` class like this:
|
43
61
|
|
44
62
|
class User < RestModel
|
45
63
|
id
|
46
64
|
property :login
|
47
|
-
property :name, field: :username #
|
48
|
-
property :birth, field: 'personal_info
|
65
|
+
property :name, field: :username # source key is different from model property
|
66
|
+
property :birth, field: 'personal_info.birth_date' # digg hash path defined by '.', the last being the key
|
49
67
|
end
|
50
68
|
|
51
69
|
### Model instances array to restful response hash
|
@@ -56,14 +74,14 @@ Just define your `User` class like this:
|
|
56
74
|
{
|
57
75
|
entries: [
|
58
76
|
{
|
59
|
-
id: 1938713897398,
|
77
|
+
id: "1938713897398",
|
60
78
|
login: "jsmith180",
|
61
79
|
name: "John Smith",
|
62
80
|
birth: "1999-02-10",
|
63
81
|
href: "http://app/api/users/1938713897398"
|
64
82
|
},
|
65
83
|
{
|
66
|
-
id: 92171987391873,
|
84
|
+
id: "92171987391873",
|
67
85
|
login: "john_appleseed",
|
68
86
|
name: "John Appleseed",
|
69
87
|
birth: "1999-02-10",
|
@@ -78,7 +96,7 @@ Just define your `User` class like this:
|
|
78
96
|
=>
|
79
97
|
|
80
98
|
{
|
81
|
-
id: 1938713897398,
|
99
|
+
id: "1938713897398",
|
82
100
|
login: "jsmith180",
|
83
101
|
name: "John Smith",
|
84
102
|
birth: "1999-02-10",
|
@@ -101,7 +119,7 @@ Just define your `User` class like this:
|
|
101
119
|
end
|
102
120
|
|
103
121
|
{
|
104
|
-
id: 1938713897398,
|
122
|
+
id: '1938713897398',
|
105
123
|
address: {
|
106
124
|
street: 'rest_client st.',
|
107
125
|
number: '39',
|
@@ -127,16 +145,16 @@ Just define your `User` class like this:
|
|
127
145
|
end
|
128
146
|
|
129
147
|
{
|
130
|
-
id: 739819813719387,
|
148
|
+
id: '739819813719387',
|
131
149
|
items: [
|
132
150
|
{
|
133
|
-
item_id: 1738917139871,
|
151
|
+
item_id: '1738917139871',
|
134
152
|
quantity: 18,
|
135
153
|
unit_price: 0.2,
|
136
154
|
amount: 3.6
|
137
155
|
},
|
138
156
|
{
|
139
|
-
item_id: 3987187398782,
|
157
|
+
item_id: '3987187398782',
|
140
158
|
quantity: 1,
|
141
159
|
unit_price: 39.9,
|
142
160
|
amount: 39.9
|
@@ -159,7 +177,7 @@ Just define your `User` class like this:
|
|
159
177
|
end
|
160
178
|
|
161
179
|
{
|
162
|
-
id: 19837139879,
|
180
|
+
id: '19837139879',
|
163
181
|
login: 'jsmith180',
|
164
182
|
link: [
|
165
183
|
{
|
@@ -181,10 +199,10 @@ Just define your `User` class like this:
|
|
181
199
|
|
182
200
|
If you want your api to handle `http://app/api/users/19371897318937?include[]=avatar&include[]=guilda`
|
183
201
|
|
184
|
-
user = User.
|
202
|
+
user = User.from_source(input, include: [avatar_input, guilda_input]).first
|
185
203
|
|
186
204
|
{
|
187
|
-
id: 19837139879,
|
205
|
+
id: '19837139879',
|
188
206
|
login: 'jsmith180',
|
189
207
|
avatar: {
|
190
208
|
name: 'K1ll3r',
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Item < RestModel
|
4
|
+
property :id, type: Integer
|
5
|
+
end
|
6
|
+
|
7
|
+
class Root < RestModel
|
8
|
+
embeds_many :items
|
9
|
+
end
|
10
|
+
|
11
|
+
@root = Root.parse({items: [{id: 2000}, {id: 2001}]}).first
|
12
|
+
@root.update_attributes({items: [{id: 3000}]})
|
13
|
+
|
14
|
+
inspect_rest_model(@root)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Root < RestModel
|
4
|
+
embeds_one :item
|
5
|
+
end
|
6
|
+
|
7
|
+
class Item < RestModel
|
8
|
+
properties :id, :name
|
9
|
+
end
|
10
|
+
|
11
|
+
@root = Root.parse({item: {id: 2000}}).first
|
12
|
+
@root.update_attributes({item: {name: "name"}})
|
13
|
+
|
14
|
+
inspect_rest_model(@root)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Service < RestModel
|
4
|
+
property :name
|
5
|
+
belongs_to :customer
|
6
|
+
end
|
7
|
+
|
8
|
+
class Customer < RestModel
|
9
|
+
id field: :customer_id, type: Integer
|
10
|
+
property :login
|
11
|
+
has_many :services
|
12
|
+
end
|
13
|
+
|
14
|
+
@root = Customer.parse({customer_id: 123, login: 'jackiechan2010'}).first
|
15
|
+
@root.update_attributes({services: [{name: "new_service_name"}]})
|
16
|
+
|
17
|
+
inspect_rest_model(@root)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Billing < RestModel
|
4
|
+
property :login
|
5
|
+
belongs_to :customer
|
6
|
+
end
|
7
|
+
|
8
|
+
class Customer < RestModel
|
9
|
+
id field: :customer_id, type: Integer
|
10
|
+
property :login
|
11
|
+
has_one :billing
|
12
|
+
end
|
13
|
+
|
14
|
+
@root = Customer.parse({customer_id: 123, login: 'jackiechan2010'}).first
|
15
|
+
@root.update_attributes({billing: {login: "new_billing_login"}})
|
16
|
+
|
17
|
+
inspect_rest_model(@root)
|
@@ -35,8 +35,23 @@ class RestModel
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def update_from_hash(resource, attrs)
|
38
|
-
one?
|
39
|
-
|
38
|
+
if one?
|
39
|
+
resource.update_attributes(attrs)
|
40
|
+
else
|
41
|
+
if resource.count > attrs.count
|
42
|
+
resource = resource.to(attrs.count - 1)
|
43
|
+
end
|
44
|
+
|
45
|
+
attrs.each_with_index do |item, index|
|
46
|
+
if index < resource.count
|
47
|
+
resource[index].update_attributes(item)
|
48
|
+
else
|
49
|
+
resource << create_from_hash(item)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
resource
|
54
|
+
end
|
40
55
|
end
|
41
56
|
end
|
42
57
|
end
|
data/lib/rest_model/version.rb
CHANGED
data/lib/rest_model.rb
CHANGED
@@ -4,6 +4,7 @@ require "active_support/concern"
|
|
4
4
|
require "active_support/core_ext/class/attribute_accessors"
|
5
5
|
require "active_support/core_ext/object/try"
|
6
6
|
require "active_support/core_ext/array/wrap"
|
7
|
+
require "active_support/core_ext/array/access"
|
7
8
|
require "active_support/core_ext/hash/slice"
|
8
9
|
require "active_support/core_ext/hash/indifferent_access"
|
9
10
|
|
@@ -2,56 +2,76 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
describe "embeds_many" do
|
6
|
+
describe_example "embeds_many/simple" do
|
7
|
+
it "parses first embedded item" do
|
8
|
+
root.items[0].id.should == 2000
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
it "parses second embedded item" do
|
12
|
+
root.items[1].id.should == 2001
|
13
|
+
end
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
15
|
-
describe_example "embeds_many/invisible" do
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
describe_example "embeds_many/invisible" do
|
17
|
+
it "parses invisible items correctly" do
|
18
|
+
root.locale.should == "pt-BR"
|
19
|
+
root.names.should == {"en"=>"Woot", "pt-BR"=>"Úia", "es"=>"Me gusta"}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "doesn't show embedded items in resource" do
|
23
|
+
root.resource.should_not have_key("locale")
|
24
|
+
root.resource.should_not have_key("names")
|
25
|
+
end
|
19
26
|
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
describe_example "embeds_many/with_array" do
|
29
|
+
it "parses items" do
|
30
|
+
root.items.should == ["a", "b"]
|
31
|
+
end
|
24
32
|
end
|
25
|
-
end
|
26
33
|
|
27
|
-
describe_example "embeds_many/
|
28
|
-
|
29
|
-
|
34
|
+
describe_example "embeds_many/with_class_name" do
|
35
|
+
it "parses embedded item" do
|
36
|
+
root.items.first.id.should == 2000
|
37
|
+
end
|
38
|
+
end
|
30
39
|
|
31
|
-
describe_example "embeds_many/
|
32
|
-
|
33
|
-
|
40
|
+
describe_example "embeds_many/with_fields" do
|
41
|
+
it "parses fields" do
|
42
|
+
root.items.should == ["i1", "i2", "i3"]
|
43
|
+
end
|
34
44
|
end
|
35
|
-
end
|
36
45
|
|
37
|
-
describe_example "embeds_many/with_if" do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
46
|
+
describe_example "embeds_many/with_if" do
|
47
|
+
context "when an embeddable has a conditional proc (:if)" do
|
48
|
+
context "and it evaluates to true" do
|
49
|
+
it "parses embedded item" do
|
50
|
+
root_with_items.items.first.id.should == "2000"
|
51
|
+
end
|
42
52
|
end
|
43
|
-
end
|
44
53
|
|
45
|
-
|
46
|
-
|
47
|
-
|
54
|
+
context "and it evaluates to false" do
|
55
|
+
it "doesn't parse embedded item" do
|
56
|
+
root_without_items.items.should_not be
|
57
|
+
end
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
51
|
-
end
|
52
61
|
|
53
|
-
describe_example "embeds_many/
|
54
|
-
|
55
|
-
|
62
|
+
describe_example "embeds_many/with_nil_value" do
|
63
|
+
it "has items nil" do
|
64
|
+
root.items.should_not be
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns an empty items list" do
|
68
|
+
root.resource[:items].should == []
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe_example "embeds_many/with_start_key" do
|
73
|
+
it "parses embedded items" do
|
74
|
+
root.items.first.id.should == "2000"
|
75
|
+
end
|
56
76
|
end
|
57
77
|
end
|
@@ -1,41 +1,43 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
root.item.id.should == "2000"
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe_example "embeds_one/with_class_name" do
|
10
|
-
context 'when a different class name is used for embeddable' do
|
3
|
+
describe "embeds_one" do
|
4
|
+
describe_example "embeds_one/simple" do
|
11
5
|
it 'parses embedded item' do
|
12
6
|
root.item.id.should == "2000"
|
13
7
|
end
|
14
8
|
end
|
15
|
-
end
|
16
9
|
|
17
|
-
describe_example "embeds_one/
|
18
|
-
|
19
|
-
context 'and it evaluates to true' do
|
10
|
+
describe_example "embeds_one/with_class_name" do
|
11
|
+
context 'when a different class name is used for embeddable' do
|
20
12
|
it 'parses embedded item' do
|
21
|
-
|
22
|
-
root_with_item.item.id.should == "2000"
|
13
|
+
root.item.id.should == "2000"
|
23
14
|
end
|
24
15
|
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe_example "embeds_one/with_if" do
|
19
|
+
context 'when an embeddable has a conditional proc (:if)' do
|
20
|
+
context 'and it evaluates to true' do
|
21
|
+
it 'parses embedded item' do
|
22
|
+
root_with_item.id.should == "1"
|
23
|
+
root_with_item.item.id.should == "2000"
|
24
|
+
end
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
context 'and it evaluates to false' do
|
28
|
+
it "doesn't parse embedded item" do
|
29
|
+
root_without_item.id.should == "100"
|
30
|
+
root_without_item.item.should_not be
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
35
|
-
describe_example "embeds_one/with_start_key" do
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
describe_example "embeds_one/with_start_key" do
|
37
|
+
context 'when there is a start key to parse input' do
|
38
|
+
it 'parses embedded item' do
|
39
|
+
root.item.id.should == "2000"
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -1,26 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
describe "#resource" do
|
10
|
-
subject {root.resource}
|
11
|
-
|
12
|
-
it 'has a link' do
|
13
|
-
subject[:link].should be_an(Array)
|
3
|
+
describe "has_many" do
|
4
|
+
describe_example "has_many/simple" do
|
5
|
+
it 'parses properly' do
|
6
|
+
root.id.should == 123
|
7
|
+
root.login.should == 'jackiechan2010'
|
14
8
|
end
|
15
9
|
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
describe "#resource" do
|
11
|
+
subject {root.resource}
|
12
|
+
|
13
|
+
it 'has a link' do
|
14
|
+
subject[:link].should be_an(Array)
|
19
15
|
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
[:services, :billing, :devops].each do |rel|
|
18
|
+
it "has a #{rel} relation" do
|
19
|
+
subject[:link].any? {|l| l[:rel] == rel}.should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "has a href for #{rel} relation" do
|
23
|
+
link = subject[:link].find {|l| l[:rel] == rel}
|
24
|
+
link[:href].should =~ %r{/customers/123/#{rel}}
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -6,64 +6,60 @@ def it_parses_property
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
describe_example 'properties/with_field' do
|
14
|
-
context 'when input has a different name for the property' do
|
9
|
+
describe "properties" do
|
10
|
+
describe_example 'properties/simple' do
|
15
11
|
it_parses_property
|
16
12
|
end
|
17
|
-
end
|
18
13
|
|
19
|
-
describe_example 'properties/
|
20
|
-
|
21
|
-
|
14
|
+
describe_example 'properties/with_field' do
|
15
|
+
context 'when input has a different name for the property' do
|
16
|
+
it_parses_property
|
17
|
+
end
|
22
18
|
end
|
23
|
-
end
|
24
19
|
|
25
|
-
describe_example 'properties/
|
26
|
-
|
27
|
-
|
28
|
-
root.id.should == "2000"
|
20
|
+
describe_example 'properties/with_field_path' do
|
21
|
+
context 'when input has a different path for the property' do
|
22
|
+
it_parses_property
|
29
23
|
end
|
30
24
|
end
|
31
|
-
end
|
32
25
|
|
33
|
-
describe_example 'properties/
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
root_with_description.description.should == "description"
|
26
|
+
describe_example 'properties/with_id' do
|
27
|
+
context 'when property is an id' do
|
28
|
+
it 'parses id' do
|
29
|
+
root.id.should == "2000"
|
38
30
|
end
|
39
31
|
end
|
32
|
+
end
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
describe_example 'properties/with_if' do
|
35
|
+
context 'when a property has a conditional proc (:if)' do
|
36
|
+
context 'and it evaluates to true' do
|
37
|
+
it 'parses property' do
|
38
|
+
root_with_description.description.should == "description"
|
39
|
+
end
|
44
40
|
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
41
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
context 'and it evaluates to false' do
|
43
|
+
it "doesn't parse property" do
|
44
|
+
root_without_description.description.should_not be
|
45
|
+
end
|
46
|
+
end
|
53
47
|
end
|
54
48
|
end
|
55
49
|
|
56
|
-
|
57
|
-
|
50
|
+
describe_example 'properties/with_key_converter' do
|
51
|
+
context 'when a diferent key converter is configured on rest model' do
|
52
|
+
it_parses_property
|
53
|
+
end
|
58
54
|
end
|
59
|
-
end
|
60
55
|
|
61
|
-
describe_example 'properties/with_two_key_converters' do
|
62
|
-
|
63
|
-
|
56
|
+
describe_example 'properties/with_two_key_converters' do
|
57
|
+
context 'when key converters are configured for each class' do
|
58
|
+
it_parses_property
|
64
59
|
|
65
|
-
|
66
|
-
|
60
|
+
it 'parses other property with different key converter' do
|
61
|
+
root.product.unit_price.should == 29.9
|
62
|
+
end
|
67
63
|
end
|
68
64
|
end
|
69
65
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
describe "summarization" do
|
4
|
+
describe_example 'summarization/simple' do
|
5
|
+
subject {root[:entries].first}
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
it 'summarizes resources' do
|
8
|
+
subject.keys.count.should == 3
|
9
|
+
subject[:id].should == '138911938'
|
10
|
+
subject[:login].should == 'jackiechan2010'
|
11
|
+
subject[:href].should == 'http://example.com/customers/138911938'
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "update_attributes" do
|
6
|
+
describe_example "update_attributes/embeds_one" do
|
7
|
+
it "updates customer item name" do
|
8
|
+
root.item.id.should == "2000"
|
9
|
+
root.item.name.should == "name"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe_example "update_attributes/simple" do
|
14
|
+
it "updates customer login" do
|
15
|
+
root.login.should == "newjackiechan2010"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe_example "update_attributes/embeds_many" do
|
20
|
+
it "updates customer items" do
|
21
|
+
root.items.count.should == 1
|
22
|
+
root.items.first.id.should == 3000
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe_example "update_attributes/has_one" do
|
27
|
+
it "updates customer billing" do
|
28
|
+
root.billing.should_not be_nil
|
29
|
+
root.billing.login.should == "new_billing_login"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe_example "update_attributes/has_many" do
|
34
|
+
it "updates customer services" do
|
35
|
+
root.services.should_not be_nil
|
36
|
+
root.services.count.should == 1
|
37
|
+
root.services.first.name.should == "new_service_name"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/support/examples.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Examples
|
2
|
-
def describe_example(file, &block)
|
3
|
-
describe "example #{file}" do
|
2
|
+
def describe_example(file, tags = {}, &block)
|
3
|
+
describe "example #{file}", tags do
|
4
4
|
[:Root, :Item, :Customer, :Entry].each do |klass|
|
5
5
|
Examples.send(:remove_const, klass) if Examples.const_defined?(klass)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
RestModel::Configuration.configure do |c|
|
9
|
+
c.convert_input_keys = RestModel::Configuration::DefaultHandler
|
10
|
+
end
|
11
11
|
|
12
|
-
|
12
|
+
silently {eval File.read("examples/#{file}.rb")}
|
13
13
|
|
14
14
|
variables = instance_variables.reject {|var| var.to_s =~ /metadata$/}
|
15
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2011-10-
|
14
|
+
date: 2011-10-05 00:00:00.000000000Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
18
|
-
requirement: &
|
18
|
+
requirement: &70140255570300 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '3.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70140255570300
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: i18n
|
29
|
-
requirement: &
|
29
|
+
requirement: &70140255569800 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '0.5'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70140255569800
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rspec
|
40
|
-
requirement: &
|
40
|
+
requirement: &70140255569300 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '2.6'
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70140255569300
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: guard
|
51
|
-
requirement: &
|
51
|
+
requirement: &70140255568780 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ~>
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: '0.5'
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *70140255568780
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: guard-rspec
|
62
|
-
requirement: &
|
62
|
+
requirement: &70140255568100 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ~>
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: '0.4'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *70140255568100
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: growl
|
73
|
-
requirement: &
|
73
|
+
requirement: &70140255567560 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ~>
|
@@ -78,7 +78,7 @@ dependencies:
|
|
78
78
|
version: '1.0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *70140255567560
|
82
82
|
description: ''
|
83
83
|
email:
|
84
84
|
- victorcrodrigues@gmail.com
|
@@ -136,6 +136,11 @@ files:
|
|
136
136
|
- examples/to_input/with_fields.rb
|
137
137
|
- examples/to_input/without_key.rb
|
138
138
|
- examples/to_input/without_nil.rb
|
139
|
+
- examples/update_attributes/embeds_many.rb
|
140
|
+
- examples/update_attributes/embeds_one.rb
|
141
|
+
- examples/update_attributes/has_many.rb
|
142
|
+
- examples/update_attributes/has_one.rb
|
143
|
+
- examples/update_attributes/simple.rb
|
139
144
|
- lib/rest_model.rb
|
140
145
|
- lib/rest_model/configuration.rb
|
141
146
|
- lib/rest_model/key.rb
|
@@ -174,6 +179,7 @@ files:
|
|
174
179
|
- spec/integration/has_many_spec.rb
|
175
180
|
- spec/integration/property_spec.rb
|
176
181
|
- spec/integration/summarization_spec.rb
|
182
|
+
- spec/integration/update_attributes_spec.rb
|
177
183
|
- spec/spec_helper.rb
|
178
184
|
- spec/support/examples.rb
|
179
185
|
- spec/support/out.rb
|
@@ -231,6 +237,7 @@ test_files:
|
|
231
237
|
- spec/integration/has_many_spec.rb
|
232
238
|
- spec/integration/property_spec.rb
|
233
239
|
- spec/integration/summarization_spec.rb
|
240
|
+
- spec/integration/update_attributes_spec.rb
|
234
241
|
- spec/spec_helper.rb
|
235
242
|
- spec/support/examples.rb
|
236
243
|
- spec/support/out.rb
|