her 0.2.6 → 0.3
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 +78 -39
- data/lib/her/model/introspection.rb +27 -0
- data/lib/her/model/orm.rb +3 -5
- data/lib/her/model/paths.rb +6 -2
- data/lib/her/model/relationships.rb +44 -32
- data/lib/her/version.rb +1 -1
- data/spec/model/hooks_spec.rb +105 -105
- data/spec/model/http_spec.rb +44 -33
- data/spec/model/introspection_spec.rb +27 -6
- data/spec/model/orm_spec.rb +19 -20
- data/spec/model/paths_spec.rb +43 -43
- data/spec/model/relationships_spec.rb +48 -51
- data/spec/spec_helper.rb +28 -13
- metadata +4 -4
data/spec/model/http_spec.rb
CHANGED
@@ -7,8 +7,10 @@ describe Her::Model::HTTP do
|
|
7
7
|
api = Her::API.new
|
8
8
|
api.setup :url => "https://api.example.com"
|
9
9
|
|
10
|
-
spawn_model
|
11
|
-
|
10
|
+
spawn_model "Foo::User"
|
11
|
+
Foo::User.uses_api api
|
12
|
+
|
13
|
+
Foo::User.class_eval do
|
12
14
|
@her_api.should_not == nil
|
13
15
|
@her_api.base_uri.should == "https://api.example.com"
|
14
16
|
end
|
@@ -17,7 +19,9 @@ describe Her::Model::HTTP do
|
|
17
19
|
it "binds a model directly to Her::API" do # {{{
|
18
20
|
Her::API.setup :url => "https://api.example.com"
|
19
21
|
|
20
|
-
spawn_model
|
22
|
+
spawn_model "Foo::User"
|
23
|
+
|
24
|
+
Foo::User.class_eval do
|
21
25
|
@her_api.should_not == nil
|
22
26
|
@her_api.base_uri.should == "https://api.example.com"
|
23
27
|
end
|
@@ -30,8 +34,10 @@ describe Her::Model::HTTP do
|
|
30
34
|
builder.use Faraday::Request::UrlEncoded
|
31
35
|
end
|
32
36
|
|
33
|
-
spawn_model
|
34
|
-
|
37
|
+
spawn_model "Foo::User"
|
38
|
+
Foo::User.uses_api api1
|
39
|
+
|
40
|
+
Foo::User.class_eval do
|
35
41
|
@her_api.base_uri.should == "https://api1.example.com"
|
36
42
|
end
|
37
43
|
|
@@ -41,8 +47,10 @@ describe Her::Model::HTTP do
|
|
41
47
|
builder.use Faraday::Request::UrlEncoded
|
42
48
|
end
|
43
49
|
|
44
|
-
spawn_model
|
45
|
-
|
50
|
+
spawn_model "Foo::Comment"
|
51
|
+
Foo::Comment.uses_api api2
|
52
|
+
|
53
|
+
Foo::Comment.class_eval do
|
46
54
|
@her_api.base_uri.should == "https://api2.example.com"
|
47
55
|
end
|
48
56
|
end # }}}
|
@@ -53,7 +61,9 @@ describe Her::Model::HTTP do
|
|
53
61
|
builder.use Faraday::Request::UrlEncoded
|
54
62
|
end
|
55
63
|
|
56
|
-
spawn_model
|
64
|
+
spawn_model "Foo::User"
|
65
|
+
|
66
|
+
Foo::User.class_eval do
|
57
67
|
@her_api.base_uri.should == "https://api1.example.com"
|
58
68
|
end
|
59
69
|
|
@@ -63,8 +73,10 @@ describe Her::Model::HTTP do
|
|
63
73
|
builder.use Faraday::Request::UrlEncoded
|
64
74
|
end
|
65
75
|
|
66
|
-
spawn_model
|
67
|
-
|
76
|
+
spawn_model "Foo::Comment"
|
77
|
+
Foo::Comment.uses_api api
|
78
|
+
|
79
|
+
Foo::Comment.class_eval do
|
68
80
|
@her_api.base_uri.should == "https://api2.example.com"
|
69
81
|
end
|
70
82
|
end # }}}
|
@@ -92,78 +104,78 @@ describe Her::Model::HTTP do
|
|
92
104
|
end
|
93
105
|
end
|
94
106
|
|
95
|
-
spawn_model
|
107
|
+
spawn_model "Foo::User"
|
96
108
|
end # }}}
|
97
109
|
|
98
110
|
it "handle GET wrapper method" do # {{{
|
99
|
-
@users = User.get(:popular)
|
111
|
+
@users = Foo::User.get(:popular)
|
100
112
|
@users.length.should == 2
|
101
113
|
@users.first.id.should == 1
|
102
114
|
|
103
|
-
@user = User.get(:"1")
|
115
|
+
@user = Foo::User.get(:"1")
|
104
116
|
@user.id.should == 1
|
105
117
|
end # }}}
|
106
118
|
|
107
119
|
it "handle raw GET" do # {{{
|
108
|
-
User.get_raw("/users") do |parsed_data|
|
120
|
+
Foo::User.get_raw("/users") do |parsed_data|
|
109
121
|
parsed_data[:data].should == [{ :id => 1 }]
|
110
122
|
end
|
111
123
|
end # }}}
|
112
124
|
|
113
125
|
it "handle raw POST" do # {{{
|
114
|
-
User.post_raw("/users") do |parsed_data|
|
126
|
+
Foo::User.post_raw("/users") do |parsed_data|
|
115
127
|
parsed_data[:data].should == [{ :id => 3 }]
|
116
128
|
end
|
117
129
|
end # }}}
|
118
130
|
|
119
131
|
it "handle raw PUT" do # {{{
|
120
|
-
User.put_raw("/users/4") do |parsed_data|
|
132
|
+
Foo::User.put_raw("/users/4") do |parsed_data|
|
121
133
|
parsed_data[:data].should == [{ :id => 4 }]
|
122
134
|
end
|
123
135
|
end # }}}
|
124
136
|
|
125
137
|
it "handle raw PATCH" do # {{{
|
126
|
-
User.patch_raw("/users/6") do |parsed_data|
|
138
|
+
Foo::User.patch_raw("/users/6") do |parsed_data|
|
127
139
|
parsed_data[:data].should == [{ :id => 6 }]
|
128
140
|
end
|
129
141
|
end # }}}
|
130
142
|
|
131
143
|
it "handle raw DELETE" do # {{{
|
132
|
-
User.delete_raw("/users/5") do |parsed_data|
|
144
|
+
Foo::User.delete_raw("/users/5") do |parsed_data|
|
133
145
|
parsed_data[:data].should == [{ :id => 5 }]
|
134
146
|
end
|
135
147
|
end # }}}
|
136
148
|
|
137
149
|
it "handle querystring parameters" do # {{{
|
138
|
-
User.get_raw("/users", :page => 2) do |parsed_data|
|
150
|
+
Foo::User.get_raw("/users", :page => 2) do |parsed_data|
|
139
151
|
parsed_data[:data].should == [{ :id => 2 }]
|
140
152
|
end
|
141
153
|
end # }}}
|
142
154
|
|
143
155
|
it "handle GET collection" do # {{{
|
144
|
-
@users = User.get_collection("/users/popular")
|
156
|
+
@users = Foo::User.get_collection("/users/popular")
|
145
157
|
@users.length.should == 2
|
146
158
|
@users.first.id.should == 1
|
147
159
|
end # }}}
|
148
160
|
|
149
161
|
it "handle GET resource" do # {{{
|
150
|
-
@user = User.get_resource("/users/1")
|
162
|
+
@user = Foo::User.get_resource("/users/1")
|
151
163
|
@user.id.should == 1
|
152
164
|
end # }}}
|
153
165
|
|
154
166
|
it "handle GET collection through a symbol" do # {{{
|
155
|
-
@users = User.get_collection(:popular)
|
167
|
+
@users = Foo::User.get_collection(:popular)
|
156
168
|
@users.length.should == 2
|
157
169
|
@users.first.id.should == 1
|
158
170
|
end # }}}
|
159
171
|
|
160
172
|
it "handle GET resource through a symbol" do # {{{
|
161
|
-
@user = User.get_resource(:"1")
|
173
|
+
@user = Foo::User.get_resource(:"1")
|
162
174
|
@user.id.should == 1
|
163
175
|
end # }}}
|
164
176
|
|
165
177
|
it "handle raw GET through a symbol" do # {{{
|
166
|
-
User.get_raw(:popular) do |parsed_data|
|
178
|
+
Foo::User.get_raw(:popular) do |parsed_data|
|
167
179
|
parsed_data[:data].should == [{ :id => 1 }, { :id => 2 }]
|
168
180
|
end
|
169
181
|
end # }}}
|
@@ -180,26 +192,25 @@ describe Her::Model::HTTP do
|
|
180
192
|
end
|
181
193
|
end
|
182
194
|
|
183
|
-
spawn_model
|
184
|
-
|
185
|
-
|
186
|
-
end
|
195
|
+
spawn_model "Foo::User"
|
196
|
+
Foo::User.custom_get :popular, :foobar
|
197
|
+
Foo::User.custom_post :from_default
|
187
198
|
end # }}}
|
188
199
|
|
189
200
|
it "handles custom methods" do # {{{
|
190
|
-
User.respond_to?(:popular).should be_true
|
191
|
-
User.respond_to?(:foobar).should be_true
|
192
|
-
User.respond_to?(:from_default).should be_true
|
201
|
+
Foo::User.respond_to?(:popular).should be_true
|
202
|
+
Foo::User.respond_to?(:foobar).should be_true
|
203
|
+
Foo::User.respond_to?(:from_default).should be_true
|
193
204
|
end # }}}
|
194
205
|
|
195
206
|
it "handles custom GET requests" do # {{{
|
196
|
-
@users = User.popular
|
207
|
+
@users = Foo::User.popular
|
197
208
|
@users.length.should == 2
|
198
209
|
@users.first.id.should == 1
|
199
210
|
end # }}}
|
200
211
|
|
201
212
|
it "handles custom POST requests" do # {{{
|
202
|
-
@user = User.from_default(:name => "Tobias Fünke")
|
213
|
+
@user = Foo::User.from_default(:name => "Tobias Fünke")
|
203
214
|
@user.id.should be_true
|
204
215
|
end # }}}
|
205
216
|
end
|
@@ -8,23 +8,44 @@ describe Her::Model::Introspection do
|
|
8
8
|
builder.use Her::Middleware::FirstLevelParseJSON
|
9
9
|
builder.use Faraday::Request::UrlEncoded
|
10
10
|
builder.adapter :test do |stub|
|
11
|
-
stub.
|
11
|
+
stub.post("/users") { |env| [200, {}, { :id => 1, :name => "Tobias Funke" }.to_json] }
|
12
|
+
stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Funke" }.to_json] }
|
13
|
+
stub.put("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Funke" }.to_json] }
|
14
|
+
stub.delete("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Funke" }.to_json] }
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
15
|
-
spawn_model
|
18
|
+
spawn_model "Foo::User"
|
16
19
|
end # }}}
|
17
20
|
|
18
21
|
describe "#inspect" do
|
19
22
|
it "outputs resource attributs for an existing resource" do # {{{
|
20
|
-
@user = User.find(1)
|
21
|
-
["#<User(/users/1) name=\"Tobias Funke\" id=1>", "#<User(/users/1) id=1 name=\"Tobias Funke\">"].should include(@user.inspect)
|
23
|
+
@user = Foo::User.find(1)
|
24
|
+
["#<Foo::User(/users/1) name=\"Tobias Funke\" id=1>", "#<Foo::User(/users/1) id=1 name=\"Tobias Funke\">"].should include(@user.inspect)
|
22
25
|
end # }}}
|
23
26
|
|
24
27
|
it "outputs resource attributs for an not-saved-yet resource" do # {{{
|
25
|
-
@user = User.new(:name => "Tobias Funke")
|
26
|
-
@user.inspect.should == "#<User(/users) name=\"Tobias Funke\">"
|
28
|
+
@user = Foo::User.new(:name => "Tobias Funke")
|
29
|
+
@user.inspect.should == "#<Foo::User(/users) name=\"Tobias Funke\">"
|
27
30
|
end # }}}
|
28
31
|
end
|
29
32
|
end
|
33
|
+
|
34
|
+
describe "#nearby_class" do
|
35
|
+
context "for a class inside of a module" do
|
36
|
+
before do
|
37
|
+
spawn_model "Foo::User"
|
38
|
+
spawn_model "Foo::AccessRecord"
|
39
|
+
spawn_model "AccessRecord"
|
40
|
+
spawn_model "Log"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns a sibling class, if found" do
|
44
|
+
Foo::User.nearby_class("AccessRecord").should == Foo::AccessRecord
|
45
|
+
AccessRecord.nearby_class("Log").should == Log
|
46
|
+
Foo::User.nearby_class("Log").should == Log
|
47
|
+
Foo::User.nearby_class("X").should be_nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
30
51
|
end
|
data/spec/model/orm_spec.rb
CHANGED
@@ -15,49 +15,48 @@ describe Her::Model::ORM do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
spawn_model
|
18
|
+
spawn_model "Foo::User" do
|
19
19
|
uses_api api
|
20
20
|
end
|
21
21
|
|
22
|
-
spawn_model
|
22
|
+
spawn_model "Foo::AdminUser" do
|
23
23
|
uses_api api
|
24
24
|
end
|
25
25
|
end # }}}
|
26
26
|
|
27
27
|
it "maps a single resource to a Ruby object" do # {{{
|
28
|
-
@user = User.find(1)
|
28
|
+
@user = Foo::User.find(1)
|
29
29
|
@user.id.should == 1
|
30
30
|
@user.name.should == "Tobias Fünke"
|
31
31
|
end # }}}
|
32
32
|
|
33
33
|
it "maps a collection of resources to an array of Ruby objects" do # {{{
|
34
|
-
@users = User.all
|
34
|
+
@users = Foo::User.all
|
35
35
|
@users.length.should == 2
|
36
36
|
@users.first.name.should == "Tobias Fünke"
|
37
37
|
|
38
|
-
@users = AdminUser.all
|
38
|
+
@users = Foo::AdminUser.all
|
39
39
|
@users.length.should == 2
|
40
40
|
@users.first.name.should == "Tobias Fünke"
|
41
41
|
end # }}}
|
42
42
|
|
43
43
|
it "handles new resource" do # {{{
|
44
|
-
@new_user = User.new(:fullname => "Tobias Fünke"
|
44
|
+
@new_user = Foo::User.new(:fullname => "Tobias Fünke")
|
45
45
|
@new_user.new?.should be_true
|
46
46
|
@new_user.fullname.should == "Tobias Fünke"
|
47
|
-
@new_user.medicine_license.should be_nil
|
48
47
|
|
49
|
-
@existing_user = User.find(1)
|
48
|
+
@existing_user = Foo::User.find(1)
|
50
49
|
@existing_user.new?.should be_false
|
51
50
|
end # }}}
|
52
51
|
|
53
52
|
it "handles method missing for getter" do# {{{
|
54
|
-
@new_user = User.new(:fullname => 'Mayonegg')
|
53
|
+
@new_user = Foo::User.new(:fullname => 'Mayonegg')
|
55
54
|
lambda { @new_user.unknown_method_for_a_user }.should raise_error(NoMethodError)
|
56
55
|
expect { @new_user.fullname }.to_not raise_error(NoMethodError)
|
57
56
|
end# }}}
|
58
57
|
|
59
58
|
it "handles method missing for setter" do# {{{
|
60
|
-
@new_user = User.new
|
59
|
+
@new_user = Foo::User.new
|
61
60
|
expect { @new_user.fullname = "Tobias Fünke" }.to_not raise_error(NoMethodError)
|
62
61
|
end# }}}
|
63
62
|
end
|
@@ -166,17 +165,17 @@ describe Her::Model::ORM do
|
|
166
165
|
end
|
167
166
|
end
|
168
167
|
|
169
|
-
spawn_model
|
168
|
+
spawn_model "Foo::User"
|
170
169
|
end # }}}
|
171
170
|
|
172
171
|
it "handle one-line resource creation" do # {{{
|
173
|
-
@user = User.create(:fullname => "Tobias Fünke")
|
172
|
+
@user = Foo::User.create(:fullname => "Tobias Fünke")
|
174
173
|
@user.id.should == 1
|
175
174
|
@user.fullname.should == "Tobias Fünke"
|
176
175
|
end # }}}
|
177
176
|
|
178
177
|
it "handle resource creation through Model.new + #save" do # {{{
|
179
|
-
@user = User.new(:fullname => "Tobias Fünke")
|
178
|
+
@user = Foo::User.new(:fullname => "Tobias Fünke")
|
180
179
|
@user.save
|
181
180
|
@user.fullname.should == "Tobias Fünke"
|
182
181
|
end # }}}
|
@@ -193,23 +192,23 @@ describe Her::Model::ORM do
|
|
193
192
|
end
|
194
193
|
end
|
195
194
|
|
196
|
-
spawn_model
|
195
|
+
spawn_model "Foo::User"
|
197
196
|
end # }}}
|
198
197
|
|
199
198
|
it "handle resource data update without saving it" do # {{{
|
200
|
-
@user = User.find(1)
|
199
|
+
@user = Foo::User.find(1)
|
201
200
|
@user.fullname.should == "Tobias Fünke"
|
202
201
|
@user.fullname = "Kittie Sanchez"
|
203
202
|
@user.fullname.should == "Kittie Sanchez"
|
204
203
|
end # }}}
|
205
204
|
|
206
205
|
it "handle resource update through the .update class method" do # {{{
|
207
|
-
@user = User.save_existing(1, { :fullname => "Lindsay Fünke" })
|
206
|
+
@user = Foo::User.save_existing(1, { :fullname => "Lindsay Fünke" })
|
208
207
|
@user.fullname.should == "Lindsay Fünke"
|
209
208
|
end # }}}
|
210
209
|
|
211
210
|
it "handle resource update through #save on an existing resource" do # {{{
|
212
|
-
@user = User.find(1)
|
211
|
+
@user = Foo::User.find(1)
|
213
212
|
@user.fullname = "Lindsay Fünke"
|
214
213
|
@user.save
|
215
214
|
@user.fullname.should == "Lindsay Fünke"
|
@@ -227,16 +226,16 @@ describe Her::Model::ORM do
|
|
227
226
|
end
|
228
227
|
end
|
229
228
|
|
230
|
-
spawn_model
|
229
|
+
spawn_model "Foo::User"
|
231
230
|
end # }}}
|
232
231
|
|
233
232
|
it "handle resource deletion through the .destroy class method" do # {{{
|
234
|
-
@user = User.destroy_existing(1)
|
233
|
+
@user = Foo::User.destroy_existing(1)
|
235
234
|
@user.active.should be_false
|
236
235
|
end # }}}
|
237
236
|
|
238
237
|
it "handle resource deletion through #destroy on an existing resource" do # {{{
|
239
|
-
@user = User.find(1)
|
238
|
+
@user = Foo::User.find(1)
|
240
239
|
@user.destroy
|
241
240
|
@user.active.should be_false
|
242
241
|
end # }}}
|
data/spec/model/paths_spec.rb
CHANGED
@@ -5,85 +5,85 @@ describe Her::Model::Paths do
|
|
5
5
|
context "building request paths" do
|
6
6
|
context "simple model" do
|
7
7
|
before do # {{{
|
8
|
-
spawn_model
|
8
|
+
spawn_model "Foo::User"
|
9
9
|
end # }}}
|
10
10
|
|
11
11
|
describe "#build_request_path" do
|
12
12
|
it "builds paths with defaults" do # {{{
|
13
|
-
User.build_request_path(:id => "foo").should == "/users/foo"
|
14
|
-
User.build_request_path.should == "/users"
|
13
|
+
Foo::User.build_request_path(:id => "foo").should == "/users/foo"
|
14
|
+
Foo::User.build_request_path.should == "/users"
|
15
15
|
end # }}}
|
16
16
|
|
17
17
|
it "builds paths with custom collection path" do # {{{
|
18
|
-
User.collection_path "/utilisateurs"
|
19
|
-
User.build_request_path(:id => "foo").should == "/utilisateurs/foo"
|
20
|
-
User.build_request_path.should == "/utilisateurs"
|
18
|
+
Foo::User.collection_path "/utilisateurs"
|
19
|
+
Foo::User.build_request_path(:id => "foo").should == "/utilisateurs/foo"
|
20
|
+
Foo::User.build_request_path.should == "/utilisateurs"
|
21
21
|
end # }}}
|
22
22
|
|
23
23
|
it "builds paths with custom collection path with multiple variables" do # {{{
|
24
|
-
User.collection_path "/organizations/:organization_id/utilisateurs"
|
25
|
-
User.build_request_path(:id => "foo", :_organization_id => "acme").should == "/organizations/acme/utilisateurs/foo"
|
26
|
-
User.build_request_path(:_organization_id => "acme").should == "/organizations/acme/utilisateurs"
|
24
|
+
Foo::User.collection_path "/organizations/:organization_id/utilisateurs"
|
25
|
+
Foo::User.build_request_path(:id => "foo", :_organization_id => "acme").should == "/organizations/acme/utilisateurs/foo"
|
26
|
+
Foo::User.build_request_path(:_organization_id => "acme").should == "/organizations/acme/utilisateurs"
|
27
27
|
end # }}}
|
28
28
|
|
29
29
|
it "builds paths with custom item path" do # {{{
|
30
|
-
User.resource_path "/utilisateurs/:id"
|
31
|
-
User.build_request_path(:id => "foo").should == "/utilisateurs/foo"
|
32
|
-
User.build_request_path.should == "/users"
|
30
|
+
Foo::User.resource_path "/utilisateurs/:id"
|
31
|
+
Foo::User.build_request_path(:id => "foo").should == "/utilisateurs/foo"
|
32
|
+
Foo::User.build_request_path.should == "/users"
|
33
33
|
end # }}}
|
34
34
|
|
35
35
|
it "raises exceptions when building a path without required custom variables" do # {{{
|
36
|
-
User.collection_path "/organizations/:organization_id/utilisateurs"
|
37
|
-
expect { User.build_request_path(:id => "foo") }.
|
36
|
+
Foo::User.collection_path "/organizations/:organization_id/utilisateurs"
|
37
|
+
expect { Foo::User.build_request_path(:id => "foo") }.to raise_error(Her::Errors::PathError)
|
38
38
|
end # }}}
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context "simple model with multiple words" do
|
43
43
|
before do # {{{
|
44
|
-
spawn_model
|
44
|
+
spawn_model "Foo::AdminUser"
|
45
45
|
end # }}}
|
46
46
|
|
47
47
|
describe "#build_request_path" do
|
48
48
|
it "builds paths with defaults" do # {{{
|
49
|
-
AdminUser.build_request_path(:id => "foo").should == "/admin_users/foo"
|
50
|
-
AdminUser.build_request_path.should == "/admin_users"
|
49
|
+
Foo::AdminUser.build_request_path(:id => "foo").should == "/admin_users/foo"
|
50
|
+
Foo::AdminUser.build_request_path.should == "/admin_users"
|
51
51
|
end # }}}
|
52
52
|
|
53
53
|
it "builds paths with custom collection path" do # {{{
|
54
|
-
AdminUser.collection_path "/users"
|
55
|
-
AdminUser.build_request_path(:id => "foo").should == "/users/foo"
|
56
|
-
AdminUser.build_request_path.should == "/users"
|
54
|
+
Foo::AdminUser.collection_path "/users"
|
55
|
+
Foo::AdminUser.build_request_path(:id => "foo").should == "/users/foo"
|
56
|
+
Foo::AdminUser.build_request_path.should == "/users"
|
57
57
|
end # }}}
|
58
58
|
|
59
59
|
it "builds paths with custom collection path with multiple variables" do # {{{
|
60
|
-
AdminUser.collection_path "/organizations/:organization_id/users"
|
61
|
-
AdminUser.build_request_path(:id => "foo", :_organization_id => "acme").should == "/organizations/acme/users/foo"
|
62
|
-
AdminUser.build_request_path(:_organization_id => "acme").should == "/organizations/acme/users"
|
60
|
+
Foo::AdminUser.collection_path "/organizations/:organization_id/users"
|
61
|
+
Foo::AdminUser.build_request_path(:id => "foo", :_organization_id => "acme").should == "/organizations/acme/users/foo"
|
62
|
+
Foo::AdminUser.build_request_path(:_organization_id => "acme").should == "/organizations/acme/users"
|
63
63
|
end # }}}
|
64
64
|
|
65
65
|
it "builds paths with custom item path" do # {{{
|
66
|
-
AdminUser.resource_path "/users/:id"
|
67
|
-
AdminUser.build_request_path(:id => "foo").should == "/users/foo"
|
68
|
-
AdminUser.build_request_path.should == "/admin_users"
|
66
|
+
Foo::AdminUser.resource_path "/users/:id"
|
67
|
+
Foo::AdminUser.build_request_path(:id => "foo").should == "/users/foo"
|
68
|
+
Foo::AdminUser.build_request_path.should == "/admin_users"
|
69
69
|
end # }}}
|
70
70
|
|
71
71
|
it "raises exceptions when building a path without required custom variables" do # {{{
|
72
|
-
AdminUser.collection_path "/organizations/:organization_id/users"
|
73
|
-
expect { AdminUser.build_request_path(:id => "foo") }.
|
72
|
+
Foo::AdminUser.collection_path "/organizations/:organization_id/users"
|
73
|
+
expect { Foo::AdminUser.build_request_path(:id => "foo") }.to raise_error(Her::Errors::PathError)
|
74
74
|
end # }}}
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
context "nested model" do
|
79
79
|
before do # {{{
|
80
|
-
|
80
|
+
spawn_model "Foo::User"
|
81
81
|
end # }}}
|
82
82
|
|
83
83
|
describe "#build_request_path" do
|
84
84
|
it "builds paths with defaults" do # {{{
|
85
|
-
|
86
|
-
|
85
|
+
Foo::User.build_request_path(:id => "foo").should == "/users/foo"
|
86
|
+
Foo::User.build_request_path.should == "/users"
|
87
87
|
end # }}}
|
88
88
|
end
|
89
89
|
end
|
@@ -103,14 +103,14 @@ describe Her::Model::Paths do
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
spawn_model
|
106
|
+
spawn_model "Foo::User" do
|
107
107
|
collection_path "/organizations/:organization_id/users"
|
108
108
|
end
|
109
109
|
end # }}}
|
110
110
|
|
111
111
|
describe "fetching a resource" do
|
112
112
|
it "maps a single resource to a Ruby object" do # {{{
|
113
|
-
@user = User.find(1, :_organization_id => 2)
|
113
|
+
@user = Foo::User.find(1, :_organization_id => 2)
|
114
114
|
@user.id.should == 1
|
115
115
|
@user.fullname.should == "Tobias Fünke"
|
116
116
|
end # }}}
|
@@ -118,7 +118,7 @@ describe Her::Model::Paths do
|
|
118
118
|
|
119
119
|
describe "fetching a collection" do
|
120
120
|
it "maps a collection of resources to an array of Ruby objects" do # {{{
|
121
|
-
@users = User.all(:_organization_id => 2)
|
121
|
+
@users = Foo::User.all(:_organization_id => 2)
|
122
122
|
@users.length.should == 2
|
123
123
|
@users.first.fullname.should == "Tobias Fünke"
|
124
124
|
end # }}}
|
@@ -126,23 +126,23 @@ describe Her::Model::Paths do
|
|
126
126
|
|
127
127
|
describe "handling new resource" do
|
128
128
|
it "handles new resource" do # {{{
|
129
|
-
@new_user = User.new(:fullname => "Tobias Fünke", :organization_id => 2)
|
129
|
+
@new_user = Foo::User.new(:fullname => "Tobias Fünke", :organization_id => 2)
|
130
130
|
@new_user.new?.should be_true
|
131
131
|
|
132
|
-
@existing_user = User.find(1, :_organization_id => 2)
|
132
|
+
@existing_user = Foo::User.find(1, :_organization_id => 2)
|
133
133
|
@existing_user.new?.should be_false
|
134
134
|
end # }}}
|
135
135
|
end
|
136
136
|
|
137
137
|
describe "creating resources" do
|
138
138
|
it "handle one-line resource creation" do # {{{
|
139
|
-
@user = User.create(:fullname => "Tobias Fünke", :organization_id => 2)
|
139
|
+
@user = Foo::User.create(:fullname => "Tobias Fünke", :organization_id => 2)
|
140
140
|
@user.id.should == 1
|
141
141
|
@user.fullname.should == "Tobias Fünke"
|
142
142
|
end # }}}
|
143
143
|
|
144
144
|
it "handle resource creation through Model.new + #save" do # {{{
|
145
|
-
@user = User.new(:fullname => "Tobias Fünke", :organization_id => 2)
|
145
|
+
@user = Foo::User.new(:fullname => "Tobias Fünke", :organization_id => 2)
|
146
146
|
@user.save
|
147
147
|
@user.fullname.should == "Tobias Fünke"
|
148
148
|
end # }}}
|
@@ -150,19 +150,19 @@ describe Her::Model::Paths do
|
|
150
150
|
|
151
151
|
context "updating resources" do
|
152
152
|
it "handle resource data update without saving it" do # {{{
|
153
|
-
@user = User.find(1, :_organization_id => 2)
|
153
|
+
@user = Foo::User.find(1, :_organization_id => 2)
|
154
154
|
@user.fullname.should == "Tobias Fünke"
|
155
155
|
@user.fullname = "Kittie Sanchez"
|
156
156
|
@user.fullname.should == "Kittie Sanchez"
|
157
157
|
end # }}}
|
158
158
|
|
159
159
|
it "handle resource update through the .update class method" do # {{{
|
160
|
-
@user = User.save_existing(1, { :fullname => "Lindsay Fünke", :organization_id => 2 })
|
160
|
+
@user = Foo::User.save_existing(1, { :fullname => "Lindsay Fünke", :organization_id => 2 })
|
161
161
|
@user.fullname.should == "Lindsay Fünke"
|
162
162
|
end # }}}
|
163
163
|
|
164
164
|
it "handle resource update through #save on an existing resource" do # {{{
|
165
|
-
@user = User.find(1, :_organization_id => 2)
|
165
|
+
@user = Foo::User.find(1, :_organization_id => 2)
|
166
166
|
@user.fullname = "Lindsay Fünke"
|
167
167
|
@user.save
|
168
168
|
@user.fullname.should == "Lindsay Fünke"
|
@@ -171,12 +171,12 @@ describe Her::Model::Paths do
|
|
171
171
|
|
172
172
|
context "deleting resources" do
|
173
173
|
it "handle resource deletion through the .destroy class method" do # {{{
|
174
|
-
@user = User.destroy_existing(1, :_organization_id => 2)
|
174
|
+
@user = Foo::User.destroy_existing(1, :_organization_id => 2)
|
175
175
|
@user.active.should be_false
|
176
176
|
end # }}}
|
177
177
|
|
178
178
|
it "handle resource deletion through #destroy on an existing resource" do # {{{
|
179
|
-
@user = User.find(1, :_organization_id => 2)
|
179
|
+
@user = Foo::User.find(1, :_organization_id => 2)
|
180
180
|
@user.destroy
|
181
181
|
@user.active.should be_false
|
182
182
|
end # }}}
|