cancancan 1.8.2 → 1.8.3
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/CHANGELOG.rdoc +5 -0
- data/cancancan.gemspec +1 -1
- data/lib/cancan/matchers.rb +9 -3
- data/lib/cancan/version.rb +1 -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 +17 -17
- data/spec/cancan/model_adapters/active_record_adapter_spec.rb +29 -31
- data/spec/cancan/model_adapters/mongoid_adapter_spec.rb +6 -6
- data/spec/matchers.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b834aa0ca99b2b6ab4c5b731ab3f80163b4cf502
|
|
4
|
+
data.tar.gz: 0e52c52dca9331cd0f99d26f16b804c3669dd796
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 46d18d924b8eae0a1ef18b9991adc41e1a781a4885554a2a3badb3f60dc9dca8ced9ccec84d2c92150558fddb189e1c56664167fcca71316ffed92c25e13c02c
|
|
7
|
+
data.tar.gz: 8b4382876b82ed5c5826da510b6baebca02ef9c60da24dcdd6682e888e02bd44eb8990f45ca22381d5ddef91749a4f82b8753147be30ef2819aeda96b8def805
|
data/CHANGELOG.rdoc
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
Develop
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
1.8.3 (June 24th, 2014)
|
|
5
|
+
|
|
6
|
+
* Fix cancancan#85 - Remove deprecation notices for RSpec 3 and continue backwards compatibility. (andypike, bryanrite, porteta)
|
|
7
|
+
|
|
8
|
+
|
|
4
9
|
1.8.2 (June 5th, 2014)
|
|
5
10
|
|
|
6
11
|
* Fix cancancan#75 - More specific hash-like object check. (bryanrite)
|
data/cancancan.gemspec
CHANGED
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
|
24
24
|
|
|
25
25
|
s.add_development_dependency 'bundler', '~> 1.3'
|
|
26
26
|
s.add_development_dependency 'rake', '~> 10.1.1'
|
|
27
|
-
s.add_development_dependency 'rspec', '~>
|
|
27
|
+
s.add_development_dependency 'rspec', '~> 3.0.0'
|
|
28
28
|
s.add_development_dependency 'appraisal', '>= 1.0.0'
|
|
29
29
|
|
|
30
30
|
s.rubyforge_project = s.name
|
data/lib/cancan/matchers.rb
CHANGED
|
@@ -4,7 +4,7 @@ if rspec_module == 'RSpec'
|
|
|
4
4
|
require 'rspec/core'
|
|
5
5
|
require 'rspec/expectations'
|
|
6
6
|
else
|
|
7
|
-
ActiveSupport::Deprecation.warn("RSpec
|
|
7
|
+
ActiveSupport::Deprecation.warn("RSpec < 3 will not be supported in the CanCanCan >= 2.0.0")
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
Kernel.const_get(rspec_module)::Matchers.define :be_able_to do |*args|
|
|
@@ -12,11 +12,17 @@ Kernel.const_get(rspec_module)::Matchers.define :be_able_to do |*args|
|
|
|
12
12
|
ability.can?(*args)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
unless defined?(failure_message) # RSpec < 3
|
|
16
|
+
alias :failure_message :failure_message_for_should
|
|
17
|
+
alias :failure_message_when_negated :failure_message_for_should_not
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
failure_message do |ability|
|
|
16
21
|
"expected to be able to #{args.map(&:inspect).join(" ")}"
|
|
17
22
|
end
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
failure_message_when_negated do |ability|
|
|
20
25
|
"expected not to be able to #{args.map(&:inspect).join(" ")}"
|
|
21
26
|
end
|
|
27
|
+
|
|
22
28
|
end
|
data/lib/cancan/version.rb
CHANGED
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
|
|
@@ -194,7 +194,7 @@ describe CanCan::ControllerResource do
|
|
|
194
194
|
resource = CanCan::ControllerResource.new(controller)
|
|
195
195
|
resource.load_resource
|
|
196
196
|
expect(controller.instance_variable_get(:@model)).to be_nil
|
|
197
|
-
expect(controller.instance_variable_defined?(:@models)).to
|
|
197
|
+
expect(controller.instance_variable_defined?(:@models)).to be(false)
|
|
198
198
|
end
|
|
199
199
|
|
|
200
200
|
it "does not use accessible_by when defining abilities through a block" do
|
|
@@ -204,7 +204,7 @@ describe CanCan::ControllerResource do
|
|
|
204
204
|
resource = CanCan::ControllerResource.new(controller)
|
|
205
205
|
resource.load_resource
|
|
206
206
|
expect(controller.instance_variable_get(:@model)).to be_nil
|
|
207
|
-
expect(controller.instance_variable_defined?(:@models)).to
|
|
207
|
+
expect(controller.instance_variable_defined?(:@models)).to be(false)
|
|
208
208
|
end
|
|
209
209
|
|
|
210
210
|
it "does not authorize single resource in collection action" do
|
|
@@ -517,7 +517,7 @@ describe CanCan::ControllerResource do
|
|
|
517
517
|
it "only calls the santitize method with actions matching param_actions" do
|
|
518
518
|
allow(controller).to receive(:resource_params).and_return(:resource => 'params')
|
|
519
519
|
resource = CanCan::ControllerResource.new(controller)
|
|
520
|
-
resource.
|
|
520
|
+
allow(resource).to receive(:param_actions) { [:create] }
|
|
521
521
|
|
|
522
522
|
expect(controller).not_to receive(:send).with(:resource_params)
|
|
523
523
|
resource.send("resource_params")
|
|
@@ -579,41 +579,41 @@ describe CanCan::ControllerResource do
|
|
|
579
579
|
it "skips resource behavior for :only actions in array" do
|
|
580
580
|
allow(controller_class).to receive(:cancan_skipper) { {:load => {nil => {:only => [:index, :show]}}} }
|
|
581
581
|
params.merge!(:action => "index")
|
|
582
|
-
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to
|
|
583
|
-
expect(CanCan::ControllerResource.new(controller, :some_resource).skip?(:load)).to
|
|
582
|
+
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to be(true)
|
|
583
|
+
expect(CanCan::ControllerResource.new(controller, :some_resource).skip?(:load)).to be(false)
|
|
584
584
|
params.merge!(:action => "show")
|
|
585
|
-
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to
|
|
585
|
+
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to be(true)
|
|
586
586
|
params.merge!(:action => "other_action")
|
|
587
|
-
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to
|
|
587
|
+
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to be_falsey
|
|
588
588
|
end
|
|
589
589
|
|
|
590
590
|
it "skips resource behavior for :only one action on resource" do
|
|
591
591
|
allow(controller_class).to receive(:cancan_skipper) { {:authorize => {:model => {:only => :index}}} }
|
|
592
592
|
params.merge!(:action => "index")
|
|
593
|
-
expect(CanCan::ControllerResource.new(controller).skip?(:authorize)).to
|
|
594
|
-
expect(CanCan::ControllerResource.new(controller, :model).skip?(:authorize)).to
|
|
593
|
+
expect(CanCan::ControllerResource.new(controller).skip?(:authorize)).to be(false)
|
|
594
|
+
expect(CanCan::ControllerResource.new(controller, :model).skip?(:authorize)).to be(true)
|
|
595
595
|
params.merge!(:action => "other_action")
|
|
596
|
-
expect(CanCan::ControllerResource.new(controller, :model).skip?(:authorize)).to
|
|
596
|
+
expect(CanCan::ControllerResource.new(controller, :model).skip?(:authorize)).to be_falsey
|
|
597
597
|
end
|
|
598
598
|
|
|
599
599
|
it "skips resource behavior :except actions in array" do
|
|
600
600
|
allow(controller_class).to receive(:cancan_skipper) { {:load => {nil => {:except => [:index, :show]}}} }
|
|
601
601
|
params.merge!(:action => "index")
|
|
602
|
-
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to
|
|
602
|
+
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to be_falsey
|
|
603
603
|
params.merge!(:action => "show")
|
|
604
|
-
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to
|
|
604
|
+
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to be_falsey
|
|
605
605
|
params.merge!(:action => "other_action")
|
|
606
|
-
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to
|
|
607
|
-
expect(CanCan::ControllerResource.new(controller, :some_resource).skip?(:load)).to
|
|
606
|
+
expect(CanCan::ControllerResource.new(controller).skip?(:load)).to be(true)
|
|
607
|
+
expect(CanCan::ControllerResource.new(controller, :some_resource).skip?(:load)).to be(false)
|
|
608
608
|
end
|
|
609
609
|
|
|
610
610
|
it "skips resource behavior :except one action on resource" do
|
|
611
611
|
allow(controller_class).to receive(:cancan_skipper) { {:authorize => {:model => {:except => :index}}} }
|
|
612
612
|
params.merge!(:action => "index")
|
|
613
|
-
expect(CanCan::ControllerResource.new(controller, :model).skip?(:authorize)).to
|
|
613
|
+
expect(CanCan::ControllerResource.new(controller, :model).skip?(:authorize)).to be_falsey
|
|
614
614
|
params.merge!(:action => "other_action")
|
|
615
|
-
expect(CanCan::ControllerResource.new(controller).skip?(:authorize)).to
|
|
616
|
-
expect(CanCan::ControllerResource.new(controller, :model).skip?(:authorize)).to
|
|
615
|
+
expect(CanCan::ControllerResource.new(controller).skip?(:authorize)).to be(false)
|
|
616
|
+
expect(CanCan::ControllerResource.new(controller, :model).skip?(:authorize)).to be(true)
|
|
617
617
|
end
|
|
618
618
|
|
|
619
619
|
it "skips loading and authorization" do
|
|
@@ -311,7 +311,6 @@ if defined? CanCan::ModelAdapters::ActiveRecordAdapter
|
|
|
311
311
|
end
|
|
312
312
|
|
|
313
313
|
context "when MetaWhere is defined" do
|
|
314
|
-
|
|
315
314
|
before :each do
|
|
316
315
|
pending "[Deprecated] MetaWhere support is being removed" unless defined? MetaWhere
|
|
317
316
|
end
|
|
@@ -338,39 +337,38 @@ if defined? CanCan::ModelAdapters::ActiveRecordAdapter
|
|
|
338
337
|
end
|
|
339
338
|
|
|
340
339
|
it "matches any MetaWhere condition" do
|
|
341
|
-
|
|
342
340
|
adapter = CanCan::ModelAdapters::ActiveRecordAdapter
|
|
343
341
|
article1 = Article.new(:priority => 1, :name => "Hello World")
|
|
344
|
-
expect(adapter.matches_condition?(article1, :priority.eq, 1)).to
|
|
345
|
-
expect(adapter.matches_condition?(article1, :priority.eq, 2)).to
|
|
346
|
-
expect(adapter.matches_condition?(article1, :priority.eq_any, [1, 2])).to
|
|
347
|
-
expect(adapter.matches_condition?(article1, :priority.eq_any, [2, 3])).to
|
|
348
|
-
expect(adapter.matches_condition?(article1, :priority.eq_all, [1, 1])).to
|
|
349
|
-
expect(adapter.matches_condition?(article1, :priority.eq_all, [1, 2])).to
|
|
350
|
-
expect(adapter.matches_condition?(article1, :priority.ne, 2)).to
|
|
351
|
-
expect(adapter.matches_condition?(article1, :priority.ne, 1)).to
|
|
352
|
-
expect(adapter.matches_condition?(article1, :priority.in, [1, 2])).to
|
|
353
|
-
expect(adapter.matches_condition?(article1, :priority.in, [2, 3])).to
|
|
354
|
-
expect(adapter.matches_condition?(article1, :priority.nin, [2, 3])).to
|
|
355
|
-
expect(adapter.matches_condition?(article1, :priority.nin, [1, 2])).to
|
|
356
|
-
expect(adapter.matches_condition?(article1, :priority.lt, 2)).to
|
|
357
|
-
expect(adapter.matches_condition?(article1, :priority.lt, 1)).to
|
|
358
|
-
expect(adapter.matches_condition?(article1, :priority.lteq, 1)).to
|
|
359
|
-
expect(adapter.matches_condition?(article1, :priority.lteq, 0)).to
|
|
360
|
-
expect(adapter.matches_condition?(article1, :priority.gt, 0)).to
|
|
361
|
-
expect(adapter.matches_condition?(article1, :priority.gt, 1)).to
|
|
362
|
-
expect(adapter.matches_condition?(article1, :priority.gteq, 1)).to
|
|
363
|
-
expect(adapter.matches_condition?(article1, :priority.gteq, 2)).to
|
|
364
|
-
expect(adapter.matches_condition?(article1, :name.like, "%ello worl%")).to
|
|
365
|
-
expect(adapter.matches_condition?(article1, :name.like, "hello world")).to
|
|
366
|
-
expect(adapter.matches_condition?(article1, :name.like, "hello%")).to
|
|
367
|
-
expect(adapter.matches_condition?(article1, :name.like, "h%d")).to
|
|
368
|
-
expect(adapter.matches_condition?(article1, :name.like, "%helo%")).to
|
|
369
|
-
expect(adapter.matches_condition?(article1, :name.like, "hello")).to
|
|
370
|
-
expect(adapter.matches_condition?(article1, :name.like, "hello.world")).to
|
|
342
|
+
expect(adapter.matches_condition?(article1, :priority.eq, 1)).to be(true)
|
|
343
|
+
expect(adapter.matches_condition?(article1, :priority.eq, 2)).to be(false)
|
|
344
|
+
expect(adapter.matches_condition?(article1, :priority.eq_any, [1, 2])).to be(true)
|
|
345
|
+
expect(adapter.matches_condition?(article1, :priority.eq_any, [2, 3])).to be(false)
|
|
346
|
+
expect(adapter.matches_condition?(article1, :priority.eq_all, [1, 1])).to be(true)
|
|
347
|
+
expect(adapter.matches_condition?(article1, :priority.eq_all, [1, 2])).to be(false)
|
|
348
|
+
expect(adapter.matches_condition?(article1, :priority.ne, 2)).to be(true)
|
|
349
|
+
expect(adapter.matches_condition?(article1, :priority.ne, 1)).to be(false)
|
|
350
|
+
expect(adapter.matches_condition?(article1, :priority.in, [1, 2])).to be(true)
|
|
351
|
+
expect(adapter.matches_condition?(article1, :priority.in, [2, 3])).to be(false)
|
|
352
|
+
expect(adapter.matches_condition?(article1, :priority.nin, [2, 3])).to be(true)
|
|
353
|
+
expect(adapter.matches_condition?(article1, :priority.nin, [1, 2])).to be(false)
|
|
354
|
+
expect(adapter.matches_condition?(article1, :priority.lt, 2)).to be(true)
|
|
355
|
+
expect(adapter.matches_condition?(article1, :priority.lt, 1)).to be(false)
|
|
356
|
+
expect(adapter.matches_condition?(article1, :priority.lteq, 1)).to be(true)
|
|
357
|
+
expect(adapter.matches_condition?(article1, :priority.lteq, 0)).to be(false)
|
|
358
|
+
expect(adapter.matches_condition?(article1, :priority.gt, 0)).to be(true)
|
|
359
|
+
expect(adapter.matches_condition?(article1, :priority.gt, 1)).to be(false)
|
|
360
|
+
expect(adapter.matches_condition?(article1, :priority.gteq, 1)).to be(true)
|
|
361
|
+
expect(adapter.matches_condition?(article1, :priority.gteq, 2)).to be(false)
|
|
362
|
+
expect(adapter.matches_condition?(article1, :name.like, "%ello worl%")).to be_truthy
|
|
363
|
+
expect(adapter.matches_condition?(article1, :name.like, "hello world")).to be_truthy
|
|
364
|
+
expect(adapter.matches_condition?(article1, :name.like, "hello%")).to be_truthy
|
|
365
|
+
expect(adapter.matches_condition?(article1, :name.like, "h%d")).to be_truthy
|
|
366
|
+
expect(adapter.matches_condition?(article1, :name.like, "%helo%")).to be_falsey
|
|
367
|
+
expect(adapter.matches_condition?(article1, :name.like, "hello")).to be_falsey
|
|
368
|
+
expect(adapter.matches_condition?(article1, :name.like, "hello.world")).to be_falsey
|
|
371
369
|
# For some reason this is reporting "The not_matches MetaWhere condition is not supported."
|
|
372
|
-
# expect(adapter.matches_condition?(article1, :name.nlike, "%helo%")).to
|
|
373
|
-
# expect(adapter.matches_condition?(article1, :name.nlike, "%ello worl%")).to
|
|
370
|
+
# expect(adapter.matches_condition?(article1, :name.nlike, "%helo%")).to be(true)
|
|
371
|
+
# expect(adapter.matches_condition?(article1, :name.nlike, "%ello worl%")).to be(false)
|
|
374
372
|
end
|
|
375
373
|
end
|
|
376
374
|
end
|
|
@@ -119,7 +119,7 @@ if defined? CanCan::ModelAdapters::MongoidAdapter
|
|
|
119
119
|
expect(MongoidProject.accessible_by(@ability, :read)).to eq([obj])
|
|
120
120
|
|
|
121
121
|
obj2 = MongoidProject.create(:title => 'Lord')
|
|
122
|
-
expect(@ability.can?(:read, obj2)).to
|
|
122
|
+
expect(@ability.can?(:read, obj2)).to be(false)
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
describe "activates only when there are Criteria in the hash" do
|
|
@@ -145,7 +145,7 @@ if defined? CanCan::ModelAdapters::MongoidAdapter
|
|
|
145
145
|
expect(MongoidProject.accessible_by(@ability, :read)).to eq([obj])
|
|
146
146
|
|
|
147
147
|
obj2 = MongoidProject.create(:title => 'Lord')
|
|
148
|
-
expect(@ability.can?(:read, obj2)).to
|
|
148
|
+
expect(@ability.can?(:read, obj2)).to be(false)
|
|
149
149
|
end
|
|
150
150
|
|
|
151
151
|
it "handles :field.size" do
|
|
@@ -155,7 +155,7 @@ if defined? CanCan::ModelAdapters::MongoidAdapter
|
|
|
155
155
|
expect(MongoidProject.accessible_by(@ability, :read)).to eq([obj])
|
|
156
156
|
|
|
157
157
|
obj2 = MongoidProject.create(:titles => ['Palatin', 'Margrave', 'Marquis'])
|
|
158
|
-
expect(@ability.can?(:read, obj2)).to
|
|
158
|
+
expect(@ability.can?(:read, obj2)).to be(false)
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
it "handles :field.exists" do
|
|
@@ -165,7 +165,7 @@ if defined? CanCan::ModelAdapters::MongoidAdapter
|
|
|
165
165
|
expect(MongoidProject.accessible_by(@ability, :read)).to eq([obj])
|
|
166
166
|
|
|
167
167
|
obj2 = MongoidProject.create
|
|
168
|
-
expect(@ability.can?(:read, obj2)).to
|
|
168
|
+
expect(@ability.can?(:read, obj2)).to be(false)
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
it "handles :field.gt" do
|
|
@@ -175,7 +175,7 @@ if defined? CanCan::ModelAdapters::MongoidAdapter
|
|
|
175
175
|
expect(MongoidProject.accessible_by(@ability, :read)).to eq([obj])
|
|
176
176
|
|
|
177
177
|
obj2 = MongoidProject.create(:age => 40)
|
|
178
|
-
expect(@ability.can?(:read, obj2)).to
|
|
178
|
+
expect(@ability.can?(:read, obj2)).to be(false)
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
it "handles instance not saved to database" do
|
|
@@ -187,7 +187,7 @@ if defined? CanCan::ModelAdapters::MongoidAdapter
|
|
|
187
187
|
expect(MongoidProject.accessible_by(@ability, :read).entries).to eq([])
|
|
188
188
|
|
|
189
189
|
obj2 = MongoidProject.new(:title => 'Lord')
|
|
190
|
-
expect(@ability.can?(:read, obj2)).to
|
|
190
|
+
expect(@ability.can?(:read, obj2)).to be(false)
|
|
191
191
|
end
|
|
192
192
|
end
|
|
193
193
|
|
data/spec/matchers.rb
CHANGED
|
@@ -3,11 +3,11 @@ RSpec::Matchers.define :orderlessly_match do |original_string|
|
|
|
3
3
|
original_string.split('').sort == given_string.split('').sort
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
failure_message do |given_string|
|
|
7
7
|
"expected \"#{given_string}\" to have the same characters as \"#{original_string}\""
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
failure_message_when_negated do |given_string|
|
|
11
11
|
"expected \"#{given_string}\" not to have the same characters as \"#{original_string}\""
|
|
12
12
|
end
|
|
13
13
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -14,7 +14,6 @@ $:.unshift File.expand_path('../support', __FILE__)
|
|
|
14
14
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
15
15
|
|
|
16
16
|
RSpec.configure do |config|
|
|
17
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
18
17
|
config.filter_run :focus => true
|
|
19
18
|
config.run_all_when_everything_filtered = true
|
|
20
19
|
config.mock_with :rspec
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cancancan
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.8.
|
|
4
|
+
version: 1.8.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bryan Rite
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-06-
|
|
12
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -45,14 +45,14 @@ dependencies:
|
|
|
45
45
|
requirements:
|
|
46
46
|
- - "~>"
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version:
|
|
48
|
+
version: 3.0.0
|
|
49
49
|
type: :development
|
|
50
50
|
prerelease: false
|
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
|
53
53
|
- - "~>"
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
|
-
version:
|
|
55
|
+
version: 3.0.0
|
|
56
56
|
- !ruby/object:Gem::Dependency
|
|
57
57
|
name: appraisal
|
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|