trust 0.7.0 → 0.8.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.
- data/README.md +10 -4
- data/lib/trust/actor.rb +7 -1
- data/lib/trust/controller/resource.rb +56 -20
- data/lib/trust/controller.rb +20 -20
- data/lib/trust/permissions.rb +95 -28
- data/lib/trust/test_helper.rb +5 -1
- data/lib/trust/version.rb +1 -1
- data/test/dummy/log/test.log +11445 -0
- data/test/unit/trust/controller/resource_test.rb +21 -6
- data/test/unit/trust/permissions_test.rb +51 -0
- metadata +4 -4
@@ -70,6 +70,21 @@ class Trust::Controller::ResourceTest < ActiveSupport::TestCase
|
|
70
70
|
should 'resolve parameter' do
|
71
71
|
assert_equal 'cool', @res.params
|
72
72
|
end
|
73
|
+
context 'collection' do
|
74
|
+
should 'return array where parent represented' do
|
75
|
+
parent = stub('parent', :object => 12)
|
76
|
+
@res.expects(:association_name).with(parent).returns(15)
|
77
|
+
assert_equal [12, 15], @res.collection(parent)
|
78
|
+
end
|
79
|
+
should 'return class where no parent' do
|
80
|
+
assert_equal NameSpacedResource::MyEntity, @res.collection(nil)
|
81
|
+
end
|
82
|
+
should 'return with instance if present' do
|
83
|
+
parent = stub('parent', :object => 12)
|
84
|
+
@res.expects(:association_name).never
|
85
|
+
assert_equal [12, 15], @res.collection(parent, 15)
|
86
|
+
end
|
87
|
+
end
|
73
88
|
end
|
74
89
|
|
75
90
|
context 'Irregular Instance' do
|
@@ -216,34 +231,34 @@ class Trust::Controller::ResourceTest < ActiveSupport::TestCase
|
|
216
231
|
setup do
|
217
232
|
Trust::Controller::Resource.any_instance.expects(:extract_resource_info).with('child', {}).returns(@resource_info)
|
218
233
|
Trust::Controller::Resource.any_instance.expects(:extract_parent_info).with({:parent => nil}, {}, @request).returns(@parent_info)
|
219
|
-
end
|
220
|
-
should 'instantiate properly' do
|
221
234
|
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
222
235
|
end
|
223
236
|
should 'discover variable names' do
|
224
|
-
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
225
237
|
@resource_info.expects(:plural_name).returns(:children)
|
226
238
|
assert_equal :child, @resource.send(:instance_name)
|
227
239
|
assert_equal :parent, @resource.send(:parent_name)
|
228
240
|
assert_equal :children, @resource.send(:plural_instance_name)
|
229
241
|
end
|
230
242
|
should 'have access to instances' do
|
231
|
-
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
232
243
|
@resource.expects(:plural_instance_name).twice.returns(:children)
|
233
244
|
@resource.instances = [1]
|
234
245
|
assert_equal [1], @resource.instances
|
235
246
|
assert_equal [1], @controller.instance_variable_get(:@children)
|
236
247
|
end
|
237
248
|
should 'have access to instantiated' do
|
238
|
-
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
239
249
|
@resource.expects(:instances).returns(1)
|
240
250
|
assert_equal 1, @resource.instantiated
|
241
251
|
@resource.expects(:instances).returns(nil)
|
242
252
|
@resource.expects(:instance).returns(2)
|
243
253
|
assert_equal 2, @resource.instantiated
|
244
254
|
end
|
255
|
+
should 'provide collection' do
|
256
|
+
@resource_info.expects(:collection).with(@parent_info, nil).returns(1)
|
257
|
+
assert_equal 1, @resource.collection
|
258
|
+
@resource_info.expects(:collection).with(@parent_info, 2).returns(3)
|
259
|
+
assert_equal 3, @resource.collection(2)
|
260
|
+
end
|
245
261
|
should 'load as expected' do
|
246
|
-
@resource = Trust::Controller::Resource.new(@controller, @properties, 'new',{}, @request)
|
247
262
|
@resource_info.stubs(:params).returns({})
|
248
263
|
@controller.expects(:respond_to?).with(:build).returns(false)
|
249
264
|
@resource.load
|
@@ -254,5 +254,56 @@ class Trust::PermissionsTest < ActiveSupport::TestCase
|
|
254
254
|
expect = {:tester => [[:hi, {:if=>:ho}], [:wink, {}], [:hi, {:if=>:ha}]]}
|
255
255
|
assert_equal expect, TestOverride.permissions
|
256
256
|
end
|
257
|
+
|
258
|
+
context 'with cannot' do
|
259
|
+
should 'not accept options' do
|
260
|
+
class TestCannnotArgumentError < Trust::Permissions
|
261
|
+
end
|
262
|
+
assert_raises ArgumentError do
|
263
|
+
TestCannnotArgumentError.cannot :do, :options => true
|
264
|
+
end
|
265
|
+
end
|
266
|
+
should 'revoke permissions' do
|
267
|
+
class TestBaseAuth3 < Trust::Permissions
|
268
|
+
role :tester, :friend do
|
269
|
+
can :hi, :if => :ho
|
270
|
+
can :wink
|
271
|
+
end
|
272
|
+
end
|
273
|
+
expect = {:tester => [[:hi, {:if => :ho}],[:wink, {}]], :friend => [[:hi, {:if => :ho}],[:wink, {}]]}
|
274
|
+
assert_equal expect, TestBaseAuth3.permissions
|
275
|
+
class TestCannot < TestBaseAuth3
|
276
|
+
role :tester, cannot(:wink)
|
277
|
+
role :friend do
|
278
|
+
cannot :hi
|
279
|
+
end
|
280
|
+
end
|
281
|
+
expect = {:tester => [[:hi, {:if => :ho}]], :friend => [[:wink, {}]]}
|
282
|
+
assert_equal expect, TestCannot.permissions
|
283
|
+
end
|
284
|
+
end
|
285
|
+
context 'with enforce' do
|
286
|
+
should 'override previous cans' do
|
287
|
+
class TestBaseAuth4 < Trust::Permissions
|
288
|
+
role :tester, :friend do
|
289
|
+
can :hi, :if => :ho
|
290
|
+
can :wink
|
291
|
+
end
|
292
|
+
end
|
293
|
+
expect = {:tester => [[:hi, {:if => :ho}],[:wink, {}]], :friend => [[:hi, {:if => :ho}],[:wink, {}]]}
|
294
|
+
assert_equal expect, TestBaseAuth4.permissions
|
295
|
+
class TestEnforce < TestBaseAuth4
|
296
|
+
role :tester, can(:wink, :enforce => true, :if => :yo)
|
297
|
+
role :friend do
|
298
|
+
can :hi, :enforce => true, :if => :sure
|
299
|
+
end
|
300
|
+
end
|
301
|
+
expect = {:tester => [[:hi, {:if => :ho}],[:wink, {:if => :yo}]], :friend => [[:wink, {}],[:hi, {:if => :sure}]]}
|
302
|
+
assert_equal expect, TestEnforce.permissions
|
303
|
+
# Parent permissions should not be affected
|
304
|
+
expect = {:tester => [[:hi, {:if => :ho}],[:wink, {}]], :friend => [[:hi, {:if => :ho}],[:wink, {}]]}
|
305
|
+
assert_equal expect, TestBaseAuth4.permissions
|
306
|
+
end
|
307
|
+
end
|
257
308
|
end
|
258
309
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trust
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-10-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -200,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
200
|
version: '0'
|
201
201
|
segments:
|
202
202
|
- 0
|
203
|
-
hash:
|
203
|
+
hash: 608733387918017970
|
204
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
205
|
none: false
|
206
206
|
requirements:
|
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
version: '0'
|
210
210
|
segments:
|
211
211
|
- 0
|
212
|
-
hash:
|
212
|
+
hash: 608733387918017970
|
213
213
|
requirements: []
|
214
214
|
rubyforge_project:
|
215
215
|
rubygems_version: 1.8.24
|