trust 0.6.0 → 0.6.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.
@@ -208,43 +208,83 @@ class Trust::Controller::ResourceTest < ActiveSupport::TestCase
|
|
208
208
|
@parent_info = stub(:object => 6, :name => :parent)
|
209
209
|
@resource_info.expects(:relation).with(@parent_info).returns(Child)
|
210
210
|
@resource_info.stubs(:name).returns(:child)
|
211
|
-
Trust::Controller::Resource.any_instance.expects(:extract_resource_info).with('child', {}).returns(@resource_info)
|
212
|
-
Trust::Controller::Resource.any_instance.expects(:extract_parent_info).with({:parent => nil}, {}, @request).returns(@parent_info)
|
213
211
|
end
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
212
|
+
context 'Plain' do
|
213
|
+
setup do
|
214
|
+
Trust::Controller::Resource.any_instance.expects(:extract_resource_info).with('child', {}).returns(@resource_info)
|
215
|
+
Trust::Controller::Resource.any_instance.expects(:extract_parent_info).with({:parent => nil}, {}, @request).returns(@parent_info)
|
216
|
+
end
|
217
|
+
should 'instantiate properly' do
|
218
|
+
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
219
|
+
end
|
220
|
+
should 'discover variable names' do
|
221
|
+
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
222
|
+
@resource_info.expects(:plural_name).returns(:children)
|
223
|
+
assert_equal :child, @resource.send(:instance_name)
|
224
|
+
assert_equal :parent, @resource.send(:parent_name)
|
225
|
+
assert_equal :children, @resource.send(:plural_instance_name)
|
226
|
+
end
|
227
|
+
should 'have access to instances' do
|
228
|
+
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
229
|
+
@resource.expects(:plural_instance_name).twice.returns(:children)
|
230
|
+
@resource.instances = [1]
|
231
|
+
assert_equal [1], @resource.instances
|
232
|
+
assert_equal [1], @controller.instance_variable_get(:@children)
|
233
|
+
end
|
234
|
+
should 'have access to instantiated' do
|
235
|
+
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
236
|
+
@resource.expects(:instances).returns(1)
|
237
|
+
assert_equal 1, @resource.instantiated
|
238
|
+
@resource.expects(:instances).returns(nil)
|
239
|
+
@resource.expects(:instance).returns(2)
|
240
|
+
assert_equal 2, @resource.instantiated
|
241
|
+
end
|
242
|
+
should 'load as expected' do
|
243
|
+
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
244
|
+
@resource_info.stubs(:params).returns({})
|
245
|
+
@controller.expects(:respond_to?).with(:build).returns(false)
|
246
|
+
@resource.load
|
247
|
+
assert_equal 6, @controller.instance_variable_get(:@parent)
|
248
|
+
assert_equal 6, @resource.parent
|
249
|
+
assert @controller.instance_variable_get(:@child).is_a?(Child)
|
250
|
+
assert @resource.instance.is_a?(Child)
|
251
|
+
end
|
230
252
|
end
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
253
|
+
context 'Member actions' do
|
254
|
+
setup do
|
255
|
+
Trust::Controller::Resource.any_instance.expects(:extract_resource_info).with('child', { :id => 1 }).returns(@resource_info)
|
256
|
+
Trust::Controller::Resource.any_instance.expects(:extract_parent_info).with({:parent => nil}, { :id => 1 }, @request).returns(@parent_info)
|
257
|
+
end
|
258
|
+
should 'load as expected' do
|
259
|
+
@resource = Trust::Controller::Resource.new(@controller, @properties, 'member',{ :id => 1 }, @request)
|
260
|
+
@properties.actions :member => [:member]
|
261
|
+
@resource_info.stubs(:params).returns({})
|
262
|
+
@controller.expects(:respond_to?).with(:build).returns(false)
|
263
|
+
Child.expects(:find).with(1).returns(Child.new)
|
264
|
+
@resource.load
|
265
|
+
assert_equal 6, @controller.instance_variable_get(:@parent)
|
266
|
+
assert_equal 6, @resource.parent
|
267
|
+
assert @controller.instance_variable_get(:@child).is_a?(Child)
|
268
|
+
assert @resource.instance.is_a?(Child)
|
269
|
+
end
|
238
270
|
end
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
271
|
+
context 'Nested resources' do
|
272
|
+
setup do
|
273
|
+
Trust::Controller::Resource.any_instance.expects(:extract_resource_info).with('child', { :child_id => 1 }).returns(@resource_info)
|
274
|
+
Trust::Controller::Resource.any_instance.expects(:extract_parent_info).with({:parent => nil}, { :child_id => 1 }, @request).returns(@parent_info)
|
275
|
+
end
|
276
|
+
should 'load as expected' do
|
277
|
+
@resource = Trust::Controller::Resource.new(@controller, @properties, 'member',{ :child_id => 1 }, @request)
|
278
|
+
@properties.actions :member => [:member]
|
279
|
+
@resource_info.stubs(:params).returns({})
|
280
|
+
@controller.expects(:respond_to?).with(:build).returns(false)
|
281
|
+
Child.expects(:find).with(1).returns(Child.new)
|
282
|
+
@resource.load
|
283
|
+
assert_equal 6, @controller.instance_variable_get(:@parent)
|
284
|
+
assert_equal 6, @resource.parent
|
285
|
+
assert @controller.instance_variable_get(:@child).is_a?(Child)
|
286
|
+
assert @resource.instance.is_a?(Child)
|
287
|
+
end
|
248
288
|
end
|
249
289
|
end
|
250
290
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: trust
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.6.
|
5
|
+
version: 0.6.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Patrick Hanevold
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-07-20 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -188,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
188
|
requirements:
|
189
189
|
- - ">="
|
190
190
|
- !ruby/object:Gem::Version
|
191
|
-
hash:
|
191
|
+
hash: -4478100999703184470
|
192
192
|
segments:
|
193
193
|
- 0
|
194
194
|
version: "0"
|
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
197
|
requirements:
|
198
198
|
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
|
-
hash:
|
200
|
+
hash: -4478100999703184470
|
201
201
|
segments:
|
202
202
|
- 0
|
203
203
|
version: "0"
|