cancancan 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +0 -1
- data/CHANGELOG.rdoc +7 -0
- data/README.rdoc +1 -1
- data/gemfiles/sequel_3.x.gemfile +0 -1
- data/lib/cancan/ability.rb +1 -1
- data/lib/cancan/version.rb +1 -1
- data/spec/cancan/controller_resource_spec.rb +17 -17
- data/spec/cancan/model_adapters/active_record_adapter_spec.rb +1 -1
- data/spec/cancan/model_adapters/sequel_adapter_spec.rb +49 -65
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8ae98ee2960d59064addef2385b147001f02a90
|
4
|
+
data.tar.gz: 6f906603e1573ab3983ec429e0ba0a91b830a486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e61cfecc5894d707b9f1db24278eb117fae7cec6fac6514ffdfc95eee8ec64db6c2fba872e2a98dc0342520e7aa61256a8453dd8ded1eefd85cf18f91513fa53
|
7
|
+
data.tar.gz: 36256ef9081035d4eb1b66a79197beeb7e971ed4efc4df96a6f4f039f7d98632ce6b992381bc15234f649989a9f3e64f0d3c45f4aae0d2c2e8cfdc37020d7c0d
|
data/Appraisals
CHANGED
data/CHANGELOG.rdoc
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
Develop
|
2
2
|
|
3
3
|
|
4
|
+
1.8.1 (May 27th, 2014)
|
5
|
+
|
6
|
+
* Fix cancancan#67 - Sequel tests are run properly for JRuby. (bryanrite)
|
7
|
+
|
8
|
+
* Fix cancancan#68 - Checks for hash-like objects in subject better. (bryanrite)
|
9
|
+
|
10
|
+
|
4
11
|
1.8.0 (May 8th, 2014)
|
5
12
|
|
6
13
|
* Feature cancan#884 - Add a Sequel model adapter (szetobo)
|
data/README.rdoc
CHANGED
@@ -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/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.respond_to?(:
|
288
|
+
subject = if subject.respond_to?(:key?) && subject.key?(:any)
|
289
289
|
subject[:any]
|
290
290
|
else
|
291
291
|
[subject]
|
data/lib/cancan/version.rb
CHANGED
@@ -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
|
@@ -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
520
|
resource.stub(: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
|
@@ -305,7 +305,7 @@ 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
|
@@ -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
|
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.1
|
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-05-
|
12
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -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.
|