cancancan 1.8.0 → 1.9.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 +4 -4
- data/.travis.yml +15 -0
- data/Appraisals +28 -1
- data/CHANGELOG.rdoc +29 -0
- data/README.rdoc +3 -3
- data/cancancan.gemspec +1 -1
- data/gemfiles/activerecord_4.0.gemfile +17 -0
- data/gemfiles/activerecord_4.1.gemfile +17 -0
- data/gemfiles/sequel_3.x.gemfile +0 -1
- data/lib/cancan/ability.rb +1 -1
- data/lib/cancan/controller_additions.rb +1 -1
- data/lib/cancan/controller_resource.rb +14 -7
- data/lib/cancan/matchers.rb +9 -3
- data/lib/cancan/model_adapters/active_record_3_adapter.rb +47 -0
- data/lib/cancan/model_adapters/active_record_4_adapter.rb +21 -0
- data/lib/cancan/model_adapters/active_record_adapter.rb +8 -40
- data/lib/cancan/version.rb +1 -1
- data/lib/cancan.rb +11 -1
- data/lib/generators/cancan/ability/templates/ability.rb +1 -1
- data/spec/cancan/ability_spec.rb +117 -111
- data/spec/cancan/controller_additions_spec.rb +8 -8
- data/spec/cancan/controller_resource_spec.rb +65 -54
- data/spec/cancan/model_adapters/active_record_adapter_spec.rb +67 -37
- data/spec/cancan/model_adapters/mongoid_adapter_spec.rb +6 -6
- data/spec/cancan/model_adapters/sequel_adapter_spec.rb +49 -65
- data/spec/matchers.rb +2 -2
- data/spec/spec_helper.rb +3 -2
- metadata +11 -5
data/spec/cancan/ability_spec.rb
CHANGED
|
@@ -7,12 +7,12 @@ describe CanCan::Ability do
|
|
|
7
7
|
|
|
8
8
|
it "is able to :read anything" do
|
|
9
9
|
@ability.can :read, :all
|
|
10
|
-
expect(@ability.can?(:read, String)).to
|
|
11
|
-
expect(@ability.can?(:read, 123)).to
|
|
10
|
+
expect(@ability.can?(:read, String)).to be(true)
|
|
11
|
+
expect(@ability.can?(:read, 123)).to be(true)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it "does not have permission to do something it doesn't know about" do
|
|
15
|
-
expect(@ability.can?(:foodfight, String)).to
|
|
15
|
+
expect(@ability.can?(:foodfight, String)).to be(false)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "passes true to `can?` when non false/nil is returned in block" do
|
|
@@ -20,7 +20,7 @@ describe CanCan::Ability do
|
|
|
20
20
|
@ability.can :read, Symbol do |sym|
|
|
21
21
|
"foo" # TODO test that sym is nil when no instance is passed
|
|
22
22
|
end
|
|
23
|
-
expect(@ability.can?(:read, :some_symbol)).to
|
|
23
|
+
expect(@ability.can?(:read, :some_symbol)).to be(true)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "passes nil to a block when no instance is passed" do
|
|
@@ -28,7 +28,7 @@ describe CanCan::Ability do
|
|
|
28
28
|
expect(sym).to be_nil
|
|
29
29
|
true
|
|
30
30
|
end
|
|
31
|
-
expect(@ability.can?(:read, Symbol)).to
|
|
31
|
+
expect(@ability.can?(:read, Symbol)).to be(true)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "passes to previous rule, if block returns false or nil" do
|
|
@@ -39,10 +39,10 @@ describe CanCan::Ability do
|
|
|
39
39
|
@ability.can :read, Integer do |i|
|
|
40
40
|
i > 10
|
|
41
41
|
end
|
|
42
|
-
expect(@ability.can?(:read, Symbol)).to
|
|
43
|
-
expect(@ability.can?(:read, 11)).to
|
|
44
|
-
expect(@ability.can?(:read, 1)).to
|
|
45
|
-
expect(@ability.can?(:read, 6)).to
|
|
42
|
+
expect(@ability.can?(:read, Symbol)).to be(true)
|
|
43
|
+
expect(@ability.can?(:read, 11)).to be(true)
|
|
44
|
+
expect(@ability.can?(:read, 1)).to be(true)
|
|
45
|
+
expect(@ability.can?(:read, 6)).to be(false)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "does not pass class with object if :all objects are accepted" do
|
|
@@ -51,7 +51,7 @@ describe CanCan::Ability do
|
|
|
51
51
|
@block_called = true
|
|
52
52
|
end
|
|
53
53
|
@ability.can?(:preview, 123)
|
|
54
|
-
expect(@block_called).to
|
|
54
|
+
expect(@block_called).to be(true)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "does not call block when only class is passed, only return true" do
|
|
@@ -59,8 +59,8 @@ describe CanCan::Ability do
|
|
|
59
59
|
@ability.can :preview, :all do |object|
|
|
60
60
|
@block_called = true
|
|
61
61
|
end
|
|
62
|
-
expect(@ability.can?(:preview, Hash)).to
|
|
63
|
-
expect(@block_called).to
|
|
62
|
+
expect(@ability.can?(:preview, Hash)).to be(true)
|
|
63
|
+
expect(@block_called).to be(false)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
it "passes only object for global manage actions" do
|
|
@@ -68,22 +68,22 @@ describe CanCan::Ability do
|
|
|
68
68
|
expect(object).to eq("foo")
|
|
69
69
|
@block_called = true
|
|
70
70
|
end
|
|
71
|
-
expect(@ability.can?(:stuff, "foo")).to
|
|
72
|
-
expect(@block_called).to
|
|
71
|
+
expect(@ability.can?(:stuff, "foo")).to be(true)
|
|
72
|
+
expect(@block_called).to be(true)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it "makes alias for update or destroy actions to modify action" do
|
|
76
76
|
@ability.alias_action :update, :destroy, :to => :modify
|
|
77
77
|
@ability.can :modify, :all
|
|
78
|
-
expect(@ability.can?(:update, 123)).to
|
|
79
|
-
expect(@ability.can?(:destroy, 123)).to
|
|
78
|
+
expect(@ability.can?(:update, 123)).to be(true)
|
|
79
|
+
expect(@ability.can?(:destroy, 123)).to be(true)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
it "allows deeply nested aliased actions" do
|
|
83
83
|
@ability.alias_action :increment, :to => :sort
|
|
84
84
|
@ability.alias_action :sort, :to => :modify
|
|
85
85
|
@ability.can :modify, :all
|
|
86
|
-
expect(@ability.can?(:increment, 123)).to
|
|
86
|
+
expect(@ability.can?(:increment, 123)).to be(true)
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
it "raises an Error if alias target is an exist action" do
|
|
@@ -98,7 +98,7 @@ describe CanCan::Ability do
|
|
|
98
98
|
@block_called = true
|
|
99
99
|
end
|
|
100
100
|
@ability.can?(:foo, 123)
|
|
101
|
-
expect(@block_called).to
|
|
101
|
+
expect(@block_called).to be(true)
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
it "passes nil to object when comparing class with can check" do
|
|
@@ -109,20 +109,20 @@ describe CanCan::Ability do
|
|
|
109
109
|
@block_called = true
|
|
110
110
|
end
|
|
111
111
|
@ability.can?(:foo, Hash)
|
|
112
|
-
expect(@block_called).to
|
|
112
|
+
expect(@block_called).to be(true)
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
it "automatically makes alias for index and show into read calls" do
|
|
116
116
|
@ability.can :read, :all
|
|
117
|
-
expect(@ability.can?(:index, 123)).to
|
|
118
|
-
expect(@ability.can?(:show, 123)).to
|
|
117
|
+
expect(@ability.can?(:index, 123)).to be(true)
|
|
118
|
+
expect(@ability.can?(:show, 123)).to be(true)
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
it "automatically makes alias for new and edit into create and update respectively" do
|
|
122
122
|
@ability.can :create, :all
|
|
123
123
|
@ability.can :update, :all
|
|
124
|
-
expect(@ability.can?(:new, 123)).to
|
|
125
|
-
expect(@ability.can?(:edit, 123)).to
|
|
124
|
+
expect(@ability.can?(:new, 123)).to be(true)
|
|
125
|
+
expect(@ability.can?(:edit, 123)).to be(true)
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
it "does not respond to prepare (now using initialize)" do
|
|
@@ -130,56 +130,56 @@ describe CanCan::Ability do
|
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
it "offers cannot? method which is simply invert of can?" do
|
|
133
|
-
expect(@ability.cannot?(:tie, String)).to
|
|
133
|
+
expect(@ability.cannot?(:tie, String)).to be(true)
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
it "is able to specify multiple actions and match any" do
|
|
137
137
|
@ability.can [:read, :update], :all
|
|
138
|
-
expect(@ability.can?(:read, 123)).to
|
|
139
|
-
expect(@ability.can?(:update, 123)).to
|
|
140
|
-
expect(@ability.can?(:count, 123)).to
|
|
138
|
+
expect(@ability.can?(:read, 123)).to be(true)
|
|
139
|
+
expect(@ability.can?(:update, 123)).to be(true)
|
|
140
|
+
expect(@ability.can?(:count, 123)).to be(false)
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
it "is able to specify multiple classes and match any" do
|
|
144
144
|
@ability.can :update, [String, Range]
|
|
145
|
-
expect(@ability.can?(:update, "foo")).to
|
|
146
|
-
expect(@ability.can?(:update, 1..3)).to
|
|
147
|
-
expect(@ability.can?(:update, 123)).to
|
|
145
|
+
expect(@ability.can?(:update, "foo")).to be(true)
|
|
146
|
+
expect(@ability.can?(:update, 1..3)).to be(true)
|
|
147
|
+
expect(@ability.can?(:update, 123)).to be(false)
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
it "checks if there is a permission for any of given subjects" do
|
|
151
151
|
@ability.can :update, [String, Range]
|
|
152
|
-
expect(@ability.can?(:update, {:any => ["foo", 1..3]})).to
|
|
153
|
-
expect(@ability.can?(:update, {:any => [1..3, "foo"]})).to
|
|
154
|
-
expect(@ability.can?(:update, {:any => [123, "foo"]})).to
|
|
155
|
-
expect(@ability.can?(:update, {:any => [123, 1.0]})).to
|
|
152
|
+
expect(@ability.can?(:update, {:any => ["foo", 1..3]})).to be(true)
|
|
153
|
+
expect(@ability.can?(:update, {:any => [1..3, "foo"]})).to be(true)
|
|
154
|
+
expect(@ability.can?(:update, {:any => [123, "foo"]})).to be(true)
|
|
155
|
+
expect(@ability.can?(:update, {:any => [123, 1.0]})).to be(false)
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
it "supports custom objects in the rule" do
|
|
159
159
|
@ability.can :read, :stats
|
|
160
|
-
expect(@ability.can?(:read, :stats)).to
|
|
161
|
-
expect(@ability.can?(:update, :stats)).to
|
|
162
|
-
expect(@ability.can?(:read, :nonstats)).to
|
|
163
|
-
expect(@ability.can?(:read, {:any => [:stats, :nonstats]})).to
|
|
164
|
-
expect(@ability.can?(:read, {:any => [:nonstats, :neitherstats]})).to
|
|
160
|
+
expect(@ability.can?(:read, :stats)).to be(true)
|
|
161
|
+
expect(@ability.can?(:update, :stats)).to be(false)
|
|
162
|
+
expect(@ability.can?(:read, :nonstats)).to be(false)
|
|
163
|
+
expect(@ability.can?(:read, {:any => [:stats, :nonstats]})).to be(true)
|
|
164
|
+
expect(@ability.can?(:read, {:any => [:nonstats, :neitherstats]})).to be(false)
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
it "checks ancestors of class" do
|
|
168
168
|
@ability.can :read, Numeric
|
|
169
|
-
expect(@ability.can?(:read, Integer)).to
|
|
170
|
-
expect(@ability.can?(:read, 1.23)).to
|
|
171
|
-
expect(@ability.can?(:read, "foo")).to
|
|
172
|
-
expect(@ability.can?(:read, {:any => [Integer, String]})).to
|
|
169
|
+
expect(@ability.can?(:read, Integer)).to be(true)
|
|
170
|
+
expect(@ability.can?(:read, 1.23)).to be(true)
|
|
171
|
+
expect(@ability.can?(:read, "foo")).to be(false)
|
|
172
|
+
expect(@ability.can?(:read, {:any => [Integer, String]})).to be(true)
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
it "supports 'cannot' method to define what user cannot do" do
|
|
176
176
|
@ability.can :read, :all
|
|
177
177
|
@ability.cannot :read, Integer
|
|
178
|
-
expect(@ability.can?(:read, "foo")).to
|
|
179
|
-
expect(@ability.can?(:read, 123)).to
|
|
180
|
-
expect(@ability.can?(:read, {:any => ["foo", "bar"]})).to
|
|
181
|
-
expect(@ability.can?(:read, {:any => [123, "foo"]})).to
|
|
182
|
-
expect(@ability.can?(:read, {:any => [123, 456]})).to
|
|
178
|
+
expect(@ability.can?(:read, "foo")).to be(true)
|
|
179
|
+
expect(@ability.can?(:read, 123)).to be(false)
|
|
180
|
+
expect(@ability.can?(:read, {:any => ["foo", "bar"]})).to be(true)
|
|
181
|
+
expect(@ability.can?(:read, {:any => [123, "foo"]})).to be(false)
|
|
182
|
+
expect(@ability.can?(:read, {:any => [123, 456]})).to be(false)
|
|
183
183
|
end
|
|
184
184
|
|
|
185
185
|
it "passes to previous rule, if block returns false or nil" do
|
|
@@ -187,22 +187,23 @@ describe CanCan::Ability do
|
|
|
187
187
|
@ability.cannot :read, Integer do |int|
|
|
188
188
|
int > 10 ? nil : ( int > 5 )
|
|
189
189
|
end
|
|
190
|
-
|
|
191
|
-
expect(@ability.can?(:read,
|
|
192
|
-
expect(@ability.can?(:read,
|
|
193
|
-
expect(@ability.can?(:read,
|
|
194
|
-
expect(@ability.can?(:read,
|
|
195
|
-
expect(@ability.can?(:read, {:any => [
|
|
190
|
+
|
|
191
|
+
expect(@ability.can?(:read, "foo")).to be(true)
|
|
192
|
+
expect(@ability.can?(:read, 3)).to be(true)
|
|
193
|
+
expect(@ability.can?(:read, 8)).to be(false)
|
|
194
|
+
expect(@ability.can?(:read, 123)).to be(true)
|
|
195
|
+
expect(@ability.can?(:read, {:any => [123, 8]})).to be(true)
|
|
196
|
+
expect(@ability.can?(:read, {:any => [8, 9]})).to be(false)
|
|
196
197
|
end
|
|
197
198
|
|
|
198
199
|
it "always returns `false` for single cannot definition" do
|
|
199
200
|
@ability.cannot :read, Integer do |int|
|
|
200
201
|
int > 10 ? nil : ( int > 5 )
|
|
201
202
|
end
|
|
202
|
-
expect(@ability.can?(:read, "foo")).to
|
|
203
|
-
expect(@ability.can?(:read, 3)).to
|
|
204
|
-
expect(@ability.can?(:read, 8)).to
|
|
205
|
-
expect(@ability.can?(:read, 123)).to
|
|
203
|
+
expect(@ability.can?(:read, "foo")).to be(false)
|
|
204
|
+
expect(@ability.can?(:read, 3)).to be(false)
|
|
205
|
+
expect(@ability.can?(:read, 8)).to be(false)
|
|
206
|
+
expect(@ability.can?(:read, 123)).to be(false)
|
|
206
207
|
end
|
|
207
208
|
|
|
208
209
|
it "passes to previous cannot definition, if block returns false or nil" do
|
|
@@ -210,10 +211,10 @@ describe CanCan::Ability do
|
|
|
210
211
|
@ability.can :read, Integer do |int|
|
|
211
212
|
int > 10 ? nil : ( int > 5 )
|
|
212
213
|
end
|
|
213
|
-
expect(@ability.can?(:read, "foo")).to
|
|
214
|
-
expect(@ability.can?(:read, 3)).to
|
|
215
|
-
expect(@ability.can?(:read, 10)).to
|
|
216
|
-
expect(@ability.can?(:read, 123)).to
|
|
214
|
+
expect(@ability.can?(:read, "foo")).to be(false)
|
|
215
|
+
expect(@ability.can?(:read, 3)).to be(false)
|
|
216
|
+
expect(@ability.can?(:read, 10)).to be(true)
|
|
217
|
+
expect(@ability.can?(:read, 123)).to be(false)
|
|
217
218
|
end
|
|
218
219
|
|
|
219
220
|
it "appends aliased actions" do
|
|
@@ -232,91 +233,94 @@ describe CanCan::Ability do
|
|
|
232
233
|
@ability.can :read, Integer do |int, x|
|
|
233
234
|
int > x
|
|
234
235
|
end
|
|
235
|
-
|
|
236
|
-
expect(@ability.can?(:read, 2,
|
|
237
|
-
expect(@ability.can?(:read,
|
|
238
|
-
expect(@ability.can?(:read, {:any => [
|
|
236
|
+
|
|
237
|
+
expect(@ability.can?(:read, 2, 1)).to be(true)
|
|
238
|
+
expect(@ability.can?(:read, 2, 3)).to be(false)
|
|
239
|
+
expect(@ability.can?(:read, {:any => [4, 5]}, 3)).to be(true)
|
|
240
|
+
expect(@ability.can?(:read, {:any => [2, 3]}, 3)).to be(false)
|
|
239
241
|
end
|
|
240
242
|
|
|
241
243
|
it "uses conditions as third parameter and determine abilities from it" do
|
|
242
244
|
@ability.can :read, Range, :begin => 1, :end => 3
|
|
243
|
-
|
|
244
|
-
expect(@ability.can?(:read, 1..
|
|
245
|
-
expect(@ability.can?(:read,
|
|
246
|
-
expect(@ability.can?(:read,
|
|
247
|
-
expect(@ability.can?(:read, {:any => [1..
|
|
245
|
+
|
|
246
|
+
expect(@ability.can?(:read, 1..3)).to be(true)
|
|
247
|
+
expect(@ability.can?(:read, 1..4)).to be(false)
|
|
248
|
+
expect(@ability.can?(:read, Range)).to be(true)
|
|
249
|
+
expect(@ability.can?(:read, {:any => [1..3, 1..4]})).to be(true)
|
|
250
|
+
expect(@ability.can?(:read, {:any => [1..4, 2..4]})).to be(false)
|
|
248
251
|
end
|
|
249
252
|
|
|
250
253
|
it "allows an array of options in conditions hash" do
|
|
251
254
|
@ability.can :read, Range, :begin => [1, 3, 5]
|
|
252
|
-
|
|
253
|
-
expect(@ability.can?(:read,
|
|
254
|
-
expect(@ability.can?(:read,
|
|
255
|
-
expect(@ability.can?(:read,
|
|
256
|
-
expect(@ability.can?(:read, {:any => [2..4,
|
|
255
|
+
|
|
256
|
+
expect(@ability.can?(:read, 1..3)).to be(true)
|
|
257
|
+
expect(@ability.can?(:read, 2..4)).to be(false)
|
|
258
|
+
expect(@ability.can?(:read, 3..5)).to be(true)
|
|
259
|
+
expect(@ability.can?(:read, {:any => [2..4, 3..5]})).to be(true)
|
|
260
|
+
expect(@ability.can?(:read, {:any => [2..4, 2..5]})).to be(false)
|
|
257
261
|
end
|
|
258
262
|
|
|
259
263
|
it "allows a range of options in conditions hash" do
|
|
260
264
|
@ability.can :read, Range, :begin => 1..3
|
|
261
|
-
expect(@ability.can?(:read, 1..10)).to
|
|
262
|
-
expect(@ability.can?(:read, 3..30)).to
|
|
263
|
-
expect(@ability.can?(:read, 4..40)).to
|
|
265
|
+
expect(@ability.can?(:read, 1..10)).to be(true)
|
|
266
|
+
expect(@ability.can?(:read, 3..30)).to be(true)
|
|
267
|
+
expect(@ability.can?(:read, 4..40)).to be(false)
|
|
264
268
|
end
|
|
265
269
|
|
|
266
270
|
it "allows nested hashes in conditions hash" do
|
|
267
271
|
@ability.can :read, Range, :begin => { :to_i => 5 }
|
|
268
|
-
expect(@ability.can?(:read, 5..7)).to
|
|
269
|
-
expect(@ability.can?(:read, 6..8)).to
|
|
272
|
+
expect(@ability.can?(:read, 5..7)).to be(true)
|
|
273
|
+
expect(@ability.can?(:read, 6..8)).to be(false)
|
|
270
274
|
end
|
|
271
275
|
|
|
272
276
|
it "matches any element passed in to nesting if it's an array (for has_many associations)" do
|
|
273
277
|
@ability.can :read, Range, :to_a => { :to_i => 3 }
|
|
274
|
-
expect(@ability.can?(:read, 1..5)).to
|
|
275
|
-
expect(@ability.can?(:read, 4..6)).to
|
|
278
|
+
expect(@ability.can?(:read, 1..5)).to be(true)
|
|
279
|
+
expect(@ability.can?(:read, 4..6)).to be(false)
|
|
276
280
|
end
|
|
277
281
|
|
|
278
282
|
it "accepts a set as a condition value" do
|
|
279
283
|
expect(object_with_foo_2 = double(:foo => 2)).to receive(:foo)
|
|
280
|
-
expect(object_with_foo_3 = double(:foo => 3)).to receive(:foo)
|
|
284
|
+
expect(object_with_foo_3 = double(:foo => 3)).to receive(:foo)
|
|
281
285
|
@ability.can :read, Object, :foo => [1, 2, 5].to_set
|
|
282
|
-
expect(@ability.can?(:read, object_with_foo_2)).to
|
|
283
|
-
expect(@ability.can?(:read, object_with_foo_3)).to
|
|
286
|
+
expect(@ability.can?(:read, object_with_foo_2)).to be(true)
|
|
287
|
+
expect(@ability.can?(:read, object_with_foo_3)).to be(false)
|
|
284
288
|
end
|
|
285
289
|
|
|
286
290
|
it "does not match subjects return nil for methods that must match nested a nested conditions hash" do
|
|
287
291
|
expect(object_with_foo = double(:foo => :bar)).to receive(:foo)
|
|
288
292
|
@ability.can :read, Array, :first => { :foo => :bar }
|
|
289
|
-
expect(@ability.can?(:read, [object_with_foo])).to
|
|
290
|
-
expect(@ability.can?(:read, [])).to
|
|
293
|
+
expect(@ability.can?(:read, [object_with_foo])).to be(true)
|
|
294
|
+
expect(@ability.can?(:read, [])).to be(false)
|
|
291
295
|
end
|
|
292
296
|
|
|
293
297
|
it "matches strings but not substrings specified in a conditions hash" do
|
|
294
298
|
@ability.can :read, String, :presence => "declassified"
|
|
295
|
-
expect(@ability.can?(:read, "declassified")).to
|
|
296
|
-
expect(@ability.can?(:read, "classified")).to
|
|
299
|
+
expect(@ability.can?(:read, "declassified")).to be(true)
|
|
300
|
+
expect(@ability.can?(:read, "classified")).to be(false)
|
|
297
301
|
end
|
|
298
302
|
|
|
299
303
|
it "does not stop at cannot definition when comparing class" do
|
|
300
304
|
@ability.can :read, Range
|
|
301
305
|
@ability.cannot :read, Range, :begin => 1
|
|
302
|
-
expect(@ability.can?(:read, 2..5)).to
|
|
303
|
-
expect(@ability.can?(:read, 1..5)).to
|
|
304
|
-
expect(@ability.can?(:read, Range)).to
|
|
306
|
+
expect(@ability.can?(:read, 2..5)).to be(true)
|
|
307
|
+
expect(@ability.can?(:read, 1..5)).to be(false)
|
|
308
|
+
expect(@ability.can?(:read, Range)).to be(true)
|
|
305
309
|
end
|
|
306
310
|
|
|
307
311
|
it "stops at cannot definition when no hash is present" do
|
|
308
312
|
@ability.can :read, :all
|
|
309
313
|
@ability.cannot :read, Range
|
|
310
|
-
expect(@ability.can?(:read, 1..5)).to
|
|
311
|
-
expect(@ability.can?(:read, Range)).to
|
|
314
|
+
expect(@ability.can?(:read, 1..5)).to be(false)
|
|
315
|
+
expect(@ability.can?(:read, Range)).to be(false)
|
|
312
316
|
end
|
|
313
317
|
|
|
314
318
|
it "allows to check ability for Module" do
|
|
315
319
|
module B; end
|
|
316
320
|
class A; include B; end
|
|
317
321
|
@ability.can :read, B
|
|
318
|
-
expect(@ability.can?(:read, A)).to
|
|
319
|
-
expect(@ability.can?(:read, A.new)).to
|
|
322
|
+
expect(@ability.can?(:read, A)).to be(true)
|
|
323
|
+
expect(@ability.can?(:read, A.new)).to be(true)
|
|
320
324
|
end
|
|
321
325
|
|
|
322
326
|
it "passes nil to a block for ability on Module when no instance is passed" do
|
|
@@ -326,33 +330,35 @@ describe CanCan::Ability do
|
|
|
326
330
|
expect(sym).to be_nil
|
|
327
331
|
true
|
|
328
332
|
end
|
|
329
|
-
expect(@ability.can?(:read, B)).to
|
|
330
|
-
expect(@ability.can?(:read, A)).to
|
|
333
|
+
expect(@ability.can?(:read, B)).to be(true)
|
|
334
|
+
expect(@ability.can?(:read, A)).to be(true)
|
|
331
335
|
end
|
|
332
336
|
|
|
333
337
|
it "checks permissions through association when passing a hash of subjects" do
|
|
334
338
|
@ability.can :read, Range, :string => {:length => 3}
|
|
335
|
-
|
|
336
|
-
expect(@ability.can?(:read, "
|
|
337
|
-
expect(@ability.can?(:read,
|
|
338
|
-
expect(@ability.can?(:read,
|
|
339
|
-
expect(@ability.can?(:read, {:any => [{"
|
|
339
|
+
|
|
340
|
+
expect(@ability.can?(:read, "foo" => Range)).to be(true)
|
|
341
|
+
expect(@ability.can?(:read, "foobar" => Range)).to be(false)
|
|
342
|
+
expect(@ability.can?(:read, 123 => Range)).to be(true)
|
|
343
|
+
expect(@ability.can?(:read, {:any => [{"foo" => Range}, {"foobar" => Range}]})).to be(true)
|
|
344
|
+
expect(@ability.can?(:read, {:any => [{"food" => Range}, {"foobar" => Range}]})).to be(false)
|
|
340
345
|
end
|
|
341
346
|
|
|
342
347
|
it "checks permissions correctly when passing a hash of subjects with multiple definitions" do
|
|
343
348
|
@ability.can :read, Range, :string => {:length => 4}
|
|
344
349
|
@ability.can [:create, :read], Range, :string => {:upcase => 'FOO'}
|
|
345
|
-
|
|
346
|
-
expect(@ability.can?(:read, "
|
|
347
|
-
expect(@ability.can?(:read,
|
|
348
|
-
expect(@ability.can?(:read,
|
|
349
|
-
expect(@ability.can?(:read, {:any => [{"foo
|
|
350
|
+
|
|
351
|
+
expect(@ability.can?(:read, "foo" => Range)).to be(true)
|
|
352
|
+
expect(@ability.can?(:read, "foobar" => Range)).to be(false)
|
|
353
|
+
expect(@ability.can?(:read, 1234 => Range)).to be(true)
|
|
354
|
+
expect(@ability.can?(:read, {:any => [{"foo" => Range}, {"foobar" => Range}]})).to be(true)
|
|
355
|
+
expect(@ability.can?(:read, {:any => [{"foo.bar" => Range}, {"foobar" => Range}]})).to be(false)
|
|
350
356
|
end
|
|
351
357
|
|
|
352
358
|
it "allows to check ability on Hash-like object" do
|
|
353
359
|
class Container < Hash; end
|
|
354
360
|
@ability.can :read, Container
|
|
355
|
-
expect(@ability.can?(:read, Container.new)).to
|
|
361
|
+
expect(@ability.can?(:read, Container.new)).to be(true)
|
|
356
362
|
end
|
|
357
363
|
|
|
358
364
|
it "has initial attributes based on hash conditions of 'new' action" do
|
|
@@ -474,7 +480,7 @@ describe CanCan::Ability do
|
|
|
474
480
|
another_ability.can :use, :search
|
|
475
481
|
|
|
476
482
|
@ability.merge(another_ability)
|
|
477
|
-
expect(@ability.can?(:use, :search)).to
|
|
483
|
+
expect(@ability.can?(:use, :search)).to be(true)
|
|
478
484
|
expect(@ability.send(:rules).size).to eq(2)
|
|
479
485
|
end
|
|
480
486
|
end
|
|
@@ -17,7 +17,7 @@ describe CanCan::ControllerAdditions do
|
|
|
17
17
|
it "authorize! assigns @_authorized instance variable and pass args to current ability" do
|
|
18
18
|
allow(@controller.current_ability).to receive(:authorize!).with(:foo, :bar)
|
|
19
19
|
@controller.authorize!(:foo, :bar)
|
|
20
|
-
expect(@controller.instance_variable_get(:@_authorized)).to
|
|
20
|
+
expect(@controller.instance_variable_get(:@_authorized)).to be(true)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "has a current_ability method which generates an ability for the current user" do
|
|
@@ -26,8 +26,8 @@ describe CanCan::ControllerAdditions do
|
|
|
26
26
|
|
|
27
27
|
it "provides a can? and cannot? methods which go through the current ability" do
|
|
28
28
|
expect(@controller.current_ability).to be_kind_of(Ability)
|
|
29
|
-
expect(@controller.can?(:foo, :bar)).to
|
|
30
|
-
expect(@controller.cannot?(:foo, :bar)).to
|
|
29
|
+
expect(@controller.can?(:foo, :bar)).to be(false)
|
|
30
|
+
expect(@controller.cannot?(:foo, :bar)).to be(true)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "load_and_authorize_resource setups a before filter which passes call to ControllerResource" do
|
|
@@ -38,7 +38,7 @@ describe CanCan::ControllerAdditions do
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "load_and_authorize_resource properly passes first argument as the resource name" do
|
|
41
|
-
expect(cancan_resource_class = double).to receive(:load_and_authorize_resource)
|
|
41
|
+
expect(cancan_resource_class = double).to receive(:load_and_authorize_resource)
|
|
42
42
|
allow(CanCan::ControllerResource).to receive(:new).with(@controller, :project, :foo => :bar) {cancan_resource_class}
|
|
43
43
|
expect(@controller_class).to receive(:before_filter).with({}) { |options, &block| block.call(@controller) }
|
|
44
44
|
@controller_class.load_and_authorize_resource :project, :foo => :bar
|
|
@@ -50,14 +50,14 @@ describe CanCan::ControllerAdditions do
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "authorize_resource setups a before filter which passes call to ControllerResource" do
|
|
53
|
-
expect(cancan_resource_class = double).to receive(:authorize_resource)
|
|
53
|
+
expect(cancan_resource_class = double).to receive(:authorize_resource)
|
|
54
54
|
allow(CanCan::ControllerResource).to receive(:new).with(@controller, nil, :foo => :bar) {cancan_resource_class}
|
|
55
55
|
expect(@controller_class).to receive(:before_filter).with(:except => :show, :if => true) { |options, &block| block.call(@controller) }
|
|
56
56
|
@controller_class.authorize_resource :foo => :bar, :except => :show, :if => true
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
it "load_resource setups a before filter which passes call to ControllerResource" do
|
|
60
|
-
expect(cancan_resource_class = double).to receive(:load_resource)
|
|
60
|
+
expect(cancan_resource_class = double).to receive(:load_resource)
|
|
61
61
|
allow(CanCan::ControllerResource).to receive(:new).with(@controller, nil, :foo => :bar) {cancan_resource_class}
|
|
62
62
|
expect(@controller_class).to receive(:before_filter).with(:only => [:show, :index], :unless => false) { |options, &block| block.call(@controller) }
|
|
63
63
|
@controller_class.load_resource :foo => :bar, :only => [:show, :index], :unless => false
|
|
@@ -66,7 +66,7 @@ describe CanCan::ControllerAdditions do
|
|
|
66
66
|
it "skip_authorization_check setups a before filter which sets @_authorized to true" do
|
|
67
67
|
expect(@controller_class).to receive(:before_filter).with(:filter_options) { |options, &block| block.call(@controller) }
|
|
68
68
|
@controller_class.skip_authorization_check(:filter_options)
|
|
69
|
-
expect(@controller.instance_variable_get(:@_authorized)).to
|
|
69
|
+
expect(@controller.instance_variable_get(:@_authorized)).to be(true)
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
it "check_authorization triggers AuthorizationNotPerformed in after filter" do
|
|
@@ -112,7 +112,7 @@ describe CanCan::ControllerAdditions do
|
|
|
112
112
|
it "cancan_skipper is an empty hash with :authorize and :load options and remember changes" do
|
|
113
113
|
expect(@controller_class.cancan_skipper).to eq({:authorize => {}, :load => {}})
|
|
114
114
|
@controller_class.cancan_skipper[:load] = true
|
|
115
|
-
expect(@controller_class.cancan_skipper[:load]).to
|
|
115
|
+
expect(@controller_class.cancan_skipper[:load]).to be(true)
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it "skip_authorize_resource adds itself to the cancan skipper with given model name and options" do
|