mongoid_ability 3.0.0 → 3.0.2
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 +4 -4
- data/.github/workflows/test.yml +26 -0
- data/.gitignore +2 -0
- data/.travis.yml +8 -1
- data/Appraisals +31 -0
- data/CHANGELOG.md +8 -0
- data/Rakefile +3 -2
- data/gemfiles/7_0.gemfile +7 -0
- data/gemfiles/7_1.gemfile +7 -0
- data/gemfiles/7_2.gemfile +7 -0
- data/gemfiles/7_3.gemfile +7 -0
- data/gemfiles/7_4.gemfile +7 -0
- data/gemfiles/7_5.gemfile +7 -0
- data/gemfiles/8_0.gemfile +7 -0
- data/gemfiles/8_1.gemfile +7 -0
- data/lib/cancancan/model_adapters/mongoid_adapter.rb +51 -42
- data/lib/cancancan/model_additions.rb +2 -0
- data/lib/mongoid_ability/ability.rb +3 -1
- data/lib/mongoid_ability/find_lock.rb +2 -2
- data/lib/mongoid_ability/lock.rb +62 -77
- data/lib/mongoid_ability/locks_decorator.rb +2 -0
- data/lib/mongoid_ability/owner.rb +2 -0
- data/lib/mongoid_ability/subject.rb +11 -1
- data/lib/mongoid_ability/version.rb +3 -1
- data/lib/mongoid_ability.rb +0 -2
- data/mongoid_ability.gemspec +4 -4
- data/test/cancancan/model_adapters/mongoid_adapter_options_test.rb +69 -68
- data/test/cancancan/model_adapters/mongoid_adapter_test.rb +83 -69
- data/test/mongoid_ability/ability_basic_benchmark.rb +2 -2
- data/test/mongoid_ability/ability_basic_test.rb +14 -14
- data/test/mongoid_ability/ability_marshal_test.rb +8 -3
- data/test/mongoid_ability/ability_options_test.rb +16 -16
- data/test/mongoid_ability/ability_test.rb +31 -35
- data/test/mongoid_ability/find_lock_test.rb +9 -9
- data/test/mongoid_ability/lock_test.rb +20 -30
- data/test/mongoid_ability/owner_locks_test.rb +4 -4
- data/test/mongoid_ability/owner_test.rb +6 -6
- data/test/mongoid_ability/subject_test.rb +13 -13
- data/test/support/test_classes/my_flat_subject.rb +9 -0
- data/test/test_helper.rb +7 -10
- metadata +29 -24
@@ -1,101 +1,102 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
module CanCan
|
4
4
|
module ModelAdapters
|
5
5
|
describe MongoidAdapter do
|
6
|
-
describe
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
describe 'Boolean' do
|
17
|
-
let(:subject2) { MySubject.new(override: true) }
|
18
|
-
|
19
|
-
describe 'positive' do
|
20
|
-
before(:all) { MySubject.default_lock MyLock, :read, true, override: true }
|
21
|
-
|
22
|
-
it { MySubject.accessible_by(ability).wont_include subject1 }
|
23
|
-
it { MySubject.accessible_by(ability).must_include subject2 }
|
6
|
+
describe ".accessible_by" do
|
7
|
+
describe "Boolean" do
|
8
|
+
it "returns correct records when using positive locks" do
|
9
|
+
MySubject.default_lock MyLock, :read, true, override: true
|
10
|
+
unaccessible = MySubject.create!
|
11
|
+
accessible = MySubject.create!(override: true)
|
12
|
+
|
13
|
+
_(MySubject.accessible_by(ability)).wont_include unaccessible
|
14
|
+
_(MySubject.accessible_by(ability)).must_include accessible
|
24
15
|
end
|
25
16
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
it "returns the correct records when using negative locks" do
|
18
|
+
MySubject.default_lock MyLock, :read, true
|
19
|
+
MySubject.default_lock MyLock, :read, false, override: true
|
20
|
+
accessible = MySubject.create!
|
21
|
+
unaccessible = MySubject.create!(override: true)
|
31
22
|
|
32
|
-
|
33
|
-
|
23
|
+
_(MySubject.accessible_by(ability)).must_include accessible
|
24
|
+
_(MySubject.accessible_by(ability)).wont_include unaccessible
|
34
25
|
end
|
35
26
|
end
|
36
27
|
|
37
|
-
describe
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
28
|
+
describe "String" do
|
29
|
+
it "returns correct records when using positive locks" do
|
30
|
+
MySubject.default_lock MyLock, :read, true, str_val: "Jan Tschichold"
|
31
|
+
unaccessible = MySubject.create!
|
32
|
+
accessible = MySubject.create!(str_val: "Jan Tschichold")
|
42
33
|
|
43
|
-
|
44
|
-
|
34
|
+
_(MySubject.accessible_by(ability)).wont_include unaccessible
|
35
|
+
_(MySubject.accessible_by(ability)).must_include accessible
|
45
36
|
end
|
46
37
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
38
|
+
it "returns the correct records when using negative locks" do
|
39
|
+
MySubject.default_lock MyLock, :read, true
|
40
|
+
MySubject.default_lock MyLock, :read, false, str_val: "Jan Tschichold"
|
41
|
+
accessible = MySubject.create!
|
42
|
+
unaccessible = MySubject.create!(str_val: "Jan Tschichold")
|
52
43
|
|
53
|
-
|
54
|
-
|
44
|
+
_(MySubject.accessible_by(ability)).must_include accessible
|
45
|
+
_(MySubject.accessible_by(ability)).wont_include unaccessible
|
55
46
|
end
|
56
47
|
end
|
57
48
|
|
58
|
-
describe
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
49
|
+
describe "Regexp" do
|
50
|
+
it "returns correct records when using positive locks" do
|
51
|
+
MySubject.default_lock MyLock, :read, true, str_val: /tschichold/i
|
52
|
+
unaccessible = MySubject.create!
|
53
|
+
accessible = MySubject.create!(str_val: "Jan Tschichold")
|
63
54
|
|
64
|
-
|
65
|
-
|
55
|
+
_(MySubject.accessible_by(ability)).wont_include unaccessible
|
56
|
+
_(MySubject.accessible_by(ability)).must_include accessible
|
66
57
|
end
|
67
58
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
it "returns the correct records when using negative locks" do
|
60
|
+
MySubject.default_lock MyLock, :read, true
|
61
|
+
MySubject.default_lock MyLock, :read, false, str_val: /tschichold/i
|
62
|
+
accessible = MySubject.create!
|
63
|
+
unaccessible = MySubject.create!(str_val: "Jan Tschichold")
|
73
64
|
|
74
|
-
|
75
|
-
|
65
|
+
_(MySubject.accessible_by(ability)).must_include accessible
|
66
|
+
_(MySubject.accessible_by(ability)).wont_include unaccessible
|
76
67
|
end
|
77
68
|
end
|
78
69
|
|
79
|
-
describe
|
80
|
-
|
70
|
+
describe "Array" do
|
71
|
+
it "returns correct records when using positive locks" do
|
72
|
+
MySubject.default_lock MyLock, :read, true, str_val: %w[John Paul George Ringo]
|
73
|
+
unaccessible = MySubject.create!
|
74
|
+
accessible = MySubject.create!(str_val: "John")
|
81
75
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
it { MySubject.accessible_by(ability).wont_include subject1 }
|
86
|
-
it { MySubject.accessible_by(ability).must_include subject2 }
|
76
|
+
_(MySubject.accessible_by(ability)).wont_include unaccessible
|
77
|
+
_(MySubject.accessible_by(ability)).must_include accessible
|
87
78
|
end
|
88
79
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
80
|
+
it "returns the correct records when using negative locks" do
|
81
|
+
MySubject.default_lock MyLock, :read, true
|
82
|
+
MySubject.default_lock MyLock, :read, false, str_val: %w[John Paul George Ringo]
|
83
|
+
accessible = MySubject.create!
|
84
|
+
unaccessible = MySubject.create!(str_val: "John")
|
94
85
|
|
95
|
-
|
96
|
-
|
86
|
+
_(MySubject.accessible_by(ability)).must_include accessible
|
87
|
+
_(MySubject.accessible_by(ability)).wont_include unaccessible
|
97
88
|
end
|
98
89
|
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def owner
|
94
|
+
MyOwner.new
|
95
|
+
end
|
96
|
+
|
97
|
+
def ability
|
98
|
+
MongoidAbility::Ability.new(owner)
|
99
|
+
end
|
99
100
|
end
|
100
101
|
end
|
101
102
|
end
|
@@ -25,37 +25,47 @@ module CanCan
|
|
25
25
|
|
26
26
|
describe 'subject type locks' do
|
27
27
|
describe 'default open locks' do
|
28
|
-
before
|
28
|
+
before do
|
29
|
+
MySubject.default_lock MyLock, :read, true
|
30
|
+
end
|
31
|
+
|
32
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include my_subject }
|
33
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include my_subject1 }
|
34
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include my_subject2 }
|
29
35
|
|
30
|
-
it {
|
31
|
-
it {
|
32
|
-
it {
|
36
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include my_subject }
|
37
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).must_include my_subject1 }
|
38
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).must_include my_subject2 }
|
33
39
|
|
34
|
-
it {
|
35
|
-
it {
|
36
|
-
it {
|
40
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include my_subject }
|
41
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include my_subject1 }
|
42
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).must_include my_subject2 }
|
37
43
|
|
38
|
-
it
|
39
|
-
|
40
|
-
|
44
|
+
it 'works for non sci classes' do
|
45
|
+
MyFlatSubject.default_lock MyLock, :read, true
|
46
|
+
flat_subject = MyFlatSubject.create!
|
47
|
+
|
48
|
+
_(MyFlatSubject.accessible_by(ability, :read).to_a)
|
49
|
+
.must_include flat_subject
|
50
|
+
end
|
41
51
|
end
|
42
52
|
|
43
53
|
describe 'default closed locks' do
|
44
54
|
before { MySubject.default_lock MyLock, :read, false }
|
45
55
|
|
46
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include my_subject }
|
47
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include my_subject1 }
|
48
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
56
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include my_subject }
|
57
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include my_subject1 }
|
58
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
49
59
|
|
50
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include my_subject }
|
51
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include my_subject1 }
|
52
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
60
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include my_subject }
|
61
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include my_subject1 }
|
62
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
53
63
|
|
54
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include my_subject }
|
55
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include my_subject1 }
|
56
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
64
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include my_subject }
|
65
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include my_subject1 }
|
66
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
57
67
|
|
58
|
-
it { MySubject.accessible_by(ability, :read).selector.must_equal({}) }
|
68
|
+
it { _(MySubject.accessible_by(ability, :read).selector).must_equal({}) }
|
59
69
|
end
|
60
70
|
|
61
71
|
describe 'default combined locks' do
|
@@ -65,14 +75,14 @@ module CanCan
|
|
65
75
|
MySubject2.default_lock MyLock, :read, false
|
66
76
|
end
|
67
77
|
|
68
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include my_subject }
|
69
|
-
it { MySubject.accessible_by(ability, :read).to_a.must_include my_subject1 }
|
70
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
78
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include my_subject }
|
79
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include my_subject1 }
|
80
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
71
81
|
|
72
|
-
it { MySubject1.accessible_by(ability, :read).to_a.must_include my_subject1 }
|
73
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
82
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).must_include my_subject1 }
|
83
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
74
84
|
|
75
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
85
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
76
86
|
end
|
77
87
|
|
78
88
|
describe 'combined locks' do
|
@@ -84,14 +94,14 @@ module CanCan
|
|
84
94
|
let(:role) { MyRole.new(my_locks: [lock]) }
|
85
95
|
let(:owner) { MyOwner.new(my_roles: [role]) }
|
86
96
|
|
87
|
-
it { MySubject.accessible_by(ability, :read).to_a.must_include my_subject }
|
88
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include my_subject1 }
|
89
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
97
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include my_subject }
|
98
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include my_subject1 }
|
99
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
90
100
|
|
91
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include my_subject1 }
|
92
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
101
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include my_subject1 }
|
102
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
93
103
|
|
94
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
104
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
95
105
|
end
|
96
106
|
end
|
97
107
|
|
@@ -105,9 +115,9 @@ module CanCan
|
|
105
115
|
MySubject.default_lock MyLock, :read, true
|
106
116
|
end
|
107
117
|
|
108
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include my_subject }
|
109
|
-
it { MySubject.accessible_by(ability, :read).to_a.must_include my_subject1 }
|
110
|
-
it { MySubject.accessible_by(ability, :read).to_a.must_include my_subject2 }
|
118
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include my_subject }
|
119
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include my_subject1 }
|
120
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include my_subject2 }
|
111
121
|
end
|
112
122
|
|
113
123
|
describe 'open id locks' do
|
@@ -118,9 +128,9 @@ module CanCan
|
|
118
128
|
MySubject.default_lock MyLock, :read, false
|
119
129
|
end
|
120
130
|
|
121
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include my_subject }
|
122
|
-
it { MySubject1.accessible_by(ability, :read).to_a.must_include my_subject1 }
|
123
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include my_subject2 }
|
131
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include my_subject }
|
132
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).must_include my_subject1 }
|
133
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include my_subject2 }
|
124
134
|
end
|
125
135
|
|
126
136
|
describe 'closed types & open ids' do
|
@@ -130,8 +140,8 @@ module CanCan
|
|
130
140
|
|
131
141
|
let(:owner) { MyOwner.new(my_locks: [lock_1, lock_2, lock_3]) }
|
132
142
|
|
133
|
-
it { MySubject.accessible_by(ability, :read).must_include my_subject }
|
134
|
-
it { MySubject.accessible_by(ability, :read).must_include my_subject1 }
|
143
|
+
it { _(MySubject.accessible_by(ability, :read)).must_include my_subject }
|
144
|
+
it { _(MySubject.accessible_by(ability, :read)).must_include my_subject1 }
|
135
145
|
end
|
136
146
|
end
|
137
147
|
|
@@ -139,19 +149,21 @@ module CanCan
|
|
139
149
|
describe 'positive' do
|
140
150
|
let(:my_subject1) { MySubject1.new(override: true) }
|
141
151
|
|
142
|
-
before(:all)
|
152
|
+
before(:all) do
|
153
|
+
MySubject.default_lock MyLock, :read, true, override: true
|
154
|
+
end
|
143
155
|
|
144
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include(my_subject) }
|
145
|
-
it { MySubject.accessible_by(ability, :read).to_a.must_include(my_subject1) }
|
146
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include(my_subject2) }
|
156
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include(my_subject) }
|
157
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include(my_subject1) }
|
158
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include(my_subject2) }
|
147
159
|
|
148
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include(my_subject) }
|
149
|
-
it { MySubject1.accessible_by(ability, :read).to_a.must_include(my_subject1) }
|
150
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include(my_subject2) }
|
160
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include(my_subject) }
|
161
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).must_include(my_subject1) }
|
162
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include(my_subject2) }
|
151
163
|
|
152
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include(my_subject) }
|
153
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include(my_subject1) }
|
154
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include(my_subject2) }
|
164
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include(my_subject) }
|
165
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include(my_subject1) }
|
166
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include(my_subject2) }
|
155
167
|
end
|
156
168
|
|
157
169
|
describe 'negative' do
|
@@ -162,17 +174,17 @@ module CanCan
|
|
162
174
|
MySubject.default_lock MyLock, :read, false, override: true
|
163
175
|
end
|
164
176
|
|
165
|
-
it { MySubject.accessible_by(ability, :read).to_a.must_include(my_subject) }
|
166
|
-
it { MySubject.accessible_by(ability, :read).to_a.wont_include(my_subject1) }
|
167
|
-
it { MySubject.accessible_by(ability, :read).to_a.must_include(my_subject2) }
|
177
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include(my_subject) }
|
178
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).wont_include(my_subject1) }
|
179
|
+
it { _(MySubject.accessible_by(ability, :read).to_a).must_include(my_subject2) }
|
168
180
|
|
169
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include(my_subject) }
|
170
|
-
it { MySubject1.accessible_by(ability, :read).to_a.wont_include(my_subject1) }
|
171
|
-
it { MySubject1.accessible_by(ability, :read).to_a.must_include(my_subject2) }
|
181
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include(my_subject) }
|
182
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).wont_include(my_subject1) }
|
183
|
+
it { _(MySubject1.accessible_by(ability, :read).to_a).must_include(my_subject2) }
|
172
184
|
|
173
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include(my_subject) }
|
174
|
-
it { MySubject2.accessible_by(ability, :read).to_a.wont_include(my_subject1) }
|
175
|
-
it { MySubject2.accessible_by(ability, :read).to_a.must_include(my_subject2) }
|
185
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include(my_subject) }
|
186
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).wont_include(my_subject1) }
|
187
|
+
it { _(MySubject2.accessible_by(ability, :read).to_a).must_include(my_subject2) }
|
176
188
|
end
|
177
189
|
end
|
178
190
|
end
|
@@ -182,22 +194,24 @@ module CanCan
|
|
182
194
|
let(:lock_2) { MyLock.new(subject: my_subject2, action: :read, outcome: false) }
|
183
195
|
let(:role_1) { MyRole.new(my_locks: [lock_1, lock_2]) }
|
184
196
|
|
185
|
-
let(:prefix) { :subject }
|
186
|
-
let(:selector) { MySubject.accessible_by(ability, :read, prefix: prefix).selector }
|
187
|
-
|
188
197
|
before(:all) do
|
189
198
|
MySubject.default_lock MyLock, :read, true
|
190
199
|
end
|
191
200
|
|
192
201
|
it 'allows to pass prefix' do
|
193
|
-
|
194
|
-
|
195
|
-
|
202
|
+
prefix = :subject
|
203
|
+
selector = MySubject.accessible_by(ability, :read, prefix: prefix).selector
|
204
|
+
|
205
|
+
_(selector).must_equal(
|
206
|
+
{
|
207
|
+
'$or' => [
|
196
208
|
{ 'subject_type' => { '$nin' => [] } },
|
197
|
-
{ 'subject_id' => my_subject1.id }
|
198
|
-
]
|
199
|
-
|
200
|
-
|
209
|
+
{ 'subject_id' => my_subject1.id },
|
210
|
+
],
|
211
|
+
'$and' =>[
|
212
|
+
{ 'subject_id'=> { '$nin' => [my_subject2.id] } }
|
213
|
+
]
|
214
|
+
}
|
201
215
|
)
|
202
216
|
end
|
203
217
|
end
|
@@ -11,13 +11,13 @@ module MongoidAbility
|
|
11
11
|
|
12
12
|
bench_performance_constant 'can?' do |n|
|
13
13
|
n.times do
|
14
|
-
ability.can?(:read, MySubject).must_equal false
|
14
|
+
_(ability.can?(:read, MySubject)).must_equal false
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
bench_performance_constant 'cannot?' do |n|
|
19
19
|
n.times do
|
20
|
-
ability.cannot?(:read, MySubject).must_equal true
|
20
|
+
_(ability.cannot?(:read, MySubject)).must_equal true
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -6,15 +6,15 @@ module MongoidAbility
|
|
6
6
|
let(:ability) { Ability.new(owner) }
|
7
7
|
|
8
8
|
describe 'default' do
|
9
|
-
it { ability.can?(:read, MySubject).must_equal false }
|
10
|
-
it { ability.cannot?(:read, MySubject).must_equal true }
|
9
|
+
it { _(ability.can?(:read, MySubject)).must_equal false }
|
10
|
+
it { _(ability.cannot?(:read, MySubject)).must_equal true }
|
11
11
|
end
|
12
12
|
|
13
13
|
describe 'class locks' do
|
14
14
|
before(:all) { MySubject.default_lock MyLock, :read, true }
|
15
15
|
|
16
|
-
it { ability.can?(:read, MySubject).must_equal true }
|
17
|
-
it { ability.cannot?(:read, MySubject).must_equal false }
|
16
|
+
it { _(ability.can?(:read, MySubject)).must_equal true }
|
17
|
+
it { _(ability.cannot?(:read, MySubject)).must_equal false }
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'inherited locks' do
|
@@ -23,8 +23,8 @@ module MongoidAbility
|
|
23
23
|
let(:my_role) { MyRole.new(my_locks: [read_lock]) }
|
24
24
|
let(:owner) { MyOwner.new(my_roles: [my_role]) }
|
25
25
|
|
26
|
-
it { ability.can?(:read, MySubject).must_equal true }
|
27
|
-
it { ability.cannot?(:read, MySubject).must_equal false }
|
26
|
+
it { _(ability.can?(:read, MySubject)).must_equal true }
|
27
|
+
it { _(ability.cannot?(:read, MySubject)).must_equal false }
|
28
28
|
end
|
29
29
|
|
30
30
|
describe 'subject_id' do
|
@@ -33,14 +33,14 @@ module MongoidAbility
|
|
33
33
|
let(:my_role) { MyRole.new(my_locks: [read_lock]) }
|
34
34
|
let(:owner) { MyOwner.new(my_roles: [my_role]) }
|
35
35
|
|
36
|
-
it { ability.can?(:read, my_subject).must_equal true }
|
37
|
-
it { ability.cannot?(:read, my_subject).must_equal false }
|
36
|
+
it { _(ability.can?(:read, my_subject)).must_equal true }
|
37
|
+
it { _(ability.cannot?(:read, my_subject)).must_equal false }
|
38
38
|
|
39
39
|
describe 'when id stored as String' do
|
40
40
|
let(:read_lock) { MyLock.new(subject_type: my_subject.model_name.to_s, subject_id: my_subject.id.to_s, action: :read, outcome: true) }
|
41
41
|
|
42
|
-
it { ability.can?(:read, my_subject).must_equal true }
|
43
|
-
it { ability.cannot?(:read, my_subject).must_equal false }
|
42
|
+
it { _(ability.can?(:read, my_subject)).must_equal true }
|
43
|
+
it { _(ability.cannot?(:read, my_subject)).must_equal false }
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -50,8 +50,8 @@ module MongoidAbility
|
|
50
50
|
let(:read_lock) { MyLock.new(subject_type: MySubject, action: :read, outcome: true) }
|
51
51
|
let(:owner) { MyOwner.new(my_locks: [read_lock]) }
|
52
52
|
|
53
|
-
it { ability.can?(:read, MySubject).must_equal true }
|
54
|
-
it { ability.cannot?(:read, MySubject).must_equal false }
|
53
|
+
it { _(ability.can?(:read, MySubject)).must_equal true }
|
54
|
+
it { _(ability.cannot?(:read, MySubject)).must_equal false }
|
55
55
|
end
|
56
56
|
|
57
57
|
describe 'subject_id' do
|
@@ -59,8 +59,8 @@ module MongoidAbility
|
|
59
59
|
let(:read_lock) { MyLock.new(subject: my_subject, action: :read, outcome: true) }
|
60
60
|
let(:owner) { MyOwner.new(my_locks: [read_lock]) }
|
61
61
|
|
62
|
-
it { ability.can?(:read, my_subject).must_equal true }
|
63
|
-
it { ability.cannot?(:read, my_subject).must_equal false }
|
62
|
+
it { _(ability.can?(:read, my_subject)).must_equal true }
|
63
|
+
it { _(ability.cannot?(:read, my_subject)).must_equal false }
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -15,12 +15,17 @@ module MongoidAbility
|
|
15
15
|
let(:loaded_rules) { ability_load.send(:rules) }
|
16
16
|
|
17
17
|
describe 'dump' do
|
18
|
-
it { ability_dump.must_be :present? }
|
18
|
+
it { _(ability_dump).must_be :present? }
|
19
19
|
end
|
20
20
|
|
21
21
|
describe 'load' do
|
22
|
-
it
|
23
|
-
|
22
|
+
it 'loads rules for each lock' do
|
23
|
+
_(loaded_rules.count { |rule| rule.subjects == [MySubject] }).must_equal 2
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'builds conditions for the subjects id' do
|
27
|
+
_(loaded_rules.map(&:conditions)).must_include({ id: my_subject.id })
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
26
31
|
end
|
@@ -12,8 +12,8 @@ module MongoidAbility
|
|
12
12
|
describe 'positive' do
|
13
13
|
before(:all) { MySubject.default_lock MyLock, :read, true, override: true }
|
14
14
|
|
15
|
-
it { ability.can?(:read, subject1).must_equal false }
|
16
|
-
it { ability.can?(:read, subject2).must_equal true }
|
15
|
+
it { _(ability.can?(:read, subject1)).must_equal false }
|
16
|
+
it { _(ability.can?(:read, subject2)).must_equal true }
|
17
17
|
end
|
18
18
|
|
19
19
|
describe 'negative' do
|
@@ -22,8 +22,8 @@ module MongoidAbility
|
|
22
22
|
MySubject.default_lock MyLock, :read, false, override: true
|
23
23
|
end
|
24
24
|
|
25
|
-
it { ability.can?(:read, subject1).must_equal true }
|
26
|
-
it { ability.can?(:read, subject2).must_equal false }
|
25
|
+
it { _(ability.can?(:read, subject1)).must_equal true }
|
26
|
+
it { _(ability.can?(:read, subject2)).must_equal false }
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -33,8 +33,8 @@ module MongoidAbility
|
|
33
33
|
describe 'positive' do
|
34
34
|
before(:all) { MySubject.default_lock MyLock, :read, true, str_val: 'Jan Tschichold' }
|
35
35
|
|
36
|
-
it { ability.can?(:read, subject1).must_equal false }
|
37
|
-
it { ability.can?(:read, subject2).must_equal true }
|
36
|
+
it { _(ability.can?(:read, subject1)).must_equal false }
|
37
|
+
it { _(ability.can?(:read, subject2)).must_equal true }
|
38
38
|
end
|
39
39
|
|
40
40
|
describe 'negative' do
|
@@ -43,8 +43,8 @@ module MongoidAbility
|
|
43
43
|
MySubject.default_lock MyLock, :read, false, str_val: 'Jan Tschichold'
|
44
44
|
end
|
45
45
|
|
46
|
-
it { ability.can?(:read, subject1).must_equal true }
|
47
|
-
it { ability.can?(:read, subject2).must_equal false }
|
46
|
+
it { _(ability.can?(:read, subject1)).must_equal true }
|
47
|
+
it { _(ability.can?(:read, subject2)).must_equal false }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -54,8 +54,8 @@ module MongoidAbility
|
|
54
54
|
describe 'positive' do
|
55
55
|
before(:all) { MySubject.default_lock MyLock, :read, true, str_val: /tschichold/i }
|
56
56
|
|
57
|
-
it { ability.can?(:read, subject1).must_equal false }
|
58
|
-
it { ability.can?(:read, subject2).must_equal true }
|
57
|
+
it { _(ability.can?(:read, subject1)).must_equal false }
|
58
|
+
it { _(ability.can?(:read, subject2)).must_equal true }
|
59
59
|
end
|
60
60
|
|
61
61
|
describe 'negative' do
|
@@ -64,8 +64,8 @@ module MongoidAbility
|
|
64
64
|
MySubject.default_lock MyLock, :read, false, str_val: /tschichold/i
|
65
65
|
end
|
66
66
|
|
67
|
-
it { ability.can?(:read, subject1).must_equal true }
|
68
|
-
it { ability.can?(:read, subject2).must_equal false }
|
67
|
+
it { _(ability.can?(:read, subject1)).must_equal true }
|
68
|
+
it { _(ability.can?(:read, subject2)).must_equal false }
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -75,8 +75,8 @@ module MongoidAbility
|
|
75
75
|
describe 'positive' do
|
76
76
|
before(:all) { MySubject.default_lock MyLock, :read, true, str_val: %w(John Paul George Ringo) }
|
77
77
|
|
78
|
-
it { ability.can?(:read, subject1).must_equal false }
|
79
|
-
it { ability.can?(:read, subject2).must_equal true }
|
78
|
+
it { _(ability.can?(:read, subject1)).must_equal false }
|
79
|
+
it { _(ability.can?(:read, subject2)).must_equal true }
|
80
80
|
end
|
81
81
|
|
82
82
|
describe 'negative' do
|
@@ -85,8 +85,8 @@ module MongoidAbility
|
|
85
85
|
MySubject.default_lock MyLock, :read, false, str_val: %w(John Paul George Ringo)
|
86
86
|
end
|
87
87
|
|
88
|
-
it { ability.can?(:read, subject1).must_equal true }
|
89
|
-
it { ability.can?(:read, subject2).must_equal false }
|
88
|
+
it { _(ability.can?(:read, subject1)).must_equal true }
|
89
|
+
it { _(ability.can?(:read, subject2)).must_equal false }
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|