cancancan 1.8.0 → 1.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7079b16052c2f98ebe67d6ce08e390188bca856d
4
- data.tar.gz: faa43141ca3124dbe3d40ceb30a76ca78bc56117
3
+ metadata.gz: b8ae98ee2960d59064addef2385b147001f02a90
4
+ data.tar.gz: 6f906603e1573ab3983ec429e0ba0a91b830a486
5
5
  SHA512:
6
- metadata.gz: 8168024035574501d8bef61033f458facb1b7173ed98d901b9b51aedc0c659470f6210beb308273de9cd437e4d75027eb39321f104a9e8dc8f933593f1a67aa1
7
- data.tar.gz: e71e7aa4f2a66f0f660aa9ce224dff3c0de2efc3b0fb85d461113175e5349700bf4475f5f9ca7abf16c56457488a33b3b5d954e753b021f162428c5827e28cd5
6
+ metadata.gz: e61cfecc5894d707b9f1db24278eb117fae7cec6fac6514ffdfc95eee8ec64db6c2fba872e2a98dc0342520e7aa61256a8453dd8ded1eefd85cf18f91513fa53
7
+ data.tar.gz: 36256ef9081035d4eb1b66a79197beeb7e971ed4efc4df96a6f4f039f7d98632ce6b992381bc15234f649989a9f3e64f0d3c45f4aae0d2c2e8cfdc37020d7c0d
data/Appraisals CHANGED
@@ -64,7 +64,6 @@ appraise "sequel_3.x" do
64
64
  gem 'activesupport', '~> 3.0', :require => 'active_support/all'
65
65
 
66
66
  gemfile.platforms :jruby do
67
- gem "activerecord-jdbcsqlite3-adapter"
68
67
  gem "jdbc-sqlite3"
69
68
  end
70
69
 
@@ -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)
@@ -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 rails_3.0 rake</tt>.
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
 
@@ -6,7 +6,6 @@ gem "sequel", "~> 3.47.0"
6
6
  gem "activesupport", "~> 3.0", :require => "active_support/all"
7
7
 
8
8
  platforms :jruby do
9
- gem "activerecord-jdbcsqlite3-adapter"
10
9
  gem "jdbc-sqlite3"
11
10
  end
12
11
 
@@ -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?(:keys) && subject.key?(:any)
288
+ subject = if subject.respond_to?(:key?) && subject.key?(:any)
289
289
  subject[:any]
290
290
  else
291
291
  [subject]
@@ -1,3 +1,3 @@
1
1
  module CanCan
2
- VERSION = "1.8.0"
2
+ VERSION = "1.8.1"
3
3
  end
@@ -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.stub(:resource_params).and_return(:resource => 'params')
131
- controller.stub(:model_params).and_return(:model => 'params')
132
- controller.stub(:create_params).and_return(:create => 'params')
133
- controller.stub(:custom_params).and_return(:custom => 'params')
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.stub(:resource_params).and_return(:resource => 'params')
153
- controller.stub(:model_params).and_return(:model => 'params')
154
- controller.stub(:create_params).and_return(:create => 'params')
155
- controller.stub(:custom_params).and_return(:custom => 'params')
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.stub(:resource_params).and_return(:resource => 'params')
163
- controller.stub(:model_params).and_return(:model => 'params')
164
- controller.stub(:custom_params).and_return(:custom => 'params')
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.stub(:resource_params).and_return(:resource => 'params')
172
- controller.stub(:custom_params).and_return(:custom => 'params')
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.stub(:resource_params).and_return(:resource => 'params')
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.should_not_receive(:send).with(:resource_params)
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.stub(:create_params).and_return(:create => 'params')
528
- controller.stub(:update_params).and_return(:update => 'params')
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.stub(:count).and_raise('Unexpected scope execution.')
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
- if ENV["MODEL_ADAPTER"] == "sequel"
2
- require "spec_helper"
1
+ require "spec_helper"
3
2
 
4
- DB = Sequel.sqlite
3
+ if defined? CanCan::ModelAdapters::SequelAdapter
5
4
 
6
- DB.create_table :users do
7
- primary_key :id
8
- String :name
9
- end
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
- class User < Sequel::Model
12
- one_to_many :articles
13
- end
12
+ DB.create_table :users do
13
+ primary_key :id
14
+ String :name
15
+ end
14
16
 
15
- DB.create_table :articles do
16
- primary_key :id
17
- String :name
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
- class Article < Sequel::Model
25
- many_to_one :user
26
- one_to_many :comments
27
- end
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
- DB.create_table :comments do
30
- primary_key :id
31
- TrueClass :spam
32
- foreign_key :article_id, :articles
33
- end
30
+ class Article < Sequel::Model
31
+ many_to_one :user
32
+ one_to_many :comments
33
+ end
34
34
 
35
- class Comment < Sequel::Model
36
- many_to_one :article
37
- end
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 = Object.new
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.should_not be_for_class(Object)
50
- CanCan::ModelAdapters::SequelAdapter.should be_for_class(Article)
51
- CanCan::ModelAdapters::AbstractAdapter.adapter_class(Article).should == CanCan::ModelAdapters::SequelAdapter
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).should == article
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.should be_empty
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.should be_able_to(:read, article)
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.should be_able_to(:read, article1)
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.should be_able_to(:read, article1)
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.should be_able_to(:read, article1)
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.should be_able_to(:read, comment1)
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.should be_able_to(:read, comment1)
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.should be_able_to(:read, article1)
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.0
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-08 00:00:00.000000000 Z
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.1
152
+ rubygems_version: 2.2.2
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: Simple authorization solution for Rails.