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.
Files changed (36) hide show
  1. data/.travis.yml +32 -16
  2. data/CHANGELOG.rdoc +6 -0
  3. data/Gemfile +4 -2
  4. data/README.md +1 -1
  5. data/Rakefile +6 -6
  6. data/gemfiles/Gemfile.rails-3.2 +14 -15
  7. data/gemfiles/Gemfile.rails-4.0 +21 -22
  8. data/gemfiles/Gemfile.rails-4.1 +37 -0
  9. data/lib/generators/active_record/rolify_generator.rb +2 -2
  10. data/lib/rolify.rb +6 -0
  11. data/lib/rolify/adapters/active_record/resource_adapter.rb +25 -4
  12. data/lib/rolify/adapters/base.rb +4 -0
  13. data/lib/rolify/adapters/mongoid/resource_adapter.rb +18 -1
  14. data/lib/rolify/configure.rb +6 -2
  15. data/lib/rolify/resource.rb +12 -9
  16. data/lib/rolify/role.rb +8 -2
  17. data/lib/rolify/version.rb +1 -1
  18. data/rolify.gemspec +15 -15
  19. data/spec/rolify/config_spec.rb +6 -7
  20. data/spec/rolify/resource_spec.rb +22 -6
  21. data/spec/rolify/shared_contexts.rb +1 -0
  22. data/spec/rolify/shared_examples/shared_examples_for_callbacks.rb +4 -4
  23. data/spec/rolify/shared_examples/shared_examples_for_dynamic.rb +27 -27
  24. data/spec/rolify/shared_examples/shared_examples_for_finders.rb +4 -0
  25. data/spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb +29 -29
  26. data/spec/rolify/shared_examples/shared_examples_for_has_any_role.rb +32 -32
  27. data/spec/rolify/shared_examples/shared_examples_for_has_role.rb +38 -38
  28. data/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb +44 -44
  29. data/spec/rolify/shared_examples/shared_examples_for_roles.rb +21 -15
  30. data/spec/spec_helper.rb +26 -3
  31. data/spec/support/adapters/active_record.rb +12 -4
  32. data/spec/support/adapters/mongoid.rb +8 -0
  33. data/spec/support/data.rb +4 -1
  34. data/spec/support/schema.rb +4 -0
  35. metadata +48 -33
  36. 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 be_true }
