rolify 3.4.0 → 3.4.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.
- data/.travis.yml +32 -16
- data/CHANGELOG.rdoc +6 -0
- data/Gemfile +4 -2
- data/README.md +1 -1
- data/Rakefile +6 -6
- data/gemfiles/Gemfile.rails-3.2 +14 -15
- data/gemfiles/Gemfile.rails-4.0 +21 -22
- data/gemfiles/Gemfile.rails-4.1 +37 -0
- data/lib/generators/active_record/rolify_generator.rb +2 -2
- data/lib/rolify.rb +6 -0
- data/lib/rolify/adapters/active_record/resource_adapter.rb +25 -4
- data/lib/rolify/adapters/base.rb +4 -0
- data/lib/rolify/adapters/mongoid/resource_adapter.rb +18 -1
- data/lib/rolify/configure.rb +6 -2
- data/lib/rolify/resource.rb +12 -9
- data/lib/rolify/role.rb +8 -2
- data/lib/rolify/version.rb +1 -1
- data/rolify.gemspec +15 -15
- data/spec/rolify/config_spec.rb +6 -7
- data/spec/rolify/resource_spec.rb +22 -6
- data/spec/rolify/shared_contexts.rb +1 -0
- data/spec/rolify/shared_examples/shared_examples_for_callbacks.rb +4 -4
- data/spec/rolify/shared_examples/shared_examples_for_dynamic.rb +27 -27
- data/spec/rolify/shared_examples/shared_examples_for_finders.rb +4 -0
- data/spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb +29 -29
- data/spec/rolify/shared_examples/shared_examples_for_has_any_role.rb +32 -32
- data/spec/rolify/shared_examples/shared_examples_for_has_role.rb +38 -38
- data/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb +44 -44
- data/spec/rolify/shared_examples/shared_examples_for_roles.rb +21 -15
- data/spec/spec_helper.rb +26 -3
- data/spec/support/adapters/active_record.rb +12 -4
- data/spec/support/adapters/mongoid.rb +8 -0
- data/spec/support/data.rb +4 -1
- data/spec/support/schema.rb +4 -0
- metadata +48 -33
- checksums.yaml +0 -7
@@ -5,18 +5,18 @@ shared_examples_for "#has_any_role?_examples" do |param_name, param_method|
|
|
5
5
|
subject.add_role "staff".send(param_method)
|
6
6
|
end
|
7
7
|
|
8
|
-
it { subject.has_any_role?("staff".send(param_method)).should
|
9
|
-
it { subject.has_any_role?("admin".send(param_method), "staff".send(param_method)).should
|
10
|
-
it { subject.has_any_role?("admin".send(param_method), "moderator".send(param_method)).should
|
11
|
-
it { subject.has_any_role?("dummy".send(param_method), "dumber".send(param_method)).should
|
12
|
-
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "admin".send(param_method), :resource => Group }).should
|
13
|
-
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => :any }, { :name => "admin".send(param_method), :resource => Group }).should
|
14
|
-
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "staff".send(param_method), :resource => Group.last }).should
|
15
|
-
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "admin".send(param_method), :resource => Forum.last }).should
|
16
|
-
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => Forum.last }).should
|
17
|
-
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => :any }).should
|
18
|
-
it { subject.has_any_role?({ :name => "dummy".send(param_method), :resource => Forum.first }, { :name => "dumber".send(param_method), :resource => :any }).should
|
19
|
-
it { subject.has_any_role?({ :name => "dummy".send(param_method), :resource => :any }, { :name => "dumber".send(param_method), :resource => :any }).should
|
8
|
+
it { subject.has_any_role?("staff".send(param_method)).should be_truthy }
|
9
|
+
it { subject.has_any_role?("admin".send(param_method), "staff".send(param_method)).should be_truthy }
|
10
|
+
it { subject.has_any_role?("admin".send(param_method), "moderator".send(param_method)).should be_truthy }
|
11
|
+
it { subject.has_any_role?("dummy".send(param_method), "dumber".send(param_method)).should be_falsey }
|
12
|
+
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "admin".send(param_method), :resource => Group }).should be_truthy }
|
13
|
+
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => :any }, { :name => "admin".send(param_method), :resource => Group }).should be_truthy }
|
14
|
+
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "staff".send(param_method), :resource => Group.last }).should be_truthy }
|
15
|
+
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "admin".send(param_method), :resource => Forum.last }).should be_truthy }
|
16
|
+
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => Forum.last }).should be_truthy }
|
17
|
+
it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => :any }).should be_truthy }
|
18
|
+
it { subject.has_any_role?({ :name => "dummy".send(param_method), :resource => Forum.first }, { :name => "dumber".send(param_method), :resource => :any }).should be_falsey }
|
19
|
+
it { subject.has_any_role?({ :name => "dummy".send(param_method), :resource => :any }, { :name => "dumber".send(param_method), :resource => :any }).should be_falsey }
|
20
20
|
end
|
21
21
|
|
22
22
|
context "with a class scoped role", :scope => :class do
|
@@ -25,18 +25,18 @@ shared_examples_for "#has_any_role?_examples" do |param_name, param_method|
|
|
25
25
|
subject.add_role "superhero".send(param_method)
|
26
26
|
end
|
27
27
|
|
28
|
-
it { subject.has_any_role?({ :name => "player".send(param_method), :resource => Forum }).should
|
29
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => Forum }).should
|
30
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => :any }).should
|
31
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => :any }).should
|
32
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => :any }, { :name => "player".send(param_method), :resource => :any }).should
|
33
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => Forum }).should
|
34
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => :any }).should
|
35
|
-
it { subject.has_any_role?({ :name => "dummy".send(param_method), :resource => Forum }, { :name => "dumber".send(param_method), :resource => Group }).should
|
36
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "manager".send(param_method), :resource => Forum.last }).should
|
37
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Group }, { :name => "moderator".send(param_method), :resource => Forum.first }).should
|
38
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "moderator".send(param_method), :resource => Forum }).should
|
39
|
-
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum.last }, { :name => "warrior".send(param_method), :resource => Forum.last }).should
|
28
|
+
it { subject.has_any_role?({ :name => "player".send(param_method), :resource => Forum }).should be_truthy }
|
29
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => Forum }).should be_truthy }
|
30
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => :any }).should be_truthy }
|
31
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => :any }).should be_truthy }
|
32
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => :any }, { :name => "player".send(param_method), :resource => :any }).should be_truthy }
|
33
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => Forum }).should be_truthy }
|
34
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => :any }).should be_truthy }
|
35
|
+
it { subject.has_any_role?({ :name => "dummy".send(param_method), :resource => Forum }, { :name => "dumber".send(param_method), :resource => Group }).should be_falsey }
|
36
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "manager".send(param_method), :resource => Forum.last }).should be_truthy }
|
37
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Group }, { :name => "moderator".send(param_method), :resource => Forum.first }).should be_falsey }
|
38
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "moderator".send(param_method), :resource => Forum }).should be_truthy }
|
39
|
+
it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum.last }, { :name => "warrior".send(param_method), :resource => Forum.last }).should be_truthy }
|
40
40
|
end
|
41
41
|
|
42
42
|
context "with a instance scoped role", :scope => :instance do
|
@@ -46,14 +46,14 @@ shared_examples_for "#has_any_role?_examples" do |param_name, param_method|
|
|
46
46
|
subject.add_role "warrior"
|
47
47
|
end
|
48
48
|
|
49
|
-
it { subject.has_any_role?({ :name => "visitor", :resource => Forum.last }).should
|
50
|
-
it { subject.has_any_role?({ :name => "moderator", :resource => Forum.first }, { :name => "visitor", :resource => Forum.last }).should
|
51
|
-
it { subject.has_any_role?({ :name => "moderator", :resource => :any }, { :name => "visitor", :resource => Forum.last }).should
|
52
|
-
it { subject.has_any_role?({ :name => "moderator", :resource => :any }, { :name => "visitor", :resource => :any}).should
|
53
|
-
it { subject.has_any_role?({ :name => "moderator", :resource => Forum }, { :name => "visitor", :resource => :any }).should
|
54
|
-
it { subject.has_any_role?({ :name => "moderator", :resource => Forum.first }, { :name => "moderator", :resource => Forum.last }).should
|
55
|
-
it { subject.has_any_role?({ :name => "moderator", :resource => Forum.first }, { :name => "dummy", :resource => Forum.last }).should
|
56
|
-
it { subject.has_any_role?({ :name => "dummy", :resource => Forum.first }, { :name => "dumber", :resource => Forum.last }).should
|
49
|
+
it { subject.has_any_role?({ :name => "visitor", :resource => Forum.last }).should be_truthy }
|
50
|
+
it { subject.has_any_role?({ :name => "moderator", :resource => Forum.first }, { :name => "visitor", :resource => Forum.last }).should be_truthy }
|
51
|
+
it { subject.has_any_role?({ :name => "moderator", :resource => :any }, { :name => "visitor", :resource => Forum.last }).should be_truthy }
|
52
|
+
it { subject.has_any_role?({ :name => "moderator", :resource => :any }, { :name => "visitor", :resource => :any}).should be_truthy }
|
53
|
+
it { subject.has_any_role?({ :name => "moderator", :resource => Forum }, { :name => "visitor", :resource => :any }).should be_truthy }
|
54
|
+
it { subject.has_any_role?({ :name => "moderator", :resource => Forum.first }, { :name => "moderator", :resource => Forum.last }).should be_truthy }
|
55
|
+
it { subject.has_any_role?({ :name => "moderator", :resource => Forum.first }, { :name => "dummy", :resource => Forum.last }).should be_truthy }
|
56
|
+
it { subject.has_any_role?({ :name => "dummy", :resource => Forum.first }, { :name => "dumber", :resource => Forum.last }).should be_falsey }
|
57
57
|
it { subject.has_any_role?("warrior", { :name => "moderator", :resource => Forum.first }, { :name => "leader", :resource => Group }).should be(true) }
|
58
58
|
it { subject.has_any_role?("warrior", { :name => "moderator", :resource => :any }, { :name => "leader", :resource => Forum }).should be(true) }
|
59
59
|
it { subject.has_any_role?("warrior", { :name => "moderator", :resource => Forum.first }, { :name => "leader", :resource => :any }).should be(true) }
|
@@ -1,133 +1,133 @@
|
|
1
1
|
shared_examples_for "#has_role?_examples" do |param_name, param_method|
|
2
2
|
context "using #{param_name} as parameter" do
|
3
3
|
context "with a global role", :scope => :global do
|
4
|
-
it { subject.has_role?("admin".send(param_method)).should
|
4
|
+
it { subject.has_role?("admin".send(param_method)).should be_truthy }
|
5
5
|
|
6
6
|
context "on resource request" do
|
7
|
-
it { subject.has_role?("admin".send(param_method), Forum.first).should
|
8
|
-
it { subject.has_role?("admin".send(param_method), Forum).should
|
9
|
-
it { subject.has_role?("admin".send(param_method), :any).should
|
7
|
+
it { subject.has_role?("admin".send(param_method), Forum.first).should be_truthy }
|
8
|
+
it { subject.has_role?("admin".send(param_method), Forum).should be_truthy }
|
9
|
+
it { subject.has_role?("admin".send(param_method), :any).should be_truthy }
|
10
10
|
end
|
11
11
|
|
12
12
|
context "with another global role" do
|
13
13
|
before(:all) { role_class.create(:name => "global") }
|
14
14
|
|
15
|
-
it { subject.has_role?("global".send(param_method)).should
|
16
|
-
it { subject.has_role?("global".send(param_method), :any).should
|
15
|
+
it { subject.has_role?("global".send(param_method)).should be_falsey }
|
16
|
+
it { subject.has_role?("global".send(param_method), :any).should be_falsey }
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should not get an instance scoped role" do
|
20
|
-
subject.has_role?("moderator".send(param_method), Group.first).should
|
20
|
+
subject.has_role?("moderator".send(param_method), Group.first).should be_falsey
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should not get a class scoped role" do
|
24
|
-
subject.has_role?("manager".send(param_method), Forum).should
|
24
|
+
subject.has_role?("manager".send(param_method), Forum).should be_falsey
|
25
25
|
end
|
26
26
|
|
27
27
|
context "using inexisting role" do
|
28
|
-
it { subject.has_role?("dummy".send(param_method)).should
|
29
|
-
it { subject.has_role?("dumber".send(param_method), Forum.first).should
|
28
|
+
it { subject.has_role?("dummy".send(param_method)).should be_falsey }
|
29
|
+
it { subject.has_role?("dumber".send(param_method), Forum.first).should be_falsey }
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context "with a class scoped role", :scope => :class do
|
34
34
|
context "on class scoped role request" do
|
35
|
-
it { subject.has_role?("manager".send(param_method), Forum).should
|
36
|
-
it { subject.has_role?("manager".send(param_method), Forum.first).should
|
37
|
-
it { subject.has_role?("manager".send(param_method), :any).should
|
35
|
+
it { subject.has_role?("manager".send(param_method), Forum).should be_truthy }
|
36
|
+
it { subject.has_role?("manager".send(param_method), Forum.first).should be_truthy }
|
37
|
+
it { subject.has_role?("manager".send(param_method), :any).should be_truthy }
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should not get a scoped role when asking for a global" do
|
41
|
-
subject.has_role?("manager".send(param_method)).should
|
41
|
+
subject.has_role?("manager".send(param_method)).should be_falsey
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should not get a global role" do
|
45
45
|
role_class.create(:name => "admin")
|
46
|
-
subject.has_role?("admin".send(param_method)).should
|
46
|
+
subject.has_role?("admin".send(param_method)).should be_falsey
|
47
47
|
end
|
48
48
|
|
49
49
|
context "with another class scoped role" do
|
50
50
|
context "on the same resource but with a different name" do
|
51
51
|
before(:all) { role_class.create(:name => "member", :resource_type => "Forum") }
|
52
52
|
|
53
|
-
it { subject.has_role?("member".send(param_method), Forum).should
|
54
|
-
it { subject.has_role?("member".send(param_method), :any).should
|
53
|
+
it { subject.has_role?("member".send(param_method), Forum).should be_falsey }
|
54
|
+
it { subject.has_role?("member".send(param_method), :any).should be_falsey }
|
55
55
|
end
|
56
56
|
|
57
57
|
context "on another resource with the same name" do
|
58
58
|
before(:all) { role_class.create(:name => "manager", :resource_type => "Group") }
|
59
59
|
|
60
|
-
it { subject.has_role?("manager".send(param_method), Group).should
|
61
|
-
it { subject.has_role?("manager".send(param_method), :any).should
|
60
|
+
it { subject.has_role?("manager".send(param_method), Group).should be_falsey }
|
61
|
+
it { subject.has_role?("manager".send(param_method), :any).should be_truthy }
|
62
62
|
end
|
63
63
|
|
64
64
|
context "on another resource with another name" do
|
65
65
|
before(:all) { role_class.create(:name => "defenders", :resource_type => "Group") }
|
66
66
|
|
67
|
-
it { subject.has_role?("defenders".send(param_method), Group).should
|
68
|
-
it { subject.has_role?("defenders".send(param_method), :any).should
|
67
|
+
it { subject.has_role?("defenders".send(param_method), Group).should be_falsey }
|
68
|
+
it { subject.has_role?("defenders".send(param_method), :any).should be_falsey }
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
context "using inexisting role" do
|
73
|
-
it { subject.has_role?("dummy".send(param_method), Forum).should
|
74
|
-
it { subject.has_role?("dumber".send(param_method)).should
|
73
|
+
it { subject.has_role?("dummy".send(param_method), Forum).should be_falsey }
|
74
|
+
it { subject.has_role?("dumber".send(param_method)).should be_falsey }
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
context "with a instance scoped role", :scope => :instance do
|
79
79
|
context "on instance scoped role request" do
|
80
|
-
it { subject.has_role?("moderator".send(param_method), Forum.first).should
|
81
|
-
it { subject.has_role?("moderator".send(param_method), :any).should
|
80
|
+
it { subject.has_role?("moderator".send(param_method), Forum.first).should be_truthy }
|
81
|
+
it { subject.has_role?("moderator".send(param_method), :any).should be_truthy }
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should not get an instance scoped role when asking for a global" do
|
85
|
-
subject.has_role?("moderator".send(param_method)).should
|
85
|
+
subject.has_role?("moderator".send(param_method)).should be_falsey
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should not get an instance scoped role when asking for a class scoped" do
|
89
|
-
subject.has_role?("moderator".send(param_method), Forum).should
|
89
|
+
subject.has_role?("moderator".send(param_method), Forum).should be_falsey
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should not get a global role" do
|
93
93
|
role_class.create(:name => "admin")
|
94
|
-
subject.has_role?("admin".send(param_method)).should
|
94
|
+
subject.has_role?("admin".send(param_method)).should be_falsey
|
95
95
|
end
|
96
96
|
|
97
97
|
context "with another instance scoped role" do
|
98
98
|
context "on the same resource but with a different role name" do
|
99
99
|
before(:all) { role_class.create(:name => "member", :resource => Forum.first) }
|
100
100
|
|
101
|
-
it { subject.has_role?("member".send(param_method), Forum.first).should
|
102
|
-
it { subject.has_role?("member".send(param_method), :any).should
|
101
|
+
it { subject.has_role?("member".send(param_method), Forum.first).should be_falsey }
|
102
|
+
it { subject.has_role?("member".send(param_method), :any).should be_falsey }
|
103
103
|
end
|
104
104
|
|
105
105
|
context "on another resource of the same type but with the same role name" do
|
106
106
|
before(:all) { role_class.create(:name => "moderator", :resource => Forum.last) }
|
107
107
|
|
108
|
-
it { subject.has_role?("moderator".send(param_method), Forum.last).should
|
109
|
-
it { subject.has_role?("moderator".send(param_method), :any).should
|
108
|
+
it { subject.has_role?("moderator".send(param_method), Forum.last).should be_falsey }
|
109
|
+
it { subject.has_role?("moderator".send(param_method), :any).should be_truthy }
|
110
110
|
end
|
111
111
|
|
112
112
|
context "on another resource of different type but with the same role name" do
|
113
113
|
before(:all) { role_class.create(:name => "moderator", :resource => Group.last) }
|
114
114
|
|
115
|
-
it { subject.has_role?("moderator".send(param_method), Group.last).should
|
116
|
-
it { subject.has_role?("moderator".send(param_method), :any).should
|
115
|
+
it { subject.has_role?("moderator".send(param_method), Group.last).should be_falsey }
|
116
|
+
it { subject.has_role?("moderator".send(param_method), :any).should be_truthy }
|
117
117
|
end
|
118
118
|
|
119
119
|
context "on another resource of the same type and with another role name" do
|
120
120
|
before(:all) { role_class.create(:name => "member", :resource => Forum.last) }
|
121
121
|
|
122
|
-
it { subject.has_role?("member".send(param_method), Forum.last).should
|
123
|
-
it { subject.has_role?("member".send(param_method), :any).should
|
122
|
+
it { subject.has_role?("member".send(param_method), Forum.last).should be_falsey }
|
123
|
+
it { subject.has_role?("member".send(param_method), :any).should be_falsey }
|
124
124
|
end
|
125
125
|
|
126
126
|
context "on another resource of different type and with another role name" do
|
127
127
|
before(:all) { role_class.create(:name => "member", :resource => Group.first) }
|
128
128
|
|
129
|
-
it { subject.has_role?("member".send(param_method), Group.first).should
|
130
|
-
it { subject.has_role?("member".send(param_method), :any).should
|
129
|
+
it { subject.has_role?("member".send(param_method), Group.first).should be_falsey }
|
130
|
+
it { subject.has_role?("member".send(param_method), :any).should be_falsey }
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -7,38 +7,38 @@ shared_examples_for "#only_has_role?_examples" do |param_name, param_method|
|
|
7
7
|
user
|
8
8
|
end
|
9
9
|
|
10
|
-
it { subject.only_has_role?("global_role".send(param_method)).should
|
10
|
+
it { subject.only_has_role?("global_role".send(param_method)).should be_truthy }
|
11
11
|
|
12
12
|
context "on resource request" do
|
13
|
-
it { subject.only_has_role?("global_role".send(param_method), Forum.first).should
|
14
|
-
it { subject.only_has_role?("global_role".send(param_method), Forum).should
|
15
|
-
it { subject.only_has_role?("global_role".send(param_method), :any).should
|
13
|
+
it { subject.only_has_role?("global_role".send(param_method), Forum.first).should be_truthy }
|
14
|
+
it { subject.only_has_role?("global_role".send(param_method), Forum).should be_truthy }
|
15
|
+
it { subject.only_has_role?("global_role".send(param_method), :any).should be_truthy }
|
16
16
|
end
|
17
17
|
|
18
18
|
context "with another global role" do
|
19
19
|
before(:all) { role_class.create(:name => "another_global_role") }
|
20
20
|
|
21
|
-
it { subject.only_has_role?("another_global_role".send(param_method)).should
|
22
|
-
it { subject.only_has_role?("another_global_role".send(param_method), :any).should
|
21
|
+
it { subject.only_has_role?("another_global_role".send(param_method)).should be_falsey }
|
22
|
+
it { subject.only_has_role?("another_global_role".send(param_method), :any).should be_falsey }
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should not get an instance scoped role" do
|
26
|
-
subject.only_has_role?("moderator".send(param_method), Group.first).should
|
26
|
+
subject.only_has_role?("moderator".send(param_method), Group.first).should be_falsey
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should not get a class scoped role" do
|
30
|
-
subject.only_has_role?("manager".send(param_method), Forum).should
|
30
|
+
subject.only_has_role?("manager".send(param_method), Forum).should be_falsey
|
31
31
|
end
|
32
32
|
|
33
33
|
context "using inexisting role" do
|
34
|
-
it { subject.only_has_role?("dummy".send(param_method)).should
|
35
|
-
it { subject.only_has_role?("dumber".send(param_method), Forum.first).should
|
34
|
+
it { subject.only_has_role?("dummy".send(param_method)).should be_falsey }
|
35
|
+
it { subject.only_has_role?("dumber".send(param_method), Forum.first).should be_falsey }
|
36
36
|
end
|
37
37
|
|
38
38
|
context "with multiple roles" do
|
39
39
|
before { subject.add_role "multiple_global_roles".send(param_method) }
|
40
40
|
|
41
|
-
it { subject.only_has_role?("global_role".send(param_method)).should
|
41
|
+
it { subject.only_has_role?("global_role".send(param_method)).should be_falsey }
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -50,54 +50,54 @@ shared_examples_for "#only_has_role?_examples" do |param_name, param_method|
|
|
50
50
|
end
|
51
51
|
|
52
52
|
context "on class scoped role request" do
|
53
|
-
it { subject.only_has_role?("class_role".send(param_method), Forum).should
|
54
|
-
it { subject.only_has_role?("class_role".send(param_method), Forum.first).should
|
55
|
-
it { subject.only_has_role?("class_role".send(param_method), :any).should
|
53
|
+
it { subject.only_has_role?("class_role".send(param_method), Forum).should be_truthy }
|
54
|
+
it { subject.only_has_role?("class_role".send(param_method), Forum.first).should be_truthy }
|
55
|
+
it { subject.only_has_role?("class_role".send(param_method), :any).should be_truthy }
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should not get a scoped role when asking for a global" do
|
59
|
-
subject.only_has_role?("class_role".send(param_method)).should
|
59
|
+
subject.only_has_role?("class_role".send(param_method)).should be_falsey
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should not get a global role" do
|
63
63
|
role_class.create(:name => "global_role")
|
64
|
-
subject.only_has_role?("global_role".send(param_method)).should
|
64
|
+
subject.only_has_role?("global_role".send(param_method)).should be_falsey
|
65
65
|
end
|
66
66
|
|
67
67
|
context "with another class scoped role" do
|
68
68
|
context "on the same resource but with a different name" do
|
69
69
|
before(:all) { role_class.create(:name => "another_class_role", :resource_type => "Forum") }
|
70
70
|
|
71
|
-
it { subject.only_has_role?("another_class_role".send(param_method), Forum).should
|
72
|
-
it { subject.only_has_role?("another_class_role".send(param_method), :any).should
|
71
|
+
it { subject.only_has_role?("another_class_role".send(param_method), Forum).should be_falsey }
|
72
|
+
it { subject.only_has_role?("another_class_role".send(param_method), :any).should be_falsey }
|
73
73
|
end
|
74
74
|
|
75
75
|
context "on another resource with the same name" do
|
76
76
|
before(:all) { role_class.create(:name => "class_role", :resource_type => "Group") }
|
77
77
|
|
78
|
-
it { subject.only_has_role?("class_role".send(param_method), Group).should
|
79
|
-
it { subject.only_has_role?("class_role".send(param_method), :any).should
|
78
|
+
it { subject.only_has_role?("class_role".send(param_method), Group).should be_falsey }
|
79
|
+
it { subject.only_has_role?("class_role".send(param_method), :any).should be_truthy }
|
80
80
|
end
|
81
81
|
|
82
82
|
context "on another resource with another name" do
|
83
83
|
before(:all) { role_class.create(:name => "another_class_role", :resource_type => "Group") }
|
84
84
|
|
85
|
-
it { subject.only_has_role?("another_class_role".send(param_method), Group).should
|
86
|
-
it { subject.only_has_role?("another_class_role".send(param_method), :any).should
|
85
|
+
it { subject.only_has_role?("another_class_role".send(param_method), Group).should be_falsey }
|
86
|
+
it { subject.only_has_role?("another_class_role".send(param_method), :any).should be_falsey }
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
context "using inexisting role" do
|
91
|
-
it { subject.only_has_role?("dummy".send(param_method), Forum).should
|
92
|
-
it { subject.only_has_role?("dumber".send(param_method)).should
|
91
|
+
it { subject.only_has_role?("dummy".send(param_method), Forum).should be_falsey }
|
92
|
+
it { subject.only_has_role?("dumber".send(param_method)).should be_falsey }
|
93
93
|
end
|
94
94
|
|
95
95
|
context "with multiple roles" do
|
96
96
|
before { subject.add_role "multiple_class_roles".send(param_method) }
|
97
97
|
|
98
|
-
it { subject.only_has_role?("class_role".send(param_method), Forum).should
|
99
|
-
it { subject.only_has_role?("class_role".send(param_method), Forum.first).should
|
100
|
-
it { subject.only_has_role?("class_role".send(param_method), :any).should
|
98
|
+
it { subject.only_has_role?("class_role".send(param_method), Forum).should be_falsey }
|
99
|
+
it { subject.only_has_role?("class_role".send(param_method), Forum.first).should be_falsey }
|
100
|
+
it { subject.only_has_role?("class_role".send(param_method), :any).should be_falsey }
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -109,65 +109,65 @@ shared_examples_for "#only_has_role?_examples" do |param_name, param_method|
|
|
109
109
|
end
|
110
110
|
|
111
111
|
context "on instance scoped role request" do
|
112
|
-
it { subject.only_has_role?("instance_role".send(param_method), Forum.first).should
|
113
|
-
it { subject.only_has_role?("instance_role".send(param_method), :any).should
|
112
|
+
it { subject.only_has_role?("instance_role".send(param_method), Forum.first).should be_truthy }
|
113
|
+
it { subject.only_has_role?("instance_role".send(param_method), :any).should be_truthy }
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should not get an instance scoped role when asking for a global" do
|
117
|
-
subject.only_has_role?("instance_role".send(param_method)).should
|
117
|
+
subject.only_has_role?("instance_role".send(param_method)).should be_falsey
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should not get an instance scoped role when asking for a class scoped" do
|
121
|
-
subject.only_has_role?("instance_role".send(param_method), Forum).should
|
121
|
+
subject.only_has_role?("instance_role".send(param_method), Forum).should be_falsey
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should not get a global role" do
|
125
125
|
role_class.create(:name => "global_role")
|
126
|
-
subject.only_has_role?("global_role".send(param_method)).should
|
126
|
+
subject.only_has_role?("global_role".send(param_method)).should be_falsey
|
127
127
|
end
|
128
128
|
|
129
129
|
context "with another instance scoped role" do
|
130
130
|
context "on the same resource but with a different role name" do
|
131
131
|
before(:all) { role_class.create(:name => "another_instance_role", :resource => Forum.first) }
|
132
132
|
|
133
|
-
it { subject.only_has_role?("another_instance_role".send(param_method), Forum.first).should
|
134
|
-
it { subject.only_has_role?("another_instance_role".send(param_method), :any).should
|
133
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), Forum.first).should be_falsey }
|
134
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), :any).should be_falsey }
|
135
135
|
end
|
136
136
|
|
137
137
|
context "on another resource of the same type but with the same role name" do
|
138
138
|
before(:all) { role_class.create(:name => "moderator", :resource => Forum.last) }
|
139
139
|
|
140
|
-
it { subject.only_has_role?("instance_role".send(param_method), Forum.last).should
|
141
|
-
it { subject.only_has_role?("instance_role".send(param_method), :any).should
|
140
|
+
it { subject.only_has_role?("instance_role".send(param_method), Forum.last).should be_falsey }
|
141
|
+
it { subject.only_has_role?("instance_role".send(param_method), :any).should be_truthy }
|
142
142
|
end
|
143
143
|
|
144
144
|
context "on another resource of different type but with the same role name" do
|
145
145
|
before(:all) { role_class.create(:name => "moderator", :resource => Group.last) }
|
146
146
|
|
147
|
-
it { subject.only_has_role?("instance_role".send(param_method), Group.last).should
|
148
|
-
it { subject.only_has_role?("instance_role".send(param_method), :any).should
|
147
|
+
it { subject.only_has_role?("instance_role".send(param_method), Group.last).should be_falsey }
|
148
|
+
it { subject.only_has_role?("instance_role".send(param_method), :any).should be_truthy }
|
149
149
|
end
|
150
150
|
|
151
151
|
context "on another resource of the same type and with another role name" do
|
152
152
|
before(:all) { role_class.create(:name => "another_instance_role", :resource => Forum.last) }
|
153
153
|
|
154
|
-
it { subject.only_has_role?("another_instance_role".send(param_method), Forum.last).should
|
155
|
-
it { subject.only_has_role?("another_instance_role".send(param_method), :any).should
|
154
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), Forum.last).should be_falsey }
|
155
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), :any).should be_falsey }
|
156
156
|
end
|
157
157
|
|
158
158
|
context "on another resource of different type and with another role name" do
|
159
159
|
before(:all) { role_class.create(:name => "another_instance_role", :resource => Group.first) }
|
160
160
|
|
161
|
-
it { subject.only_has_role?("another_instance_role".send(param_method), Group.first).should
|
162
|
-
it { subject.only_has_role?("another_instance_role".send(param_method), :any).should
|
161
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), Group.first).should be_falsey }
|
162
|
+
it { subject.only_has_role?("another_instance_role".send(param_method), :any).should be_falsey }
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
166
|
context "with multiple roles" do
|
167
167
|
before { subject.add_role "multiple_instance_roles".send(param_method), Forum.first }
|
168
168
|
|
169
|
-
it { subject.only_has_role?("instance_role".send(param_method), Forum.first).should
|
170
|
-
it { subject.only_has_role?("instance_role".send(param_method), :any).should
|
169
|
+
it { subject.only_has_role?("instance_role".send(param_method), Forum.first).should be_falsey }
|
170
|
+
it { subject.only_has_role?("instance_role".send(param_method), :any).should be_falsey }
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|