walruz 0.0.6 → 0.0.7

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.
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Walruz::CoreExt::Array do
4
+
5
+ it "should add an 'only_authorized_for' method" do
6
+ [].should respond_to(:only_authorized_for)
7
+ end
8
+
9
+ describe "#only_authorized_for" do
10
+
11
+ before(:each) do
12
+ @songs = [
13
+ Song::A_DAY_IN_LIFE,
14
+ Song::YELLOW_SUBMARINE,
15
+ Song::TAXMAN,
16
+ Song::YESTERDAY,
17
+ Song::ALL_YOU_NEED_IS_LOVE,
18
+ Song::BLUE_JAY_WAY,
19
+ ]
20
+ end
21
+
22
+ describe "using an action as a parameter with option :action" do
23
+
24
+ shared_examples_for "only_authorized with action as a parameter expectations" do
25
+
26
+ it "should remove the elements that are not authorized" do
27
+ @songs.only_authorized_for(Beatle::JOHN, @options).should == [
28
+ Song::A_DAY_IN_LIFE,
29
+ Song::YELLOW_SUBMARINE,
30
+ Song::TAXMAN,
31
+ Song::ALL_YOU_NEED_IS_LOVE]
32
+ @songs.only_authorized_for(Beatle::PAUL, @options).should == [
33
+ Song::A_DAY_IN_LIFE,
34
+ Song::YELLOW_SUBMARINE,
35
+ Song::YESTERDAY]
36
+ @songs.only_authorized_for(Beatle::GEORGE, @options).should == [Song::TAXMAN, Song::BLUE_JAY_WAY]
37
+ @songs.only_authorized_for(Beatle::RINGO, @options).should be_empty
38
+ end
39
+
40
+ end
41
+
42
+ describe "with a hash and an option :action" do
43
+
44
+ before(:each) do
45
+ @options = { :action => :sing }
46
+ end
47
+
48
+ it_should_behave_like "only_authorized with action as a parameter expectations"
49
+
50
+ end
51
+
52
+ describe "with just a symbol" do
53
+
54
+ before(:each) do
55
+ @options = :sing
56
+ end
57
+
58
+ it_should_behave_like "only_authorized with action as a parameter expectations"
59
+
60
+ end
61
+
62
+ end
63
+
64
+ describe "with option :policy" do
65
+
66
+ before(:each) do
67
+ @options = { :policy => :in_colaboration }
68
+ end
69
+
70
+ it "should remote the elements that are not authorized" do
71
+ @songs.only_authorized_for(Beatle::JOHN, @options).should == [Song::A_DAY_IN_LIFE,
72
+ Song::YELLOW_SUBMARINE,
73
+ Song::TAXMAN]
74
+ @songs.only_authorized_for(Beatle::PAUL, @options).should == [Song::A_DAY_IN_LIFE,
75
+ Song::YELLOW_SUBMARINE]
76
+ @songs.only_authorized_for(Beatle::GEORGE, @options).should == [Song::TAXMAN]
77
+ @songs.only_authorized_for(Beatle::RINGO, @options).should be_empty
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -26,9 +26,8 @@ describe Walruz::Utils do
26
26
  describe "#all" do
27
27
 
28
28
  it "should return as policy keyword, the name of the original policies keywords concatenated with `_and_`" do
29
- Beatle::JOHN.can?(:sell, Song::ALL_YOU_NEED_IS_LOVE) do |policy_params|
30
- policy_params[:"author_policy_and_not(author_in_colaboration_policy)?"].should be_true
31
- end
29
+ policy_params = Beatle::JOHN.authorize(:sell, Song::ALL_YOU_NEED_IS_LOVE)
30
+ policy_params[:"author_policy_and_not(in_colaboration)?"].should be_true
32
31
  end
33
32
 
34
33
  end
@@ -36,9 +35,8 @@ describe Walruz::Utils do
36
35
  describe "#negate" do
37
36
 
38
37
  it "should return as policy keyword, the name of the original policy keyword with a `not()` around" do
39
- Beatle::JOHN.can?(:sell, Song::ALL_YOU_NEED_IS_LOVE) do |policy_params|
40
- policy_params[:"not(author_in_colaboration_policy)?"].should be_true
41
- end
38
+ policy_params = Beatle::JOHN.authorize(:sell, Song::ALL_YOU_NEED_IS_LOVE)
39
+ policy_params[:"not(in_colaboration)?"].should be_true
42
40
  end
43
41
 
44
42
  end
@@ -11,10 +11,24 @@ describe Walruz do
11
11
  it "should return all the policies created that have a label" do
12
12
  Walruz.policies.should_not be_nil
13
13
  Walruz.policies[:author_policy].should be_nil
14
- Walruz.policies[:author_in_colaboration_policy].should == AuthorInColaborationPolicy
14
+ Walruz.policies[:in_colaboration].should == AuthorInColaborationPolicy
15
15
  Walruz.policies[:colaborating_with_john_policy].should == ColaboratingWithJohnPolicy
16
16
  end
17
17
 
18
18
  end
19
+
20
+ describe "#fetch_policy" do
21
+
22
+ it "should grab the policy if this is registered" do
23
+ Walruz.fetch_policy(:in_colaboration).should == AuthorInColaborationPolicy
24
+ end
25
+
26
+ it "should raise an Walruz::ActionNotFound exception if the policy is not registered" do
27
+ lambda do
28
+ Walruz.fetch_policy(:author_in_colaboration_policy)
29
+ end.should raise_error(Walruz::ActionNotFound)
30
+ end
31
+
32
+ end
19
33
 
20
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: walruz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Gonzalez
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-20 00:00:00 -07:00
12
+ date: 2009-07-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,6 +29,7 @@ files:
29
29
  - VERSION.yml
30
30
  - lib/walruz.rb
31
31
  - lib/walruz/actor.rb
32
+ - lib/walruz/core_ext/array.rb
32
33
  - lib/walruz/policy.rb
33
34
  - lib/walruz/subject.rb
34
35
  - lib/walruz/utils.rb
@@ -36,11 +37,12 @@ files:
36
37
  - spec/spec.opts
37
38
  - spec/spec_helper.rb
38
39
  - spec/walruz/actor_spec.rb
40
+ - spec/walruz/core_ext/array_spec.rb
39
41
  - spec/walruz/policy_spec.rb
40
42
  - spec/walruz/subject_spec.rb
41
43
  - spec/walruz/utils_spec.rb
42
44
  - spec/walruz/walruz_spec.rb
43
- has_rdoc: true
45
+ has_rdoc: yard
44
46
  homepage: http://github.com/noomii/walruz
45
47
  licenses: []
46
48
 
@@ -72,6 +74,7 @@ test_files:
72
74
  - spec/scenario.rb
73
75
  - spec/spec_helper.rb
74
76
  - spec/walruz/actor_spec.rb
77
+ - spec/walruz/core_ext/array_spec.rb
75
78
  - spec/walruz/policy_spec.rb
76
79
  - spec/walruz/subject_spec.rb
77
80
  - spec/walruz/utils_spec.rb