9
- it { subject.has_any_role?("admin".send(param_method), "staff".send(param_method)).should be_true }
10
- it { subject.has_any_role?("admin".send(param_method), "moderator".send(param_method)).should be_true }
11
- it { subject.has_any_role?("dummy".send(param_method), "dumber".send(param_method)).should be_false }
12
- it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "admin".send(param_method), :resource => Group }).should be_true }
13
- it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => :any }, { :name => "admin".send(param_method), :resource => Group }).should be_true }
14
- it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum }, { :name => "staff".send(param_method), :resource => Group.last }).should be_true }
15
- it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "admin".send(param_method), :resource => Forum.last }).should be_true }
16
- it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => Forum.last }).should be_true }
17
- it { subject.has_any_role?({ :name => "admin".send(param_method), :resource => Forum.first }, { :name => "dummy".send(param_method), :resource => :any }).should be_true }
18
- it { subject.has_any_role?({ :name => "dummy".send(param_method), :resource => Forum.first }, { :name => "dumber".send(param_method), :resource => :any }).should be_false }
19
- it { subject.has_any_role?({ :name => "dummy".send(param_method), :resource => :any }, { :name => "dumber".send(param_method), :resource => :any }).should be_false }
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 be_true }
29
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => Forum }).should be_true }
30
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => :any }).should be_true }
31
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "player".send(param_method), :resource => :any }).should be_true }
32
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => :any }, { :name => "player".send(param_method), :resource => :any }).should be_true }
33
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => Forum }).should be_true }
34
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum }, { :name => "dummy".send(param_method), :resource => :any }).should be_true }
35
- it { subject.has_any_role?({ :name => "dummy".send(param_method), :resource => Forum }, { :name => "dumber".send(param_method), :resource => Group }).should be_false }
36
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "manager".send(param_method), :resource => Forum.last }).should be_true }
37
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Group }, { :name => "moderator".send(param_method), :resource => Forum.first }).should be_false }
38
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum.first }, { :name => "moderator".send(param_method), :resource => Forum }).should be_true }
39
- it { subject.has_any_role?({ :name => "manager".send(param_method), :resource => Forum.last }, { :name => "warrior".send(param_method), :resource => Forum.last }).should be_true }
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 be_true }
50
- it { subject.has_any_role?({ :name => "moderator", :resource => Forum.first }, { :name => "visitor", :resource => Forum.last }).should be_true }
51
- it { subject.has_any_role?({ :name => "moderator", :resource => :any }, { :name => "visitor", :resource => Forum.last }).should be_true }
52
- it { subject.has_any_role?({ :name => "moderator", :resource => :any }, { :name => "visitor", :resource => :any}).should be_true }
53
- it { subject.has_any_role?({ :name => "moderator", :resource => Forum }, { :name => "visitor", :resource => :any }).should be_true }
54
- it { subject.has_any_role?({ :name => "moderator", :resource => Forum.first }, { :name => "moderator", :resource => Forum.last }).should be_true }
55
- it { subject.has_any_role?({ :name => "moderator", :resource => Forum.first }, { :name => "dummy", :resource => Forum.last }).should be_true }
56
- it { subject.has_any_role?({ :name => "dummy", :resource => Forum.first }, { :name => "dumber", :resource => Forum.last }).should be_false }
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 be_true }
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 be_true }
8
- it { subject.has_role?("admin".send(param_method), Forum).should be_true }
9
- it { subject.has_role?("admin".send(param_method), :any).should be_true }
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 be_false }
16
- it { subject.has_role?("global".send(param_method), :any).should be_false }
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 be_false
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 be_false
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 be_false }
29
- it { subject.has_role?("dumber".send(param_method), Forum.first).should be_false }
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 be_true }
36
- it { subject.has_role?("manager".send(param_method), Forum.first).should be_true }
37
- it { subject.has_role?("manager".send(param_method), :any).should be_true }
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 be_false
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 be_false
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 be_false }
54
- it { subject.has_role?("member".send(param_method), :any).should be_false }
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 be_false }
61
- it { subject.has_role?("manager".send(param_method), :any).should be_true }
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 be_false }
68
- it { subject.has_role?("defenders".send(param_method), :any).should be_false }
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 be_false }
74
- it { subject.has_role?("dumber".send(param_method)).should be_false }
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 be_true }
81
- it { subject.has_role?("moderator".send(param_method), :any).should be_true }
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 be_false
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 be_false
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 be_false
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 be_false }
102
- it { subject.has_role?("member".send(param_method), :any).should be_false }
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 be_false }
109
- it { subject.has_role?("moderator".send(param_method), :any).should be_true }
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 be_false }
116
- it { subject.has_role?("moderator".send(param_method), :any).should be_true }
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 be_false }
123
- it { subject.has_role?("member".send(param_method), :any).should be_false }
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 be_false }
130
- it { subject.has_role?("member".send(param_method), :any).should be_false }
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 be_true }
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 be_true }
14
- it { subject.only_has_role?("global_role".send(param_method), Forum).should be_true }
15
- it { subject.only_has_role?("global_role".send(param_method), :any).should be_true }
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 be_false }
22
- it { subject.only_has_role?("another_global_role".send(param_method), :any).should be_false }
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 be_false
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 be_false
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 be_false }
35
- it { subject.only_has_role?("dumber".send(param_method), Forum.first).should be_false }
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 be_false }
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 be_true }
54
- it { subject.only_has_role?("class_role".send(param_method), Forum.first).should be_true }
55
- it { subject.only_has_role?("class_role".send(param_method), :any).should be_true }
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 be_false
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 be_false
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 be_false }
72
- it { subject.only_has_role?("another_class_role".send(param_method), :any).should be_false }
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 be_false }
79
- it { subject.only_has_role?("class_role".send(param_method), :any).should be_true }
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 be_false }
86
- it { subject.only_has_role?("another_class_role".send(param_method), :any).should be_false }
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 be_false }
92
- it { subject.only_has_role?("dumber".send(param_method)).should be_false }
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 be_false }
99
- it { subject.only_has_role?("class_role".send(param_method), Forum.first).should be_false }
100
- it { subject.only_has_role?("class_role".send(param_method), :any).should be_false }
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 be_true }
113
- it { subject.only_has_role?("instance_role".send(param_method), :any).should be_true }
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 be_false
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 be_false
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 be_false
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 be_false }
134
- it { subject.only_has_role?("another_instance_role".send(param_method), :any).should be_false }
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 be_false }
141
- it { subject.only_has_role?("instance_role".send(param_method), :any).should be_true }
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 be_false }
148
- it { subject.only_has_role?("instance_role".send(param_method), :any).should be_true }
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 be_false }
155
- it { subject.only_has_role?("another_instance_role".send(param_method), :any).should be_false }
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 be_false }
162
- it { subject.only_has_role?("another_instance_role".send(param_method), :any).should be_false }
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 be_false }
170
- it { subject.only_has_role?("instance_role".send(param_method), :any).should be_false }
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