cancancan 1.8.0 → 1.8.4
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/Appraisals +0 -1
- data/CHANGELOG.rdoc +22 -0
- data/README.rdoc +2 -2
- data/cancancan.gemspec +1 -1
- data/gemfiles/sequel_3.x.gemfile +0 -1
- data/lib/cancan/ability.rb +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 +34 -34
- data/spec/cancan/model_adapters/active_record_adapter_spec.rb +30 -32
- 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 +0 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 819e93ed0b90294960a5cf198d9b2b706bb92102
|
|
4
|
+
data.tar.gz: d172cc5b2b9a84c5c16a984bf4f7a736b7972a56
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0561f92075412910012056ba8de57554d093bf19d8b4d8453a79b322e46fac3a5cd55683312505afd85c6d910fd55ca6ea787f1db1f57d4debd8e91e89adefce
|
|
7
|
+
data.tar.gz: e241a95106dd3ee46df19a7808368fbcfb970798e8e87bc0836e4f88df3b032a4f1462e698b0a739ff57ff37b90661c598bc96ebf89f824bc025dc68e09070c0
|
data/Appraisals
CHANGED
data/CHANGELOG.rdoc
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
Develop
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
1.8.4 (June 24th, 2014)
|
|
5
|
+
|
|
6
|
+
* Fix cancancan#86 - Fixes previous RSpec 3 update as there was a bug in the fix for RSpec 2.99. (bryanrite)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
1.8.3 (June 24th, 2014)
|
|
10
|
+
|
|
11
|
+
* Fix cancancan#85 - Remove deprecation notices for RSpec 3 and continue backwards compatibility. (andypike, bryanrite, porteta)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
1.8.2 (June 5th, 2014)
|
|
15
|
+
|
|
16
|
+
* Fix cancancan#75 - More specific hash-like object check. (bryanrite)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
1.8.1 (May 27th, 2014)
|
|
20
|
+
|
|
21
|
+
* Fix cancancan#67 - Sequel tests are run properly for JRuby. (bryanrite)
|
|
22
|
+
|
|
23
|
+
* Fix cancancan#68 - Checks for hash-like objects in subject better. (bryanrite)
|
|
24
|
+
|
|
25
|
+
|
|
4
26
|
1.8.0 (May 8th, 2014)
|
|
5
27
|
|
|
6
28
|
* Feature cancan#884 - Add a Sequel model adapter (szetobo)
|
data/README.rdoc
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
{<img src="https://badge.fury.io/rb/cancancan.png" alt="Gem Version" />}[http://badge.fury.io/rb/cancancan]
|
|
3
3
|
{<img src="https://travis-ci.org/CanCanCommunity/cancancan.png?branch=master" alt="Build Status" />}[https://travis-ci.org/CanCanCommunity/cancancan]
|
|
4
4
|
{<img src="https://codeclimate.com/github/CanCanCommunity/cancancan.png" />}[https://codeclimate.com/github/CanCanCommunity/cancancan]
|
|
5
|
-
{<img src="http://inch-
|
|
5
|
+
{<img src="http://inch-ci.org/github/CanCanCommunity/cancancan.png" alt="Inline docs" />}[http://inch-ci.org/github/CanCanCommunity/cancancan]
|
|
6
6
|
|
|
7
7
|
Wiki[https://github.com/bryanrite/cancancan/wiki] | RDocs[http://rdoc.info/projects/ryanb/cancan] | Screencast[http://railscasts.com/episodes/192-authorization-with-cancan]
|
|
8
8
|
|
|
@@ -173,7 +173,7 @@ Cancancan uses {appraisals}[https://github.com/thoughtbot/appraisal] to test the
|
|
|
173
173
|
|
|
174
174
|
When first developing, you may need to run <tt>bundle install</tt> and then <tt>appraisal install</tt>, to install the different sets.
|
|
175
175
|
|
|
176
|
-
You can then run all appraisal files (like CI does), with <tt>appraisal rake</tt> or just run a specific set <tt>appraisal
|
|
176
|
+
You can then run all appraisal files (like CI does), with <tt>appraisal rake</tt> or just run a specific set <tt>appraisal activerecord_3.0 rake</tt>.
|
|
177
177
|
|
|
178
178
|
See the {CONTRIBUTING}[https://github.com/CanCanCommunity/cancancan/blob/develop/CONTRIBUTING.md] and {spec/README}[https://github.com/bryanrite/cancancan/blob/master/spec/README.rdoc] for more information.
|
|
179
179
|
|
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/gemfiles/sequel_3.x.gemfile
CHANGED
data/lib/cancan/ability.rb
CHANGED
|
@@ -285,7 +285,7 @@ module CanCan
|
|
|
285
285
|
|
|
286
286
|
# It translates to an array the subject or the hash with multiple subjects given to can?.
|
|
287
287
|
def extract_subjects(subject)
|
|
288
|
-
subject = if subject.
|
|
288
|
+
subject = if subject.kind_of?(Hash) && subject.key?(:any)
|
|
289
289
|
subject[:any]
|
|
290
290
|
else
|
|
291
291
|
[subject]
|
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
|
+
# Check that RSpec is < 2.99
|
|
16
|
+
if !respond_to?(:failure_message) && respond_to?(:failure_message_for_should)
|
|
17
|
+
alias :failure_message :failure_message_for_should
|
|
18
|
+
alias :failure_message_when_negated :failure_message_for_should_not
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
failure_message do |ability|
|
|
16
22
|
"expected to be able to #{args.map(&:inspect).join(" ")}"
|
|
17
23
|
end
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
failure_message_when_negated do |ability|
|
|
20
26
|
"expected not to be able to #{args.map(&:inspect).join(" ")}"
|
|
21
27
|
end
|
|
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
|
|
@@ -127,10 +127,10 @@ describe CanCan::ControllerResource do
|
|
|
127
127
|
context "with a strong parameters method" do
|
|
128
128
|
it "accepts and uses the specified symbol for santitizing input" do
|
|
129
129
|
params.merge!(:controller => "model")
|
|
130
|
-
controller.
|
|
131
|
-
controller.
|
|
132
|
-
controller.
|
|
133
|
-
controller.
|
|
130
|
+
allow(controller).to receive(:resource_params).and_return(:resource => 'params')
|
|
131
|
+
allow(controller).to receive(:model_params).and_return(:model => 'params')
|
|
132
|
+
allow(controller).to receive(:create_params).and_return(:create => 'params')
|
|
133
|
+
allow(controller).to receive(:custom_params).and_return(:custom => 'params')
|
|
134
134
|
resource = CanCan::ControllerResource.new(controller, {:param_method => :custom_params})
|
|
135
135
|
expect(resource.send("resource_params")).to eq(:custom => 'params')
|
|
136
136
|
end
|
|
@@ -149,27 +149,27 @@ describe CanCan::ControllerResource do
|
|
|
149
149
|
|
|
150
150
|
it "prefers to use the create_params method for santitizing input" do
|
|
151
151
|
params.merge!(:controller => "model")
|
|
152
|
-
controller.
|
|
153
|
-
controller.
|
|
154
|
-
controller.
|
|
155
|
-
controller.
|
|
152
|
+
allow(controller).to receive(:resource_params).and_return(:resource => 'params')
|
|
153
|
+
allow(controller).to receive(:model_params).and_return(:model => 'params')
|
|
154
|
+
allow(controller).to receive(:create_params).and_return(:create => 'params')
|
|
155
|
+
allow(controller).to receive(:custom_params).and_return(:custom => 'params')
|
|
156
156
|
resource = CanCan::ControllerResource.new(controller)
|
|
157
157
|
expect(resource.send("resource_params")).to eq(:create => 'params')
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
it "prefers to use the <model_name>_params method for santitizing input if create is not found" do
|
|
161
161
|
params.merge!(:controller => "model")
|
|
162
|
-
controller.
|
|
163
|
-
controller.
|
|
164
|
-
controller.
|
|
162
|
+
allow(controller).to receive(:resource_params).and_return(:resource => 'params')
|
|
163
|
+
allow(controller).to receive(:model_params).and_return(:model => 'params')
|
|
164
|
+
allow(controller).to receive(:custom_params).and_return(:custom => 'params')
|
|
165
165
|
resource = CanCan::ControllerResource.new(controller)
|
|
166
166
|
expect(resource.send("resource_params")).to eq(:model => 'params')
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
it "prefers to use the resource_params method for santitizing input if create or model is not found" do
|
|
170
170
|
params.merge!(:controller => "model")
|
|
171
|
-
controller.
|
|
172
|
-
controller.
|
|
171
|
+
allow(controller).to receive(:resource_params).and_return(:resource => 'params')
|
|
172
|
+
allow(controller).to receive(:custom_params).and_return(:custom => 'params')
|
|
173
173
|
resource = CanCan::ControllerResource.new(controller)
|
|
174
174
|
expect(resource.send("resource_params")).to eq(:resource => 'params')
|
|
175
175
|
end
|
|
@@ -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
|
|
@@ -515,17 +515,17 @@ describe CanCan::ControllerResource do
|
|
|
515
515
|
|
|
516
516
|
context "with a strong parameters method" do
|
|
517
517
|
it "only calls the santitize method with actions matching param_actions" do
|
|
518
|
-
controller.
|
|
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
|
-
controller.
|
|
522
|
+
expect(controller).not_to receive(:send).with(:resource_params)
|
|
523
523
|
resource.send("resource_params")
|
|
524
524
|
end
|
|
525
525
|
|
|
526
526
|
it "uses the proper action param based on the action" do
|
|
527
|
-
controller.
|
|
528
|
-
controller.
|
|
527
|
+
allow(controller).to receive(:create_params).and_return(:create => 'params')
|
|
528
|
+
allow(controller).to receive(:update_params).and_return(:update => 'params')
|
|
529
529
|
resource = CanCan::ControllerResource.new(controller)
|
|
530
530
|
expect(resource.send("resource_params")).to eq(:update => 'params')
|
|
531
531
|
end
|
|
@@ -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
|
|
@@ -305,13 +305,12 @@ if defined? CanCan::ModelAdapters::ActiveRecordAdapter
|
|
|
305
305
|
article.secret == true
|
|
306
306
|
end
|
|
307
307
|
|
|
308
|
-
relation.
|
|
308
|
+
allow(relation).to receive(:count).and_raise('Unexpected scope execution.')
|
|
309
309
|
|
|
310
310
|
expect { @ability.can? :read, Article }.not_to raise_error
|
|
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
|
|
|
@@ -1,80 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
require "spec_helper"
|
|
1
|
+
require "spec_helper"
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
if defined? CanCan::ModelAdapters::SequelAdapter
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
describe CanCan::ModelAdapters::SequelAdapter do
|
|
6
|
+
DB = if RUBY_PLATFORM == 'java'
|
|
7
|
+
Sequel.connect('jdbc:sqlite:db.sqlite3')
|
|
8
|
+
else
|
|
9
|
+
Sequel.sqlite
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
DB.create_table :users do
|
|
13
|
+
primary_key :id
|
|
14
|
+
String :name
|
|
15
|
+
end
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
TrueClass :published
|
|
19
|
-
TrueClass :secret
|
|
20
|
-
Integer :priority
|
|
21
|
-
foreign_key :user_id, :users
|
|
22
|
-
end
|
|
17
|
+
class User < Sequel::Model
|
|
18
|
+
one_to_many :articles
|
|
19
|
+
end
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
DB.create_table :articles do
|
|
22
|
+
primary_key :id
|
|
23
|
+
String :name
|
|
24
|
+
TrueClass :published
|
|
25
|
+
TrueClass :secret
|
|
26
|
+
Integer :priority
|
|
27
|
+
foreign_key :user_id, :users
|
|
28
|
+
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
30
|
+
class Article < Sequel::Model
|
|
31
|
+
many_to_one :user
|
|
32
|
+
one_to_many :comments
|
|
33
|
+
end
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
DB.create_table :comments do
|
|
36
|
+
primary_key :id
|
|
37
|
+
TrueClass :spam
|
|
38
|
+
foreign_key :article_id, :articles
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Comment < Sequel::Model
|
|
42
|
+
many_to_one :article
|
|
43
|
+
end
|
|
38
44
|
|
|
39
|
-
describe CanCan::ModelAdapters::SequelAdapter do
|
|
40
45
|
before(:each) do
|
|
41
46
|
Comment.dataset.delete
|
|
42
47
|
Article.dataset.delete
|
|
43
48
|
User.dataset.delete
|
|
44
|
-
@ability =
|
|
45
|
-
@ability.extend(CanCan::Ability)
|
|
49
|
+
(@ability = double).extend(CanCan::Ability)
|
|
46
50
|
end
|
|
47
51
|
|
|
48
52
|
it "should be for only sequel model classes" do
|
|
49
|
-
CanCan::ModelAdapters::SequelAdapter.
|
|
50
|
-
CanCan::ModelAdapters::SequelAdapter.
|
|
51
|
-
CanCan::ModelAdapters::AbstractAdapter.adapter_class(Article).
|
|
53
|
+
expect(CanCan::ModelAdapters::SequelAdapter).to_not be_for_class(Object)
|
|
54
|
+
expect(CanCan::ModelAdapters::SequelAdapter).to be_for_class(Article)
|
|
55
|
+
expect(CanCan::ModelAdapters::AbstractAdapter.adapter_class(Article)).to eq CanCan::ModelAdapters::SequelAdapter
|
|
52
56
|
end
|
|
53
57
|
|
|
54
58
|
it "should find record" do
|
|
55
59
|
article = Article.create
|
|
56
|
-
CanCan::ModelAdapters::SequelAdapter.find(Article, article.id).
|
|
60
|
+
expect(CanCan::ModelAdapters::SequelAdapter.find(Article, article.id)).to eq article
|
|
57
61
|
end
|
|
58
62
|
|
|
59
63
|
it "should not fetch any records when no abilities are defined" do
|
|
60
64
|
Article.create
|
|
61
|
-
Article.accessible_by(@ability).all.
|
|
65
|
+
expect(Article.accessible_by(@ability).all).to be_empty
|
|
62
66
|
end
|
|
63
67
|
|
|
64
68
|
it "should fetch all articles when one can read all" do
|
|
65
69
|
@ability.can :read, Article
|
|
66
70
|
article = Article.create
|
|
67
|
-
@ability.
|
|
68
|
-
Article.accessible_by(@ability).all.should == [article]
|
|
71
|
+
expect(Article.accessible_by(@ability).all).to eq [article]
|
|
69
72
|
end
|
|
70
73
|
|
|
71
74
|
it "should fetch only the articles that are published" do
|
|
72
75
|
@ability.can :read, Article, :published => true
|
|
73
76
|
article1 = Article.create(:published => true)
|
|
74
77
|
article2 = Article.create(:published => false)
|
|
75
|
-
@ability.
|
|
76
|
-
@ability.should_not be_able_to(:read, article2)
|
|
77
|
-
Article.accessible_by(@ability).all.should == [article1]
|
|
78
|
+
expect(Article.accessible_by(@ability).all).to eq [article1]
|
|
78
79
|
end
|
|
79
80
|
|
|
80
81
|
it "should fetch any articles which are published or secret" do
|
|
@@ -84,11 +85,7 @@ if ENV["MODEL_ADAPTER"] == "sequel"
|
|
|
84
85
|
article2 = Article.create(:published => true, :secret => true)
|
|
85
86
|
article3 = Article.create(:published => false, :secret => true)
|
|
86
87
|
article4 = Article.create(:published => false, :secret => false)
|
|
87
|
-
@ability.
|
|
88
|
-
@ability.should be_able_to(:read, article2)
|
|
89
|
-
@ability.should be_able_to(:read, article3)
|
|
90
|
-
@ability.should_not be_able_to(:read, article4)
|
|
91
|
-
Article.accessible_by(@ability).all.should == [article1, article2, article3]
|
|
88
|
+
expect(Article.accessible_by(@ability).all).to eq([article1, article2, article3])
|
|
92
89
|
end
|
|
93
90
|
|
|
94
91
|
it "should fetch only the articles that are published and not secret" do
|
|
@@ -98,20 +95,14 @@ if ENV["MODEL_ADAPTER"] == "sequel"
|
|
|
98
95
|
article2 = Article.create(:published => true, :secret => true)
|
|
99
96
|
article3 = Article.create(:published => false, :secret => true)
|
|
100
97
|
article4 = Article.create(:published => false, :secret => false)
|
|
101
|
-
@ability.
|
|
102
|
-
@ability.should_not be_able_to(:read, article2)
|
|
103
|
-
@ability.should_not be_able_to(:read, article3)
|
|
104
|
-
@ability.should_not be_able_to(:read, article4)
|
|
105
|
-
Article.accessible_by(@ability).all.should == [article1]
|
|
98
|
+
expect(Article.accessible_by(@ability).all).to eq [article1]
|
|
106
99
|
end
|
|
107
100
|
|
|
108
101
|
it "should only read comments for articles which are published" do
|
|
109
102
|
@ability.can :read, Comment, :article => { :published => true }
|
|
110
103
|
comment1 = Comment.create(:article => Article.create(:published => true))
|
|
111
104
|
comment2 = Comment.create(:article => Article.create(:published => false))
|
|
112
|
-
@ability.
|
|
113
|
-
@ability.should_not be_able_to(:read, comment2)
|
|
114
|
-
Comment.accessible_by(@ability).all.should == [comment1]
|
|
105
|
+
expect(Comment.accessible_by(@ability).all).to eq [comment1]
|
|
115
106
|
end
|
|
116
107
|
|
|
117
108
|
it "should only read comments for articles which are published and user is 'me'" do
|
|
@@ -120,10 +111,7 @@ if ENV["MODEL_ADAPTER"] == "sequel"
|
|
|
120
111
|
comment1 = Comment.create(:article => Article.create(:published => true, :user => user1))
|
|
121
112
|
comment2 = Comment.create(:article => Article.create(:published => true))
|
|
122
113
|
comment3 = Comment.create(:article => Article.create(:published => false, :user => user1))
|
|
123
|
-
@ability.
|
|
124
|
-
@ability.should_not be_able_to(:read, comment2)
|
|
125
|
-
@ability.should_not be_able_to(:read, comment3)
|
|
126
|
-
Comment.accessible_by(@ability).all.should == [comment1]
|
|
114
|
+
expect(Comment.accessible_by(@ability).all).to eq [comment1]
|
|
127
115
|
end
|
|
128
116
|
|
|
129
117
|
it "should allow conditions in SQL and merge with hash conditions" do
|
|
@@ -138,11 +126,7 @@ if ENV["MODEL_ADAPTER"] == "sequel"
|
|
|
138
126
|
article2 = Article.create(:published => true, :secret => true, :priority => 1)
|
|
139
127
|
article3 = Article.create(:published => true, :secret => true, :priority => 2)
|
|
140
128
|
article4 = Article.create(:published => false, :secret => false, :priority => 2)
|
|
141
|
-
@ability.
|
|
142
|
-
@ability.should be_able_to(:read, article2)
|
|
143
|
-
@ability.should_not be_able_to(:read, article3)
|
|
144
|
-
@ability.should_not be_able_to(:read, article4)
|
|
145
|
-
Article.accessible_by(@ability).all.should == [article1, article2]
|
|
129
|
+
expect(Article.accessible_by(@ability).all).to eq [article1, article2]
|
|
146
130
|
end
|
|
147
131
|
end
|
|
148
132
|
end
|
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.4
|
|
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-
|
|
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
|
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
149
149
|
version: 1.3.4
|
|
150
150
|
requirements: []
|
|
151
151
|
rubyforge_project: cancancan
|
|
152
|
-
rubygems_version: 2.2.
|
|
152
|
+
rubygems_version: 2.2.2
|
|
153
153
|
signing_key:
|
|
154
154
|
specification_version: 4
|
|
155
155
|
summary: Simple authorization solution for Rails.
|