aegis 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.2
1
+ 2.0.3
data/aegis.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aegis}
8
- s.version = "2.0.2"
8
+ s.version = "2.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Henning Koch", "Tobias Kraze"]
@@ -62,6 +62,7 @@ Gem::Specification.new do |s|
62
62
  "spec/loader_spec.rb",
63
63
  "spec/permissions_spec.rb",
64
64
  "spec/rcov.opts",
65
+ "spec/sieve_spec.rb",
65
66
  "spec/spec.opts",
66
67
  "spec/spec_helper.rb"
67
68
  ]
@@ -94,7 +95,8 @@ Gem::Specification.new do |s|
94
95
  "spec/has_role_spec.rb",
95
96
  "spec/permissions_spec.rb",
96
97
  "spec/spec_helper.rb",
97
- "spec/loader_spec.rb"
98
+ "spec/loader_spec.rb",
99
+ "spec/sieve_spec.rb"
98
100
  ]
99
101
 
100
102
  if s.respond_to? :specification_version then
data/lib/aegis/sieve.rb CHANGED
@@ -9,7 +9,7 @@ module Aegis
9
9
  end
10
10
 
11
11
  def may?(context, *args)
12
- matches_role = @role_name == 'everyone' || @role_name == context.user.role_name
12
+ matches_role = @role_name == 'everyone' || @role_name == context.user.role.name
13
13
  if matches_role
14
14
  if @block
15
15
  block_result = context.instance_exec(*args, &@block)
data/spec/loader_spec.rb CHANGED
@@ -16,9 +16,22 @@ describe Aegis::Loader do
16
16
 
17
17
  end
18
18
 
19
+ describe 'load_paths' do
20
+
21
+ it "should require all paths" do
22
+
23
+ Aegis::Loader.stub(:paths => ['one', 'two'])
24
+ Aegis::Loader.should_receive(:require).with('one')
25
+ Aegis::Loader.should_receive(:require).with('two')
26
+ Aegis::Loader.load_paths
27
+
28
+ end
29
+
30
+ end
31
+
19
32
  describe 'loaded?' do
20
33
 
21
- it "should be loaded" do
34
+ it "should be loaded by the time this test runs" do
22
35
  Aegis::Loader.should be_loaded
23
36
  end
24
37
 
@@ -196,8 +196,8 @@ describe Aegis::Permissions do
196
196
  frank = @user_class.new(:name => 'Frank', :role_name => 'user')
197
197
  waldo = @user_class.new(:name => 'Waldo', :role_name => 'user')
198
198
 
199
- frank.may_update_post?('the post').should be_false
200
- waldo.may_update_post?('the post').should be_true
199
+ @permissions.may?(frank, 'update_post', 'the post').should be_false
200
+ @permissions.may?(waldo, 'update_post', 'the post').should be_true
201
201
 
202
202
  end
203
203
 
@@ -317,8 +317,8 @@ describe Aegis::Permissions do
317
317
  end
318
318
 
319
319
  @user.stub(:password => "secret")
320
- @user.may_sign_in?("wrong_password").should be_false
321
- @user.may_sign_in?("secret").should be_true
320
+ @permissions.may?(@user, "sign_in", "wrong_password").should be_false
321
+ @permissions.may?(@user, "sign_in", "secret").should be_true
322
322
 
323
323
  end
324
324
 
@@ -335,7 +335,7 @@ describe Aegis::Permissions do
335
335
  end
336
336
 
337
337
  spy.should_receive(:observe).with("the property", "the comment", "additional argument")
338
- @moderator.may_update_property_comment?("the property", "the comment", "additional argument")
338
+ @permissions.may?(@moderator, "update_property_comment", "the property", "the comment", "additional argument")
339
339
  end
340
340
 
341
341
  it "should evaluate additional resource actions" do
@@ -487,32 +487,32 @@ describe Aegis::Permissions do
487
487
  @permissions.class_eval do
488
488
  missing_action_means :default_permission
489
489
  end
490
- @user.may_missing_action?.should be_false
491
- @admin.may_missing_action?.should be_true
490
+ @permissions.may?(@user, 'missing_action').should be_false
491
+ @permissions.may?(@admin, 'missing_action').should be_true
492
492
  end
493
493
 
494
494
  it "should grant everyone access if the strategy is :allow" do
495
495
  @permissions.class_eval do
496
496
  missing_action_means :allow
