rolify 3.1.0 → 4.0.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.
- checksums.yaml +7 -0
- data/.gitignore +4 -1
- data/.travis.yml +44 -11
- data/CHANGELOG.rdoc +70 -0
- data/CONTRIBUTORS +6 -0
- data/Gemfile +21 -2
- data/README.md +130 -68
- data/Rakefile +29 -4
- data/UPGRADE.rdoc +22 -0
- data/circle.yml +13 -0
- data/gemfiles/Gemfile.rails-3.2 +27 -0
- data/gemfiles/Gemfile.rails-4.0 +33 -0
- data/gemfiles/Gemfile.rails-4.1 +37 -0
- data/lib/generators/active_record/rolify_generator.rb +54 -0
- data/lib/generators/active_record/templates/README +8 -0
- data/lib/generators/active_record/templates/migration.rb +19 -0
- data/lib/generators/mongoid/rolify_generator.rb +55 -0
- data/lib/generators/mongoid/templates/README-mongoid +4 -0
- data/lib/generators/rolify/rolify_generator.rb +35 -0
- data/lib/generators/rolify/{role/templates/README-mongoid → templates/README} +1 -5
- data/lib/generators/rolify/templates/initializer.rb +7 -0
- data/lib/generators/rolify/templates/role-active_record.rb +11 -0
- data/lib/generators/rolify/{role/templates → templates}/role-mongoid.rb +9 -9
- data/lib/generators/rolify/user_generator.rb +39 -0
- data/lib/rolify/adapters/active_record/resource_adapter.rb +36 -6
- data/lib/rolify/adapters/active_record/role_adapter.rb +25 -13
- data/lib/rolify/adapters/active_record/scopes.rb +27 -0
- data/lib/rolify/adapters/base.rb +9 -0
- data/lib/rolify/adapters/mongoid/resource_adapter.rb +27 -6
- data/lib/rolify/adapters/mongoid/role_adapter.rb +35 -11
- data/lib/rolify/adapters/mongoid/scopes.rb +27 -0
- data/lib/rolify/configure.rb +36 -5
- data/lib/rolify/finders.rb +40 -0
- data/lib/rolify/matchers.rb +31 -0
- data/lib/rolify/railtie.rb +1 -1
- data/lib/rolify/resource.rb +19 -10
- data/lib/rolify/role.rb +33 -13
- data/lib/rolify/version.rb +1 -1
- data/lib/rolify.rb +46 -20
- data/rolify.gemspec +18 -24
- data/spec/README.rdoc +24 -0
- data/spec/generators/rolify/rolify_activerecord_generator_spec.rb +165 -0
- data/spec/generators/rolify/rolify_mongoid_generator_spec.rb +113 -0
- data/spec/generators_helper.rb +27 -0
- data/spec/rolify/config_spec.rb +20 -21
- data/spec/rolify/custom_spec.rb +11 -6
- data/spec/rolify/matchers_spec.rb +24 -0
- data/spec/rolify/namespace_spec.rb +24 -0
- data/spec/rolify/resource_spec.rb +135 -37
- data/spec/rolify/resourcifed_and_rolifed_spec.rb +24 -0
- data/spec/rolify/role_spec.rb +8 -9
- data/spec/rolify/shared_contexts.rb +22 -3
- data/spec/rolify/shared_examples/shared_examples_for_add_role.rb +10 -17
- data/spec/rolify/shared_examples/shared_examples_for_callbacks.rb +65 -0
- data/spec/rolify/shared_examples/shared_examples_for_dynamic.rb +64 -27
- data/spec/rolify/shared_examples/shared_examples_for_finders.rb +81 -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 +35 -35
- 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 +174 -0
- data/spec/rolify/shared_examples/shared_examples_for_remove_role.rb +28 -59
- data/spec/rolify/shared_examples/shared_examples_for_roles.rb +58 -32
- data/spec/rolify/shared_examples/shared_examples_for_scopes.rb +38 -0
- data/spec/spec_helper.rb +39 -3
- data/spec/support/adapters/active_record.rb +58 -7
- data/spec/support/adapters/mongoid.rb +110 -17
- data/spec/support/adapters/mongoid.yml +6 -0
- data/spec/support/data.rb +18 -15
- data/spec/support/schema.rb +31 -16
- data/spec/support/stream_helpers.rb +18 -0
- metadata +88 -84
- data/lib/generators/rolify/role/role_generator.rb +0 -41
- data/lib/generators/rolify/role/templates/README +0 -11
- data/lib/generators/rolify/role/templates/README-active_record +0 -21
- data/lib/generators/rolify/role/templates/initializer.rb +0 -7
- data/lib/generators/rolify/role/templates/migration.rb +0 -19
- data/lib/generators/rolify/role/templates/role-active_record.rb +0 -4
- data/spec/generators/rolify/role/role_generator_spec.rb +0 -197
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
shared_examples_for "#has_any_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
|
-
before
|
|
4
|
+
before do
|
|
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
|
|
23
|
-
before
|
|
23
|
+
before do
|
|
24
24
|
subject.add_role "player".send(param_method), Forum
|
|
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
|
|
43
|
-
before
|
|
43
|
+
before do
|
|
44
44
|
subject.add_role "visitor".send(param_method), Forum.last
|
|
45
45
|
subject.add_role "leader", Group
|
|
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
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
shared_examples_for "#only_has_role?_examples" do |param_name, param_method|
|
|
2
|
+
context "using #{param_name} as parameter" do
|
|
3
|
+
context "with a global role", :scope => :global do
|
|
4
|
+
subject do
|
|
5
|
+
user = User.create(:login => "global_user")
|
|
6
|
+
user.add_role "global_role".send(param_method)
|
|
7
|
+
user
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it { subject.only_has_role?("global_role".send(param_method)).should be_truthy }
|
|
11
|
+
|
|
12
|
+
context "on resource request" do
|
|
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
|
+
end
|
|
17
|
+
|
|
18
|
+
context "with another global role" do
|
|
19
|
+
before(:all) { role_class.create(:name => "another_global_role") }
|
|
20
|
+
|
|
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
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should not get an instance scoped role" do
|
|
26
|
+
subject.only_has_role?("moderator".send(param_method), Group.first).should be_falsey
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should not get a class scoped role" do
|
|
30
|
+
subject.only_has_role?("manager".send(param_method), Forum).should be_falsey
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "using inexisting role" do
|
|
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
|
+
end
|
|
37
|
+
|
|
38
|
+
context "with multiple roles" do
|
|
39
|
+
before { subject.add_role "multiple_global_roles".send(param_method) }
|
|
40
|
+
|
|
41
|
+
it { subject.only_has_role?("global_role".send(param_method)).should be_falsey }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "with a class scoped role", :scope => :class do
|
|
46
|
+
subject do
|
|
47
|
+
user = User.create(:login => "class_user")
|
|
48
|
+
user.add_role "class_role".send(param_method), Forum
|
|
49
|
+
user
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "on class scoped role request" do
|
|
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
|
+
end
|
|
57
|
+
|
|
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 be_falsey
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "should not get a global role" do
|
|
63
|
+
role_class.create(:name => "global_role")
|
|
64
|
+
subject.only_has_role?("global_role".send(param_method)).should be_falsey
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context "with another class scoped role" do
|
|
68
|
+
context "on the same resource but with a different name" do
|
|
69
|
+
before(:all) { role_class.create(:name => "another_class_role", :resource_type => "Forum") }
|
|
70
|
+
|
|
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
|
+
end
|
|
74
|
+
|
|
75
|
+
context "on another resource with the same name" do
|
|
76
|
+
before(:all) { role_class.create(:name => "class_role", :resource_type => "Group") }
|
|
77
|
+
|
|
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
|
+
end
|
|
81
|
+
|
|
82
|
+
context "on another resource with another name" do
|
|
83
|
+
before(:all) { role_class.create(:name => "another_class_role", :resource_type => "Group") }
|
|
84
|
+
|
|
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
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context "using inexisting role" do
|
|
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
|
+
end
|
|
94
|
+
|
|
95
|
+
context "with multiple roles" do
|
|
96
|
+
before { subject.add_role "multiple_class_roles".send(param_method) }
|
|
97
|
+
|
|
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
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context "with a instance scoped role", :scope => :instance do
|
|
105
|
+
subject do
|
|
106
|
+
user = User.create(:login => "instance_user")
|
|
107
|
+
user.add_role "instance_role".send(param_method), Forum.first
|
|
108
|
+
user
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
context "on instance scoped role request" do
|
|
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
|
+
end
|
|
115
|
+
|
|
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 be_falsey
|
|
118
|
+
end
|
|
119
|
+
|
|
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 be_falsey
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "should not get a global role" do
|
|
125
|
+
role_class.create(:name => "global_role")
|
|
126
|
+
subject.only_has_role?("global_role".send(param_method)).should be_falsey
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context "with another instance scoped role" do
|
|
130
|
+
context "on the same resource but with a different role name" do
|
|
131
|
+
before(:all) { role_class.create(:name => "another_instance_role", :resource => Forum.first) }
|
|
132
|
+
|
|
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
|
+
end
|
|
136
|
+
|
|
137
|
+
context "on another resource of the same type but with the same role name" do
|
|
138
|
+
before(:all) { role_class.create(:name => "moderator", :resource => Forum.last) }
|
|
139
|
+
|
|
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
|
+
end
|
|
143
|
+
|
|
144
|
+
context "on another resource of different type but with the same role name" do
|
|
145
|
+
before(:all) { role_class.create(:name => "moderator", :resource => Group.last) }
|
|
146
|
+
|
|
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
|
+
end
|
|
150
|
+
|
|
151
|
+
context "on another resource of the same type and with another role name" do
|
|
152
|
+
before(:all) { role_class.create(:name => "another_instance_role", :resource => Forum.last) }
|
|
153
|
+
|
|
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
|
+
end
|
|
157
|
+
|
|
158
|
+
context "on another resource of different type and with another role name" do
|
|
159
|
+
before(:all) { role_class.create(:name => "another_instance_role", :resource => Group.first) }
|
|
160
|
+
|
|
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
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context "with multiple roles" do
|
|
167
|
+
before { subject.add_role "multiple_instance_roles".send(param_method), Forum.first }
|
|
168
|
+
|
|
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
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
@@ -3,55 +3,36 @@ shared_examples_for "#remove_role_examples" do |param_name, param_method|
|
|
|
3
3
|
context "removing a global role", :scope => :global do
|
|
4
4
|
context "being a global role of the user" do
|
|
5
5
|
it { expect { subject.remove_role("admin".send(param_method)) }.to change { subject.roles.size }.by(-1) }
|
|
6
|
-
|
|
7
|
-
it {
|
|
8
|
-
it { subject.has_role?("staff".send(param_method)).should be_true }
|
|
9
|
-
it { subject.has_role?("manager".send(param_method), Group).should be_true }
|
|
10
|
-
it { subject.has_role?("moderator".send(param_method), Forum.last).should be_true }
|
|
11
|
-
it { subject.has_role?("moderator".send(param_method), Group.last).should be_true }
|
|
12
|
-
it { subject.has_role?("anonymous".send(param_method), Forum.first).should be_true }
|
|
6
|
+
|
|
7
|
+
it { should_not have_role("admin".send(param_method)) }
|
|
13
8
|
end
|
|
14
|
-
|
|
9
|
+
|
|
15
10
|
context "being a class scoped role to the user" do
|
|
16
11
|
it { expect { subject.remove_role("manager".send(param_method)) }.to change { subject.roles.size }.by(-1) }
|
|
17
|
-
|
|
18
|
-
it {
|
|
19
|
-
it { subject.has_role?("staff".send(param_method)).should be_true }
|
|
20
|
-
it { subject.has_role?("manager".send(param_method), Group).should be_false }
|
|
21
|
-
it { subject.has_role?("moderator".send(param_method), Forum.last).should be_true }
|
|
22
|
-
it { subject.has_role?("moderator".send(param_method), Group.last).should be_true }
|
|
23
|
-
it { subject.has_role?("anonymous".send(param_method), Forum.first).should be_true }
|
|
12
|
+
|
|
13
|
+
it { should_not have_role("manager".send(param_method), Group) }
|
|
24
14
|
end
|
|
25
|
-
|
|
15
|
+
|
|
26
16
|
context "being instance scoped roles to the user" do
|
|
27
17
|
it { expect { subject.remove_role("moderator".send(param_method)) }.to change { subject.roles.size }.by(-2) }
|
|
28
|
-
|
|
29
|
-
it {
|
|
30
|
-
it {
|
|
31
|
-
it { subject.has_role?("manager".send(param_method), Group).should be_false }
|
|
32
|
-
it { subject.has_role?("moderator".send(param_method), Forum.last).should be_false }
|
|
33
|
-
it { subject.has_role?("moderator".send(param_method), Group.last).should be_false }
|
|
34
|
-
it { subject.has_role?("anonymous".send(param_method), Forum.first).should be_true }
|
|
18
|
+
|
|
19
|
+
it { should_not have_role("moderator".send(param_method), Forum.last) }
|
|
20
|
+
it { should_not have_role("moderator".send(param_method), Group.last) }
|
|
35
21
|
end
|
|
36
|
-
|
|
22
|
+
|
|
37
23
|
context "not being a role of the user" do
|
|
38
24
|
it { expect { subject.remove_role("superhero".send(param_method)) }.not_to change { subject.roles.size } }
|
|
39
25
|
end
|
|
40
|
-
|
|
26
|
+
|
|
41
27
|
context "used by another user" do
|
|
42
28
|
before do
|
|
43
29
|
user = user_class.last
|
|
44
30
|
user.add_role "staff".send(param_method)
|
|
45
31
|
end
|
|
46
|
-
|
|
32
|
+
|
|
47
33
|
it { expect { subject.remove_role("staff".send(param_method)) }.not_to change { role_class.count } }
|
|
48
|
-
|
|
49
|
-
it {
|
|
50
|
-
it { subject.has_role?("staff".send(param_method)).should be_false }
|
|
51
|
-
it { subject.has_role?("manager".send(param_method), Group).should be_false }
|
|
52
|
-
it { subject.has_role?("moderator".send(param_method), Forum.last).should be_false }
|
|
53
|
-
it { subject.has_role?("moderator".send(param_method), Group.last).should be_false }
|
|
54
|
-
it { subject.has_role?("anonymous".send(param_method), Forum.first).should be_true }
|
|
34
|
+
|
|
35
|
+
it { should_not have_role("staff".send(param_method)) }
|
|
55
36
|
end
|
|
56
37
|
|
|
57
38
|
context "not used by anyone else" do
|
|
@@ -67,29 +48,20 @@ shared_examples_for "#remove_role_examples" do |param_name, param_method|
|
|
|
67
48
|
context "being a global role of the user" do
|
|
68
49
|
it { expect { subject.remove_role("warrior".send(param_method), Forum) }.not_to change{ subject.roles.size } }
|
|
69
50
|
end
|
|
70
|
-
|
|
51
|
+
|
|
71
52
|
context "being a class scoped role to the user" do
|
|
72
53
|
it { expect { subject.remove_role("manager".send(param_method), Forum) }.to change{ subject.roles.size }.by(-1) }
|
|
73
|
-
|
|
74
|
-
it {
|
|
75
|
-
it { subject.has_role?("manager", Forum).should be_false }
|
|
76
|
-
it { subject.has_role?("player", Forum).should be_true }
|
|
77
|
-
it { subject.has_role?("moderator".send(param_method), Forum.last).should be_true }
|
|
78
|
-
it { subject.has_role?("moderator".send(param_method), Group.last).should be_true }
|
|
79
|
-
it { subject.has_role?("anonymous".send(param_method), Forum.first).should be_true }
|
|
54
|
+
|
|
55
|
+
it { should_not have_role("manager", Forum) }
|
|
80
56
|
end
|
|
81
|
-
|
|
57
|
+
|
|
82
58
|
context "being instance scoped role to the user" do
|
|
83
59
|
it { expect { subject.remove_role("moderator".send(param_method), Forum) }.to change { subject.roles.size }.by(-1) }
|
|
84
|
-
|
|
85
|
-
it {
|
|
86
|
-
it {
|
|
87
|
-
it { subject.has_role?("player", Forum).should be_true }
|
|
88
|
-
it { subject.has_role?("moderator".send(param_method), Forum.last).should be_false }
|
|
89
|
-
it { subject.has_role?("moderator".send(param_method), Group.last).should be_true }
|
|
90
|
-
it { subject.has_role?("anonymous".send(param_method), Forum.first).should be_true }
|
|
60
|
+
|
|
61
|
+
it { should_not have_role("moderator".send(param_method), Forum.last) }
|
|
62
|
+
it { should have_role("moderator".send(param_method), Group.last) }
|
|
91
63
|
end
|
|
92
|
-
|
|
64
|
+
|
|
93
65
|
context "not being a role of the user" do
|
|
94
66
|
it { expect { subject.remove_role("manager".send(param_method), Group) }.not_to change { subject.roles.size } }
|
|
95
67
|
end
|
|
@@ -99,23 +71,20 @@ shared_examples_for "#remove_role_examples" do |param_name, param_method|
|
|
|
99
71
|
context "being a global role of the user" do
|
|
100
72
|
it { expect { subject.remove_role("soldier".send(param_method), Group.first) }.not_to change { subject.roles.size } }
|
|
101
73
|
end
|
|
102
|
-
|
|
74
|
+
|
|
103
75
|
context "being a class scoped role to the user" do
|
|
104
76
|
it { expect { subject.remove_role("visitor".send(param_method), Forum.first) }.not_to change { subject.roles.size } }
|
|
105
77
|
end
|
|
106
|
-
|
|
78
|
+
|
|
107
79
|
context "being instance scoped role to the user" do
|
|
108
80
|
it { expect { subject.remove_role("moderator".send(param_method), Forum.first) }.to change { subject.roles.size }.by(-1) }
|
|
109
|
-
|
|
110
|
-
it {
|
|
111
|
-
it { subject.has_role?("visitor", Forum).should be_true }
|
|
112
|
-
it { subject.has_role?("moderator", Forum.first).should be_false }
|
|
113
|
-
it { subject.has_role?("anonymous", Forum.last).should be_true }
|
|
81
|
+
|
|
82
|
+
it { should_not have_role("moderator", Forum.first) }
|
|
114
83
|
end
|
|
115
|
-
|
|
84
|
+
|
|
116
85
|
context "not being a role of the user" do
|
|
117
86
|
it { expect { subject.remove_role("anonymous".send(param_method), Forum.first) }.not_to change { subject.roles.size } }
|
|
118
87
|
end
|
|
119
88
|
end
|
|
120
89
|
end
|
|
121
|
-
end
|
|
90
|
+
end
|