mongoid_ability 3.0.0 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -6,30 +6,32 @@ module MongoidAbility
|
|
6
6
|
let(:ability) { Ability.new(owner) }
|
7
7
|
|
8
8
|
it 'exposes owner' do
|
9
|
-
ability.owner.must_equal owner
|
9
|
+
_(ability.owner).must_equal owner
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'default locks' do
|
13
|
-
|
14
|
-
|
13
|
+
after(:all) do
|
14
|
+
[MySubject, MySubject1, MySubject2, MySubject11, MySubject21]
|
15
|
+
.each(&:reset_default_locks!)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'propagates from superclass to subclasses' do
|
19
|
+
MySubject.default_lock MyLock, :update, true
|
15
20
|
|
16
|
-
|
17
|
-
ability.can?(:update,
|
18
|
-
ability.can?(:update,
|
19
|
-
ability.can?(:update, MySubject2).must_equal true
|
21
|
+
_(ability.can?(:update, MySubject)).must_equal true
|
22
|
+
_(ability.can?(:update, MySubject1)).must_equal true
|
23
|
+
_(ability.can?(:update, MySubject2)).must_equal true
|
20
24
|
end
|
21
|
-
end
|
22
25
|
|
23
|
-
|
24
|
-
before(:all) do
|
26
|
+
it 'supersedes superclass locks' do
|
25
27
|
MySubject.default_lock MyLock, :read, false
|
26
28
|
MySubject1.default_lock MyLock, :read, true
|
27
29
|
MySubject2.default_lock MyLock, :read, false
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
_(ability.can?(:read, MySubject)).must_equal false
|
32
|
+
_(ability.can?(:read, MySubject1)).must_equal true
|
33
|
+
_(ability.can?(:read, MySubject2)).must_equal false
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
describe 'when defined for some superclasses' do
|
@@ -40,25 +42,21 @@ module MongoidAbility
|
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'propagates default locks to subclasses' do
|
43
|
-
ability.can?(:read, MySubject).must_equal false
|
44
|
-
ability.can?(:read, MySubject1).must_equal false
|
45
|
-
ability.can?(:read, MySubject2).must_equal true
|
45
|
+
_(ability.can?(:read, MySubject)).must_equal false
|
46
|
+
_(ability.can?(:read, MySubject1)).must_equal false
|
47
|
+
_(ability.can?(:read, MySubject2)).must_equal true
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
|
-
# ---------------------------------------------------------------------
|
50
|
-
|
51
51
|
describe 'user locks' do
|
52
52
|
describe 'when defined for superclass' do
|
53
53
|
let(:owner) { MyOwner.new(my_locks: [MyLock.new(subject_type: MySubject, action: :read, outcome: true)]) }
|
54
54
|
before(:all) { MySubject.default_lock MyLock, :read, false }
|
55
55
|
|
56
|
-
it { ability.can?(:read, MySubject2).must_equal true }
|
56
|
+
it { _(ability.can?(:read, MySubject2)).must_equal true }
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
# ---------------------------------------------------------------------
|
61
|
-
|
62
60
|
describe 'inherited owner locks' do
|
63
61
|
describe 'when multiple inherited owners' do
|
64
62
|
let(:owner) do
|
@@ -70,7 +68,7 @@ module MongoidAbility
|
|
70
68
|
|
71
69
|
before(:all) { MySubject.default_lock MyLock, :read, false }
|
72
70
|
|
73
|
-
it { ability.can?(:read, MySubject).must_equal true }
|
71
|
+
it { _(ability.can?(:read, MySubject)).must_equal true }
|
74
72
|
end
|
75
73
|
|
76
74
|
describe 'when defined for superclass' do
|
@@ -82,12 +80,10 @@ module MongoidAbility
|
|
82
80
|
|
83
81
|
before(:all) { MySubject.default_lock MyLock, :read, false }
|
84
82
|
|
85
|
-
it { ability.can?(:read, MySubject2).must_equal true }
|
83
|
+
it { _(ability.can?(:read, MySubject2)).must_equal true }
|
86
84
|
end
|
87
85
|
end
|
88
86
|
|
89
|
-
# ---------------------------------------------------------------------
|
90
|
-
|
91
87
|
describe 'combined locks' do
|
92
88
|
describe 'user and role locks' do
|
93
89
|
let(:role_lock) { MyLock.new(subject_type: MySubject, action: :read, outcome: true) }
|
@@ -98,7 +94,7 @@ module MongoidAbility
|
|
98
94
|
|
99
95
|
before(:all) { MySubject.default_lock MyLock, :read, false }
|
100
96
|
|
101
|
-
it { ability.can?(:read, MySubject).must_equal false }
|
97
|
+
it { _(ability.can?(:read, MySubject)).must_equal false }
|
102
98
|
end
|
103
99
|
|
104
100
|
describe 'roles and default locks' do
|
@@ -109,13 +105,13 @@ module MongoidAbility
|
|
109
105
|
let(:role) { MyRole.new(my_locks: [lock]) }
|
110
106
|
let(:owner) { MyOwner.new(my_roles: [role]) }
|
111
107
|
|
112
|
-
it { ability.can?(:read, MySubject).must_equal true }
|
108
|
+
it { _(ability.can?(:read, MySubject)).must_equal true }
|
113
109
|
|
114
110
|
describe 'subclass' do
|
115
111
|
let(:lock) { MyLock.new(subject_type: MySubject1, action: :read, outcome: true) }
|
116
112
|
|
117
|
-
it { ability.can?(:read, MySubject).must_equal false }
|
118
|
-
it { ability.can?(:read, MySubject1).must_equal true }
|
113
|
+
it { _(ability.can?(:read, MySubject)).must_equal false }
|
114
|
+
it { _(ability.can?(:read, MySubject1)).must_equal true }
|
119
115
|
end
|
120
116
|
end
|
121
117
|
|
@@ -126,13 +122,13 @@ module MongoidAbility
|
|
126
122
|
let(:role) { MyRole.new(my_locks: [lock]) }
|
127
123
|
let(:owner) { MyOwner.new(my_roles: [role]) }
|
128
124
|
|
129
|
-
it { ability.can?(:read, MySubject).must_equal false }
|
125
|
+
it { _(ability.can?(:read, MySubject)).must_equal false }
|
130
126
|
|
131
127
|
describe 'subclass' do
|
132
128
|
let(:lock) { MyLock.new(subject_type: MySubject1, action: :read, outcome: false) }
|
133
129
|
|
134
|
-
it { ability.can?(:read, MySubject).must_equal true }
|
135
|
-
it { ability.can?(:read, MySubject1).must_equal false }
|
130
|
+
it { _(ability.can?(:read, MySubject)).must_equal true }
|
131
|
+
it { _(ability.can?(:read, MySubject1)).must_equal false }
|
136
132
|
end
|
137
133
|
end
|
138
134
|
|
@@ -146,8 +142,8 @@ module MongoidAbility
|
|
146
142
|
let(:role) { MyRole.new(my_locks: [lock]) }
|
147
143
|
let(:owner) { MyOwner.new(my_roles: [role]) }
|
148
144
|
|
149
|
-
it { ability.can?(:read, MySubject).must_equal true }
|
150
|
-
it { ability.can?(:read, MySubject1).must_equal false }
|
145
|
+
it { _(ability.can?(:read, MySubject)).must_equal true }
|
146
|
+
it { _(ability.can?(:read, MySubject1)).must_equal false }
|
151
147
|
end
|
152
148
|
end
|
153
149
|
end
|
@@ -7,8 +7,8 @@ module MongoidAbility
|
|
7
7
|
describe 'default lock' do
|
8
8
|
before { MySubject.default_lock MyLock, :read, true }
|
9
9
|
|
10
|
-
it { FindLock.call(owner, :read, MySubject).must_equal MySubject.default_locks.for_action(:read).first }
|
11
|
-
it { FindLock.call(owner, :read, MySubject1).must_equal MySubject.default_locks.for_action(:read).first }
|
10
|
+
it { _(FindLock.call(owner, :read, MySubject)).must_equal MySubject.default_locks.for_action(:read).first }
|
11
|
+
it { _(FindLock.call(owner, :read, MySubject1)).must_equal MySubject.default_locks.for_action(:read).first }
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'inherited lock' do
|
@@ -18,7 +18,7 @@ module MongoidAbility
|
|
18
18
|
let(:role) { MyRole.new(my_locks: [lock]) }
|
19
19
|
let(:owner) { MyOwner.new(my_roles: [role]) }
|
20
20
|
|
21
|
-
it { FindLock.call(owner, :read, MySubject).must_equal lock }
|
21
|
+
it { _(FindLock.call(owner, :read, MySubject)).must_equal lock }
|
22
22
|
|
23
23
|
describe 'conflicting locks' do
|
24
24
|
let(:lock_1) { MyLock.new(subject_type: MySubject, action: :read, outcome: true) }
|
@@ -28,7 +28,7 @@ module MongoidAbility
|
|
28
28
|
let(:role_2) { MyRole.new(my_locks: [lock_2]) }
|
29
29
|
let(:owner) { MyOwner.new(my_roles: [role_1, role_2]) }
|
30
30
|
|
31
|
-
it { FindLock.call(owner, :read, MySubject).must_equal lock_1 }
|
31
|
+
it { _(FindLock.call(owner, :read, MySubject)).must_equal lock_1 }
|
32
32
|
end
|
33
33
|
|
34
34
|
describe 'id lock' do
|
@@ -39,8 +39,8 @@ module MongoidAbility
|
|
39
39
|
let(:role) { MyRole.new(my_locks: [lock_1, lock_2]) }
|
40
40
|
let(:owner) { MyOwner.new(my_roles: [role]) }
|
41
41
|
|
42
|
-
it { FindLock.call(owner, :read, MySubject).must_equal MySubject.default_locks.for_action(:read).first }
|
43
|
-
it { FindLock.call(owner, :read, my_subject.class, my_subject.id).must_equal lock_1 }
|
42
|
+
it { _(FindLock.call(owner, :read, MySubject)).must_equal MySubject.default_locks.for_action(:read).first }
|
43
|
+
it { _(FindLock.call(owner, :read, my_subject.class, my_subject.id)).must_equal lock_1 }
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -50,7 +50,7 @@ module MongoidAbility
|
|
50
50
|
let(:lock) { MyLock.new(subject_type: MySubject, action: :read, outcome: false) }
|
51
51
|
let(:owner) { MyOwner.new(my_locks: [lock]) }
|
52
52
|
|
53
|
-
it { FindLock.call(owner, :read, MySubject).must_equal lock }
|
53
|
+
it { _(FindLock.call(owner, :read, MySubject)).must_equal lock }
|
54
54
|
|
55
55
|
describe 'id lock' do
|
56
56
|
let(:my_subject) { MySubject.new }
|
@@ -59,8 +59,8 @@ module MongoidAbility
|
|
59
59
|
let(:lock_2) { MyLock.new(subject_type: other_subject.model_name, subject_id: other_subject.id, action: :read, outcome: false) }
|
60
60
|
let(:owner) { MyOwner.new(my_locks: [lock_1, lock_2]) }
|
61
61
|
|
62
|
-
it { FindLock.call(owner, :read, MySubject).must_equal MySubject.default_locks.for_action(:read).first }
|
63
|
-
it { FindLock.call(owner, :read, my_subject.class, my_subject.id).must_equal lock_1 }
|
62
|
+
it { _(FindLock.call(owner, :read, MySubject)).must_equal MySubject.default_locks.for_action(:read).first }
|
63
|
+
it { _(FindLock.call(owner, :read, my_subject.class, my_subject.id)).must_equal lock_1 }
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -7,51 +7,43 @@ module MongoidAbility
|
|
7
7
|
let(:my_subject) { MySubject.new }
|
8
8
|
let(:inherited_lock) { MyLock1.new }
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
it { subject.must_respond_to :
|
13
|
-
it { subject.must_respond_to :
|
14
|
-
it { subject.must_respond_to :
|
15
|
-
it { subject.must_respond_to :
|
16
|
-
it { subject.must_respond_to :subject_type }
|
17
|
-
it { subject.must_respond_to :owner }
|
18
|
-
|
19
|
-
# ---------------------------------------------------------------------
|
10
|
+
it { _(subject).must_respond_to :action }
|
11
|
+
it { _(subject).must_respond_to :outcome }
|
12
|
+
it { _(subject).must_respond_to :subject }
|
13
|
+
it { _(subject).must_respond_to :subject_id }
|
14
|
+
it { _(subject).must_respond_to :subject_type }
|
15
|
+
it { _(subject).must_respond_to :owner }
|
20
16
|
|
21
17
|
it '#open?' do
|
22
|
-
subject.must_respond_to :open?
|
23
|
-
subject.open
|
18
|
+
_(subject).must_respond_to :open?
|
19
|
+
_(subject.open?).must_equal false
|
24
20
|
end
|
25
21
|
|
26
22
|
it '#closed?' do
|
27
|
-
subject.must_respond_to :closed?
|
28
|
-
subject.closed
|
23
|
+
_(subject).must_respond_to :closed?
|
24
|
+
_(subject.closed?).must_equal true
|
29
25
|
end
|
30
26
|
|
31
27
|
it '#class_lock?' do
|
32
|
-
subject.must_respond_to :class_lock?
|
28
|
+
_(subject).must_respond_to :class_lock?
|
33
29
|
end
|
34
30
|
|
35
31
|
it '#id_lock?' do
|
36
|
-
subject.must_respond_to :id_lock?
|
32
|
+
_(subject).must_respond_to :id_lock?
|
37
33
|
end
|
38
34
|
|
39
|
-
# ---------------------------------------------------------------------
|
40
|
-
|
41
35
|
describe '.subject_id' do
|
42
36
|
it 'converts legal id String to BSON' do
|
43
37
|
id = BSON::ObjectId.new
|
44
|
-
MyLock.for_subject_id(id.to_s).selector['subject_id'].must_be_kind_of BSON::ObjectId
|
38
|
+
_(MyLock.for_subject_id(id.to_s).selector['subject_id']).must_be_kind_of BSON::ObjectId
|
45
39
|
end
|
46
40
|
|
47
41
|
it 'converts empty String to nil' do
|
48
42
|
id = ''
|
49
|
-
MyLock.for_subject_id(id.to_s).selector['subject_id'].must_be_nil
|
43
|
+
_(MyLock.for_subject_id(id.to_s).selector['subject_id']).must_be_nil
|
50
44
|
end
|
51
45
|
end
|
52
46
|
|
53
|
-
# ---------------------------------------------------------------------
|
54
|
-
|
55
47
|
describe 'sort' do
|
56
48
|
let(:lock0) { MyLock.new(subject_type: MySubject, action: :update, outcome: false) }
|
57
49
|
let(:lock1) { MyLock.new(subject_type: MySubject, action: :update, outcome: true) }
|
@@ -63,12 +55,10 @@ module MongoidAbility
|
|
63
55
|
|
64
56
|
let(:sorted_locks) { owner.my_locks.sort(&Lock.sort) }
|
65
57
|
|
66
|
-
it { sorted_locks[0].must_equal lock4 }
|
67
|
-
it { sorted_locks[3].must_equal lock1 }
|
58
|
+
it { _(sorted_locks[0]).must_equal lock4 }
|
59
|
+
it { _(sorted_locks[3]).must_equal lock1 }
|
68
60
|
end
|
69
61
|
|
70
|
-
# ---------------------------------------------------------------------
|
71
|
-
|
72
62
|
describe '#inherited_outcome' do
|
73
63
|
before(:all) { MySubject.default_lock MyLock, :read, true }
|
74
64
|
|
@@ -83,11 +73,11 @@ module MongoidAbility
|
|
83
73
|
let(:subject_lock) { owner.my_locks.detect(&:id_lock?) }
|
84
74
|
let(:default_lock) { MySubject.default_locks.detect { |l| l.action == :read } }
|
85
75
|
|
86
|
-
it { ability.can?(:read, my_subject).must_equal true }
|
76
|
+
it { _(ability.can?(:read, my_subject)).must_equal true }
|
87
77
|
|
88
|
-
it { subject_lock.inherited_outcome.must_equal false }
|
89
|
-
it { subject_type_lock.inherited_outcome.must_equal true }
|
90
|
-
it { default_lock.inherited_outcome.must_equal true }
|
78
|
+
it { _(subject_lock.inherited_outcome).must_equal false }
|
79
|
+
it { _(subject_type_lock.inherited_outcome).must_equal true }
|
80
|
+
it { _(default_lock.inherited_outcome).must_equal true }
|
91
81
|
end
|
92
82
|
end
|
93
83
|
end
|
@@ -13,8 +13,8 @@ module MongoidAbility
|
|
13
13
|
|
14
14
|
before(:all) { MySubject.default_lock MyLock, :read, true }
|
15
15
|
|
16
|
-
it { ability.can?(:read, subject.class).must_equal true }
|
17
|
-
it { ability.can?(:read, subject).must_equal false }
|
16
|
+
it { _(ability.can?(:read, subject.class)).must_equal true }
|
17
|
+
it { _(ability.can?(:read, subject)).must_equal false }
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'when lock for subject type' do
|
@@ -23,8 +23,8 @@ module MongoidAbility
|
|
23
23
|
|
24
24
|
before(:all) { MySubject.default_lock MyLock, :read, true }
|
25
25
|
|
26
|
-
it { ability.can?(:read, subject.class).must_equal false }
|
27
|
-
it { ability.can?(:read, subject).must_equal false }
|
26
|
+
it { _(ability.can?(:read, subject.class)).must_equal false }
|
27
|
+
it { _(ability.can?(:read, subject)).must_equal false }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -13,11 +13,11 @@ module MongoidAbility
|
|
13
13
|
subject.run_callbacks(:save)
|
14
14
|
end
|
15
15
|
|
16
|
-
it { subject.my_locks.sort(&Lock.sort).must_equal [closed_lock].sort(&Lock.sort) }
|
16
|
+
it { _(subject.my_locks.sort(&Lock.sort)).must_equal [closed_lock].sort(&Lock.sort) }
|
17
17
|
|
18
18
|
describe 'locks relation' do
|
19
|
-
it { subject.class.locks_relation_name.must_equal :my_locks }
|
20
|
-
it { subject.reflect_on_association(:my_locks).name.must_equal :my_locks }
|
19
|
+
it { _(subject.class.locks_relation_name).must_equal :my_locks }
|
20
|
+
it { _(subject.reflect_on_association(:my_locks).name).must_equal :my_locks }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -27,9 +27,9 @@ module MongoidAbility
|
|
27
27
|
let(:other_lock) { MyLock.new(action: :update, subject: MySubject.new) }
|
28
28
|
let(:owner) { MyOwner.new(my_locks: [subject_type_lock, subject_lock]) }
|
29
29
|
|
30
|
-
it { owner.has_lock?(subject_type_lock).must_equal true }
|
31
|
-
it { owner.has_lock?(subject_lock).must_equal true }
|
32
|
-
it { owner.has_lock?(other_lock).must_equal false }
|
30
|
+
it { _(owner.has_lock?(subject_type_lock)).must_equal true }
|
31
|
+
it { _(owner.has_lock?(subject_lock)).must_equal true }
|
32
|
+
it { _(owner.has_lock?(other_lock)).must_equal false }
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -9,8 +9,8 @@ module MongoidAbility
|
|
9
9
|
MySubject1.default_lock MyLock1, :update, false
|
10
10
|
end
|
11
11
|
|
12
|
-
it { MySubject.default_locks.map(&:action).map(&:to_s).sort.must_equal %w(read update) }
|
13
|
-
it { MySubject1.default_locks.map(&:action).map(&:to_s).sort.must_equal %w(update) }
|
12
|
+
it { _(MySubject.default_locks.map(&:action).map(&:to_s).sort).must_equal %w(read update) }
|
13
|
+
it { _(MySubject1.default_locks.map(&:action).map(&:to_s).sort).must_equal %w(update) }
|
14
14
|
end
|
15
15
|
|
16
16
|
describe 'prevents conflicts' do
|
@@ -20,7 +20,7 @@ module MongoidAbility
|
|
20
20
|
MySubject1.default_lock MyLock, :read, true
|
21
21
|
end
|
22
22
|
|
23
|
-
it { MySubject.default_locks.count { |l| l.action == :read }.must_equal 1 }
|
23
|
+
it { _(MySubject.default_locks.count { |l| l.action == :read }).must_equal 1 }
|
24
24
|
end
|
25
25
|
|
26
26
|
describe 'replace existing locks with new attributes' do
|
@@ -29,7 +29,7 @@ module MongoidAbility
|
|
29
29
|
MySubject1.default_lock MyLock, :read, true
|
30
30
|
end
|
31
31
|
|
32
|
-
it { MySubject.default_locks.detect { |l| l.action == :read }.outcome.must_equal false }
|
32
|
+
it { _(MySubject.default_locks.detect { |l| l.action == :read }.outcome).must_equal false }
|
33
33
|
end
|
34
34
|
|
35
35
|
describe 'replaces existing locks with new one' do
|
@@ -38,7 +38,7 @@ module MongoidAbility
|
|
38
38
|
MySubject1.default_lock MyLock, :read, true
|
39
39
|
end
|
40
40
|
|
41
|
-
it { MySubject.default_locks.detect { |l| l.action == :read }.class.must_equal MyLock1 }
|
41
|
+
it { _(MySubject.default_locks.detect { |l| l.action == :read }.class).must_equal MyLock1 }
|
42
42
|
end
|
43
43
|
|
44
44
|
describe 'replaces superclass locks' do
|
@@ -47,21 +47,21 @@ module MongoidAbility
|
|
47
47
|
MySubject1.default_lock MyLock, :read, true
|
48
48
|
end
|
49
49
|
|
50
|
-
it { MySubject1.default_locks.count.must_equal 1 }
|
51
|
-
it { MySubject1.default_locks.detect { |l| l.action == :read }.outcome.must_equal true }
|
50
|
+
it { _(MySubject1.default_locks.count).must_equal 1 }
|
51
|
+
it { _(MySubject1.default_locks.detect { |l| l.action == :read }.outcome).must_equal true }
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
describe '.is_root_class?' do
|
56
|
-
it { MySubject.is_root_class
|
57
|
-
it { MySubject1.is_root_class
|
58
|
-
it { MySubject2.is_root_class
|
56
|
+
it { _(MySubject.is_root_class?).must_equal true }
|
57
|
+
it { _(MySubject1.is_root_class?).must_equal false }
|
58
|
+
it { _(MySubject2.is_root_class?).must_equal false }
|
59
59
|
end
|
60
60
|
|
61
61
|
describe '.root_class' do
|
62
|
-
it { MySubject.root_class.must_equal MySubject }
|
63
|
-
it { MySubject1.root_class.must_equal MySubject }
|
64
|
-
it { MySubject2.root_class.must_equal MySubject }
|
62
|
+
it { _(MySubject.root_class).must_equal MySubject }
|
63
|
+
it { _(MySubject1.root_class).must_equal MySubject }
|
64
|
+
it { _(MySubject2.root_class).must_equal MySubject }
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
-
require 'database_cleaner'
|
2
|
+
require 'database_cleaner/mongoid'
|
3
3
|
require 'minitest'
|
4
4
|
require 'minitest/autorun'
|
5
5
|
require 'minitest/spec'
|
@@ -9,10 +9,10 @@ require 'mongoid_ability'
|
|
9
9
|
|
10
10
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
11
|
|
12
|
-
if ENV['CI']
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
# if ENV['CI']
|
13
|
+
# require 'coveralls'
|
14
|
+
# Coveralls.wear!
|
15
|
+
# end
|
16
16
|
|
17
17
|
Mongoid.logger.level = Logger::INFO
|
18
18
|
Mongo::Logger.logger.level = Logger::INFO
|
@@ -21,16 +21,13 @@ Mongoid.configure do |config|
|
|
21
21
|
config.connect_to('mongoid_ability_test')
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
DatabaseCleaner.strategy = :truncation
|
26
|
-
|
27
|
-
class MiniTest::Spec
|
24
|
+
class Minitest::Spec
|
28
25
|
before(:each) do
|
29
26
|
DatabaseCleaner.start
|
30
27
|
end
|
31
28
|
|
32
29
|
after(:each) do
|
33
|
-
[ MySubject,
|
30
|
+
[ MySubject,
|
34
31
|
MySubject1, MySubject2,
|
35
32
|
MySubject11, MySubject21
|
36
33
|
].each(&:reset_default_locks!)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_ability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cancancan
|
@@ -28,24 +28,18 @@ dependencies:
|
|
28
28
|
name: mongoid
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '7.0'
|
34
31
|
- - ">="
|
35
32
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
33
|
+
version: '0'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '7.0'
|
44
38
|
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
40
|
+
version: '0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
42
|
+
name: appraisal
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
50
44
|
requirements:
|
51
45
|
- - ">="
|
@@ -59,7 +53,7 @@ dependencies:
|
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: '0'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
56
|
+
name: bundler
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
64
58
|
requirements:
|
65
59
|
- - ">="
|
@@ -73,19 +67,19 @@ dependencies:
|
|
73
67
|
- !ruby/object:Gem::Version
|
74
68
|
version: '0'
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
|
-
name: database_cleaner
|
70
|
+
name: database_cleaner-mongoid
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
78
72
|
requirements:
|
79
73
|
- - ">="
|
80
74
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
75
|
+
version: '0'
|
82
76
|
type: :development
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
80
|
- - ">="
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
82
|
+
version: '0'
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: guard
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,16 +126,16 @@ dependencies:
|
|
132
126
|
name: rake
|
133
127
|
requirement: !ruby/object:Gem::Requirement
|
134
128
|
requirements:
|
135
|
-
- - "
|
129
|
+
- - ">="
|
136
130
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
131
|
+
version: '0'
|
138
132
|
type: :development
|
139
133
|
prerelease: false
|
140
134
|
version_requirements: !ruby/object:Gem::Requirement
|
141
135
|
requirements:
|
142
|
-
- - "
|
136
|
+
- - ">="
|
143
137
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
138
|
+
version: '0'
|
145
139
|
description: Custom Ability class that allows CanCanCan authorization library store
|
146
140
|
permissions in MongoDB via the Mongoid gem.
|
147
141
|
email:
|
@@ -151,14 +145,24 @@ extensions: []
|
|
151
145
|
extra_rdoc_files: []
|
152
146
|
files:
|
153
147
|
- ".coveralls.yml"
|
148
|
+
- ".github/workflows/test.yml"
|
154
149
|
- ".gitignore"
|
155
150
|
- ".travis.yml"
|
151
|
+
- Appraisals
|
156
152
|
- CHANGELOG.md
|
157
153
|
- Gemfile
|
158
154
|
- Guardfile
|
159
155
|
- LICENSE.txt
|
160
156
|
- README.md
|
161
157
|
- Rakefile
|
158
|
+
- gemfiles/7_0.gemfile
|
159
|
+
- gemfiles/7_1.gemfile
|
160
|
+
- gemfiles/7_2.gemfile
|
161
|
+
- gemfiles/7_3.gemfile
|
162
|
+
- gemfiles/7_4.gemfile
|
163
|
+
- gemfiles/7_5.gemfile
|
164
|
+
- gemfiles/8_0.gemfile
|
165
|
+
- gemfiles/8_1.gemfile
|
162
166
|
- lib/cancancan/model_adapters/mongoid_adapter.rb
|
163
167
|
- lib/cancancan/model_additions.rb
|
164
168
|
- lib/mongoid_ability.rb
|
@@ -183,6 +187,7 @@ files:
|
|
183
187
|
- test/mongoid_ability/owner_test.rb
|
184
188
|
- test/mongoid_ability/subject_test.rb
|
185
189
|
- test/support/expectations.rb
|
190
|
+
- test/support/test_classes/my_flat_subject.rb
|
186
191
|
- test/support/test_classes/my_lock.rb
|
187
192
|
- test/support/test_classes/my_owner.rb
|
188
193
|
- test/support/test_classes/my_role.rb
|
@@ -192,7 +197,7 @@ homepage: https://github.com/tomasc/mongoid_ability
|
|
192
197
|
licenses:
|
193
198
|
- MIT
|
194
199
|
metadata: {}
|
195
|
-
post_install_message:
|
200
|
+
post_install_message:
|
196
201
|
rdoc_options: []
|
197
202
|
require_paths:
|
198
203
|
- lib
|
@@ -207,9 +212,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
212
|
- !ruby/object:Gem::Version
|
208
213
|
version: '0'
|
209
214
|
requirements: []
|
210
|
-
|
211
|
-
|
212
|
-
signing_key:
|
215
|
+
rubygems_version: 3.4.6
|
216
|
+
signing_key:
|
213
217
|
specification_version: 4
|
214
218
|
summary: Custom Ability class that allows CanCanCan authorization library store permissions
|
215
219
|
in MongoDB via the Mongoid gem.
|
@@ -227,6 +231,7 @@ test_files:
|
|
227
231
|
- test/mongoid_ability/owner_test.rb
|
228
232
|
- test/mongoid_ability/subject_test.rb
|
229
233
|
- test/support/expectations.rb
|
234
|
+
- test/support/test_classes/my_flat_subject.rb
|
230
235
|
- test/support/test_classes/my_lock.rb
|
231
236
|
- test/support/test_classes/my_owner.rb
|
232
237
|
- test/support/test_classes/my_role.rb
|