497
497
  end
498
- @user.may_missing_action?.should be_true
499
- @admin.may_missing_action?.should be_true
498
+ @permissions.may?(@user, 'missing_action').should be_true
499
+ @permissions.may?(@admin, 'missing_action').should be_true
500
500
  end
501
501
 
502
502
  it "should deny everyone access if the strategy is :deny" do
503
503
  @permissions.class_eval do
504
504
  missing_action_means :deny
505
505
  end
506
- @user.may_missing_action?.should be_false
507
- @admin.may_missing_action?.should be_false
506
+ @permissions.may?(@user, 'missing_action').should be_false
507
+ @permissions.may?(@admin, 'missing_action').should be_false
508
508
  end
509
509
 
510
510
  it "should raise an error if the strategy is :error" do
511
511
  @permissions.class_eval do
512
512
  missing_action_means :error
513
513
  end
514
- lambda { @user.may_missing_action? }.should raise_error
515
- lambda { @admin.may_missing_action? }.should raise_error
514
+ lambda { @permissions.may?(@user, 'missing_action') }.should raise_error
515
+ lambda { @permissions.may?(@admin, 'missing_action') }.should raise_error
516
516
  end
517
517
 
518
518
  end
@@ -546,5 +546,26 @@ describe Aegis::Permissions do
546
546
 
547
547
  end
548
548
 
549
+ describe 'find_action_by_path' do
550
+
551
+ before(:each) do
552
+ @permissions.class_eval do
553
+ action :action_name do
554
+ allow :user
555
+ end
556
+ end
557
+ end
558
+
559
+ it "should find an action by a string" do
560
+ @permissions.find_action_by_path('action_name').should_not be_abstract
561
+ end
562
+
563
+ it "should find an action by a symbol" do
564
+ @permissions.find_action_by_path(:action_name).should_not be_abstract
565
+ end
566
+
567
+ end
568
+
569
+
549
570
  end
550
571
 
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe Aegis::Sieve do
4
+
5
+ before(:each) do
6
+ @role = stub('role', :name => 'user')
7
+ @user = stub('user', :role => @role)
8
+ @context = OpenStruct.new(:user => @user)
9
+ end
10
+
11
+ describe 'may? 'do
12
+
13
+ it "should use the role's name to find out if the sieve matches" do
14
+ @role.should_receive(:name)
15
+ Aegis::Sieve.new('moderator', true).may?(@context)
16
+ end
17
+
18
+ it "should return nil if the sieve doesn't match the role" do
19
+ Aegis::Sieve.new('moderator', true).may?(@context).should be_nil
20
+ end
21
+
22
+ it "should return the effect if the sieve matches the role" do
23
+ Aegis::Sieve.new('user', true).may?(@context).should be_true
24
+ Aegis::Sieve.new('user', false).may?(@context).should be_false
25
+ end
26
+
27
+ it "should match any role if its role name is set to 'everyone'" do
28
+ Aegis::Sieve.new('everyone', true).may?(@context).should be_true
29
+ Aegis::Sieve.new('everyone', false).may?(@context).should be_false
30
+ end
31
+
32
+ context "with a block" do
33
+
34
+ it "should return the effect if the block evaluates to true" do
35
+ Aegis::Sieve.new('user', true, lambda { true }).may?(@context).should be_true
36
+ Aegis::Sieve.new('user', false, lambda { true }).may?(@context).should be_false
37
+ end
38
+
39
+ it "should invert the effect if the block evaluates to false" do
40
+ Aegis::Sieve.new('user', true, lambda { false }).may?(@context).should be_false
41
+ Aegis::Sieve.new('user', false, lambda { false }).may?(@context).should be_true
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
48
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 0
8
- - 2
9
- version: 2.0.2
8
+ - 3
9
+ version: 2.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Henning Koch
@@ -74,6 +74,7 @@ files:
74
74
  - spec/loader_spec.rb
75
75
  - spec/permissions_spec.rb
76
76
  - spec/rcov.opts
77
+ - spec/sieve_spec.rb
77
78
  - spec/spec.opts
78
79
  - spec/spec_helper.rb
79
80
  has_rdoc: true
@@ -131,3 +132,4 @@ test_files:
131
132
  - spec/permissions_spec.rb
132
133
  - spec/spec_helper.rb
133
134
  - spec/loader_spec.rb
135
+ - spec/sieve_spec.rb