cancancan 1.8.4 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 819e93ed0b90294960a5cf198d9b2b706bb92102
4
- data.tar.gz: d172cc5b2b9a84c5c16a984bf4f7a736b7972a56
3
+ metadata.gz: 59fd5f683924f32658036d91ec731a03dc2620f0
4
+ data.tar.gz: 80ada1d8d82e08dae4f39afa0f4fc6e0bba1a43b
5
5
  SHA512:
6
- metadata.gz: 0561f92075412910012056ba8de57554d093bf19d8b4d8453a79b322e46fac3a5cd55683312505afd85c6d910fd55ca6ea787f1db1f57d4debd8e91e89adefce
7
- data.tar.gz: e241a95106dd3ee46df19a7808368fbcfb970798e8e87bc0836e4f88df3b032a4f1462e698b0a739ff57ff37b90661c598bc96ebf89f824bc025dc68e09070c0
6
+ metadata.gz: f7854cb0fd225fc65ca36e2ae8b3d257e2509ebc092801a1802686bd2537dcb3c53f0e522f3d9a43b15ded9765a026c9d11c3588f4a4ff28bd752606fa01788c
7
+ data.tar.gz: e98f2b6d8defb75df838a82a5c0a28befdec610db7be82f119e70a922d953963fc7c268d014668ccf28c5fd54ccabbda9ca8d8bba4e175b587a36093f4da76b4
@@ -11,6 +11,8 @@ gemfile:
11
11
  - gemfiles/activerecord_3.0.gemfile
12
12
  - gemfiles/activerecord_3.1.gemfile
13
13
  - gemfiles/activerecord_3.2.gemfile
14
+ - gemfiles/activerecord_4.0.gemfile
15
+ - gemfiles/activerecord_4.1.gemfile
14
16
  - gemfiles/datamapper_1.x.gemfile
15
17
  - gemfiles/mongoid_2.x.gemfile
16
18
  - gemfiles/sequel_3.x.gemfile
@@ -19,6 +21,19 @@ services:
19
21
  matrix:
20
22
  allow_failures:
21
23
  - rvm: rbx
24
+ exclude:
25
+ - rvm: 1.8.7
26
+ gemfile: gemfiles/activerecord_4.0.gemfile
27
+ - rvm: 1.8.7
28
+ gemfile: gemfiles/activerecord_4.1.gemfile
29
+ - rvm: 1.9.2
30
+ gemfile: gemfiles/activerecord_4.0.gemfile
31
+ - rvm: 1.9.2
32
+ gemfile: gemfiles/activerecord_4.1.gemfile
33
+ - rvm: ree
34
+ gemfile: gemfiles/activerecord_4.0.gemfile
35
+ - rvm: ree
36
+ gemfile: gemfiles/activerecord_4.1.gemfile
22
37
  notifications:
23
38
  recipients:
24
39
  - bryan@bryanrite.com
data/Appraisals CHANGED
@@ -39,6 +39,34 @@ appraise "activerecord_3.2" do
39
39
  end
40
40
  end
41
41
 
42
+ appraise "activerecord_4.0" do
43
+ gem "activerecord", "~> 4.0.5", :require => "active_record"
44
+ gem 'activesupport', '~> 4.0.5', :require => 'active_support/all'
45
+
46
+ gemfile.platforms :jruby do
47
+ gem "activerecord-jdbcsqlite3-adapter"
48
+ gem "jdbc-sqlite3"
49
+ end
50
+
51
+ gemfile.platforms :ruby, :mswin, :mingw do
52
+ gem "sqlite3"
53
+ end
54
+ end
55
+
56
+ appraise "activerecord_4.1" do
57
+ gem "activerecord", "~> 4.1.1", :require => "active_record"
58
+ gem 'activesupport', '~> 4.1.1', :require => 'active_support/all'
59
+
60
+ gemfile.platforms :jruby do
61
+ gem "activerecord-jdbcsqlite3-adapter"
62
+ gem "jdbc-sqlite3"
63
+ end
64
+
65
+ gemfile.platforms :ruby, :mswin, :mingw do
66
+ gem "sqlite3"
67
+ end
68
+ end
69
+
42
70
  appraise "datamapper_1.x" do
43
71
  gem 'activesupport', '~> 3.0', :require => 'active_support/all'
44
72
  gem "dm-core", "~> 1.0.2"
@@ -1,6 +1,13 @@
1
1
  Develop
2
2
 
3
3
 
4
+ 1.9.0 (July 20th, 2014)
5
+
6
+ * Fix cancancan#59 - Parameters are automatically detected and santitized for all actions, not just create and update. (bryanrite)
7
+
8
+ * Fix cancancan#97, 72, 40, 39, 26 - Support Active Record 4 properly with references on nested permissions. (scpike, tdg5, Crystark)
9
+
10
+
4
11
  1.8.4 (June 24th, 2014)
5
12
 
6
13
  * Fix cancancan#86 - Fixes previous RSpec 3 update as there was a bug in the fix for RSpec 2.99. (bryanrite)
@@ -22,7 +22,7 @@ Any help is greatly appreciated, feel free to submit pull-requests or open issue
22
22
 
23
23
  In <b>Rails 3 and 4</b>, add this to your Gemfile and run the +bundle+ command.
24
24
 
25
- gem 'cancancan', '~> 1.8'
25
+ gem 'cancancan', '~> 1.9'
26
26
 
27
27
  In <b>Rails 2</b>, add this to your environment.rb file.
28
28
 
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.5", :require => "active_record"
6
+ gem "activesupport", "~> 4.0.5", :require => "active_support/all"
7
+
8
+ platforms :jruby do
9
+ gem "activerecord-jdbcsqlite3-adapter"
10
+ gem "jdbc-sqlite3"
11
+ end
12
+
13
+ platforms :ruby, :mswin, :mingw do
14
+ gem "sqlite3"
15
+ end
16
+
17
+ gemspec :path => "../"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.1.1", :require => "active_record"
6
+ gem "activesupport", "~> 4.1.1", :require => "active_support/all"
7
+
8
+ platforms :jruby do
9
+ gem "activerecord-jdbcsqlite3-adapter"
10
+ gem "jdbc-sqlite3"
11
+ end
12
+
13
+ platforms :ruby, :mswin, :mingw do
14
+ gem "sqlite3"
15
+ end
16
+
17
+ gemspec :path => "../"
@@ -9,7 +9,17 @@ require 'cancan/inherited_resource'
9
9
 
10
10
  require 'cancan/model_adapters/abstract_adapter'
11
11
  require 'cancan/model_adapters/default_adapter'
12
- require 'cancan/model_adapters/active_record_adapter' if defined? ActiveRecord
12
+
13
+ if defined? ActiveRecord
14
+ require 'cancan/model_adapters/active_record_adapter'
15
+ if ActiveRecord.respond_to?(:version) &&
16
+ ActiveRecord.version >= Gem::Version.new("4")
17
+ require 'cancan/model_adapters/active_record_4_adapter'
18
+ else
19
+ require 'cancan/model_adapters/active_record_3_adapter'
20
+ end
21
+ end
22
+
13
23
  require 'cancan/model_adapters/data_mapper_adapter' if defined? DataMapper
14
24
  require 'cancan/model_adapters/mongoid_adapter' if defined?(Mongoid) && defined?(Mongoid::Document)
15
25
  require 'cancan/model_adapters/sequel_adapter' if defined? Sequel
@@ -294,7 +294,7 @@ module CanCan
294
294
 
295
295
  def self.included(base)
296
296
  base.extend ClassMethods
297
- base.helper_method :can?, :cannot?, :current_ability
297
+ base.helper_method :can?, :cannot?, :current_ability if base.respond_to? :helper_method
298
298
  end
299
299
 
300
300
  # Raises a CanCan::AccessDenied exception if the current_ability cannot
@@ -220,22 +220,29 @@ module CanCan
220
220
  end
221
221
 
222
222
  def resource_params
223
- if param_actions.include?(@params[:action].to_sym) && params_method.present?
223
+ if parameters_require_sanitizing? && params_method.present?
224
224
  return case params_method
225
225
  when Symbol then @controller.send(params_method)
226
226
  when String then @controller.instance_eval(params_method)
227
227
  when Proc then params_method.call(@controller)
228
228
  end
229
- elsif @options[:class]
230
- params_key = extract_key(@options[:class])
231
- return @params[params_key] if @params[params_key]
229
+ else
230
+ resource_params_by_namespaced_name
232
231
  end
232
+ end
233
233
 
234
- resource_params_by_namespaced_name
234
+ def parameters_require_sanitizing?
235
+ save_actions.include?(@params[:action].to_sym) || resource_params_by_namespaced_name.present?
235
236
  end
236
237
 
237
238
  def resource_params_by_namespaced_name
238
- @params[extract_key(namespaced_name)]
239
+ if @options[:instance_name] && @params.has_key?(extract_key(@options[:instance_name]))
240
+ @params[extract_key(@options[:instance_name])]
241
+ elsif @options[:class] && @params.has_key?(extract_key(@options[:class]))
242
+ @params[extract_key(@options[:class])]
243
+ else
244
+ @params[extract_key(namespaced_name)]
245
+ end
239
246
  end
240
247
 
241
248
  def params_method
@@ -277,7 +284,7 @@ module CanCan
277
284
  [:new, :create] + Array(@options[:new])
278
285
  end
279
286
 
280
- def param_actions
287
+ def save_actions
281
288
  [:create, :update]
282
289
  end
283
290
 
@@ -0,0 +1,47 @@
1
+ module CanCan
2
+ module ModelAdapters
3
+ class ActiveRecord3Adapter < AbstractAdapter
4
+ include ActiveRecordAdapter
5
+ def self.for_class?(model_class)
6
+ model_class <= ActiveRecord::Base
7
+ end
8
+
9
+ def self.override_condition_matching?(subject, name, value)
10
+ name.kind_of?(MetaWhere::Column) if defined? MetaWhere
11
+ end
12
+
13
+ def self.matches_condition?(subject, name, value)
14
+ subject_value = subject.send(name.column)
15
+ if name.method.to_s.ends_with? "_any"
16
+ value.any? { |v| meta_where_match? subject_value, name.method.to_s.sub("_any", ""), v }
17
+ elsif name.method.to_s.ends_with? "_all"
18
+ value.all? { |v| meta_where_match? subject_value, name.method.to_s.sub("_all", ""), v }
19
+ else
20
+ meta_where_match? subject_value, name.method, value
21
+ end
22
+ end
23
+
24
+ def self.meta_where_match?(subject_value, method, value)
25
+ case method.to_sym
26
+ when :eq then subject_value == value
27
+ when :not_eq then subject_value != value
28
+ when :in then value.include?(subject_value)
29
+ when :not_in then !value.include?(subject_value)
30
+ when :lt then subject_value < value
31
+ when :lteq then subject_value <= value
32
+ when :gt then subject_value > value
33
+ when :gteq then subject_value >= value
34
+ when :matches then subject_value =~ Regexp.new("^" + Regexp.escape(value).gsub("%", ".*") + "$", true)
35
+ when :does_not_match then !meta_where_match?(subject_value, :matches, value)
36
+ else raise NotImplemented, "The #{method} MetaWhere condition is not supported."
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def build_relation(*where_conditions)
43
+ @model_class.where(*where_conditions).includes(joins)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,21 @@
1
+ module CanCan
2
+ module ModelAdapters
3
+ class ActiveRecord4Adapter < AbstractAdapter
4
+ include ActiveRecordAdapter
5
+ def self.for_class?(model_class)
6
+ model_class <= ActiveRecord::Base
7
+ end
8
+
9
+ private
10
+
11
+ # As of rails 4, `includes()` no longer causes active record to
12
+ # look inside the where clause to decide to outer join tables
13
+ # you're using in the where. Instead, `references()` is required
14
+ # in addition to `includes()` to force the outer join.
15
+ #
16
+ def build_relation(*where_conditions)
17
+ @model_class.where(*where_conditions).includes(joins).references(joins)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,41 +1,6 @@
1
1
  module CanCan
2
2
  module ModelAdapters
3
- class ActiveRecordAdapter < AbstractAdapter
4
- def self.for_class?(model_class)
5
- model_class <= ActiveRecord::Base
6
- end
7
-
8
- def self.override_condition_matching?(subject, name, value)
9
- name.kind_of?(MetaWhere::Column) if defined? MetaWhere
10
- end
11
-
12
- def self.matches_condition?(subject, name, value)
13
- subject_value = subject.send(name.column)
14
- if name.method.to_s.ends_with? "_any"
15
- value.any? { |v| meta_where_match? subject_value, name.method.to_s.sub("_any", ""), v }
16
- elsif name.method.to_s.ends_with? "_all"
17
- value.all? { |v| meta_where_match? subject_value, name.method.to_s.sub("_all", ""), v }
18
- else
19
- meta_where_match? subject_value, name.method, value
20
- end
21
- end
22
-
23
- def self.meta_where_match?(subject_value, method, value)
24
- case method.to_sym
25
- when :eq then subject_value == value
26
- when :not_eq then subject_value != value
27
- when :in then value.include?(subject_value)
28
- when :not_in then !value.include?(subject_value)
29
- when :lt then subject_value < value
30
- when :lteq then subject_value <= value
31
- when :gt then subject_value > value
32
- when :gteq then subject_value >= value
33
- when :matches then subject_value =~ Regexp.new("^" + Regexp.escape(value).gsub("%", ".*") + "$", true)
34
- when :does_not_match then !meta_where_match?(subject_value, :matches, value)
35
- else raise NotImplemented, "The #{method} MetaWhere condition is not supported."
36
- end
37
- end
38
-
3
+ module ActiveRecordAdapter
39
4
  # Returns conditions intended to be used inside a database query. Normally you will not call this
40
5
  # method directly, but instead go through ModelAdditions#accessible_by.
41
6
  #
@@ -99,11 +64,10 @@ module CanCan
99
64
  if override_scope
100
65
  @model_class.where(nil).merge(override_scope)
101
66
  elsif @model_class.respond_to?(:where) && @model_class.respond_to?(:joins)
102
- mergeable_conditions = @rules.select {|rule| rule.unmergeable? }.blank?
103
- if mergeable_conditions
104
- @model_class.where(conditions).includes(joins)
67
+ if mergeable_conditions?
68
+ build_relation(conditions)
105
69
  else
106
- @model_class.where(*(@rules.map(&:conditions))).includes(joins)
70
+ build_relation(*(@rules.map(&:conditions)))
107
71
  end
108
72
  else
109
73
  @model_class.all(:conditions => conditions, :joins => joins)
@@ -112,6 +76,10 @@ module CanCan
112
76
 
113
77
  private
114
78
 
79
+ def mergeable_conditions?
80
+ @rules.find {|rule| rule.unmergeable? }.blank?
81
+ end
82
+
115
83
  def override_scope
116
84
  conditions = @rules.map(&:conditions).compact
117
85
  if defined?(ActiveRecord::Relation) && conditions.any? { |c| c.kind_of?(ActiveRecord::Relation) }
@@ -1,3 +1,3 @@
1
1
  module CanCan
2
- VERSION = "1.8.4"
2
+ VERSION = "1.9.0"
3
3
  end
@@ -125,8 +125,11 @@ describe CanCan::ControllerResource do
125
125
  end
126
126
 
127
127
  context "with a strong parameters method" do
128
+ before :each do
129
+ params.merge!(:controller => "model", :model => { :name => 'test'})
130
+ end
131
+
128
132
  it "accepts and uses the specified symbol for santitizing input" do
129
- params.merge!(:controller => "model")
130
133
  allow(controller).to receive(:resource_params).and_return(:resource => 'params')
131
134
  allow(controller).to receive(:model_params).and_return(:model => 'params')
132
135
  allow(controller).to receive(:create_params).and_return(:create => 'params')
@@ -136,19 +139,16 @@ describe CanCan::ControllerResource do
136
139
  end
137
140
 
138
141
  it "accepts the specified string for sanitizing input" do
139
- params.merge!(:controller => "model")
140
142
  resource = CanCan::ControllerResource.new(controller, {:param_method => "{:custom => 'params'}"})
141
143
  expect(resource.send("resource_params")).to eq(:custom => 'params')
142
144
  end
143
145
 
144
146
  it "accepts the specified proc for sanitizing input" do
145
- params.merge!(:controller => "model")
146
147
  resource = CanCan::ControllerResource.new(controller, {:param_method => Proc.new { |c| {:custom => 'params'}}})
147
148
  expect(resource.send("resource_params")).to eq(:custom => 'params')
148
149
  end
149
150
 
150
151
  it "prefers to use the create_params method for santitizing input" do
151
- params.merge!(:controller => "model")
152
152
  allow(controller).to receive(:resource_params).and_return(:resource => 'params')
153
153
  allow(controller).to receive(:model_params).and_return(:model => 'params')
154
154
  allow(controller).to receive(:create_params).and_return(:create => 'params')
@@ -158,7 +158,6 @@ describe CanCan::ControllerResource do
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
- params.merge!(:controller => "model")
162
161
  allow(controller).to receive(:resource_params).and_return(:resource => 'params')
163
162
  allow(controller).to receive(:model_params).and_return(:model => 'params')
164
163
  allow(controller).to receive(:custom_params).and_return(:custom => 'params')
@@ -167,7 +166,6 @@ describe CanCan::ControllerResource do
167
166
  end
168
167
 
169
168
  it "prefers to use the resource_params method for santitizing input if create or model is not found" do
170
- params.merge!(:controller => "model")
171
169
  allow(controller).to receive(:resource_params).and_return(:resource => 'params')
172
170
  allow(controller).to receive(:custom_params).and_return(:custom => 'params')
173
171
  resource = CanCan::ControllerResource.new(controller)
@@ -508,28 +506,41 @@ describe CanCan::ControllerResource do
508
506
  end
509
507
  end
510
508
 
511
- context "on update actions" do
512
- before :each do
513
- params.merge!(:action => 'update')
514
- end
509
+ it "calls the santitizer when the parameter hash matches our object" do
510
+ params.merge!(:action => 'create', :model => { :name => 'test' })
511
+ allow(controller).to receive(:create_params).and_return({})
515
512
 
516
- context "with a strong parameters method" do
517
- it "only calls the santitize method with actions matching param_actions" do
518
- allow(controller).to receive(:resource_params).and_return(:resource => 'params')
519
- resource = CanCan::ControllerResource.new(controller)
520
- allow(resource).to receive(:param_actions) { [:create] }
513
+ resource = CanCan::ControllerResource.new(controller)
514
+ resource.load_resource
515
+ expect(controller.instance_variable_get(:@model).name).to eq nil
516
+ end
521
517
 
522
- expect(controller).not_to receive(:send).with(:resource_params)
523
- resource.send("resource_params")
524
- end
518
+ it "santitizes correctly when the instance name is overriden" do
519
+ params.merge!(:action => 'create', :custom_name => {:name => "foobar"})
520
+ allow(controller).to receive(:create_params).and_return({})
525
521
 
526
- it "uses the proper action param based on the action" do
527
- allow(controller).to receive(:create_params).and_return(:create => 'params')
528
- allow(controller).to receive(:update_params).and_return(:update => 'params')
529
- resource = CanCan::ControllerResource.new(controller)
530
- expect(resource.send("resource_params")).to eq(:update => 'params')
531
- end
532
- end
522
+ resource = CanCan::ControllerResource.new(controller, :instance_name => :custom_name)
523
+ resource.load_resource
524
+ expect(controller.instance_variable_get(:@custom_name).name).to eq nil
525
+ end
526
+
527
+ it "calls the santitize method on non-save actions when required" do
528
+ params.merge!(:action => 'new', :model => { :name => 'test' })
529
+
530
+ allow(controller).to receive(:resource_params).and_return({})
531
+ resource = CanCan::ControllerResource.new(controller)
532
+ resource.load_resource
533
+ expect(controller.instance_variable_get(:@model).name).to eq nil
534
+ end
535
+
536
+ it "doesn't sanitize parameters on non-save actions when not required" do
537
+ params.merge!(:action => 'new', :not_our_model => { :name => 'test' })
538
+ allow(controller).to receive(:resource_params).and_raise
539
+
540
+ resource = CanCan::ControllerResource.new(controller)
541
+ expect {
542
+ resource.load_resource
543
+ }.to_not raise_error
533
544
  end
534
545
 
535
546
  it "is a parent resource when name is provided which doesn't match controller" do
@@ -35,6 +35,12 @@ if defined? CanCan::ModelAdapters::ActiveRecordAdapter
35
35
  t.timestamps
36
36
  end
37
37
 
38
+ create_table(:legacy_mentions) do |t|
39
+ t.integer :user_id
40
+ t.integer :article_id
41
+ t.timestamps
42
+ end
43
+
38
44
  create_table(:users) do |t|
39
45
  t.timestamps
40
46
  end
@@ -50,9 +56,17 @@ if defined? CanCan::ModelAdapters::ActiveRecordAdapter
50
56
  class Article < ActiveRecord::Base
51
57
  belongs_to :category
52
58
  has_many :comments
59
+ has_many :mentions
60
+ has_many :mentioned_users, :through => :mentions, :source => :user
53
61
  belongs_to :user
54
62
  end
55
63
 
64
+ class Mention < ActiveRecord::Base
65
+ self.table_name = 'legacy_mentions'
66
+ belongs_to :user
67
+ belongs_to :article
68
+ end
69
+
56
70
  class Comment < ActiveRecord::Base
57
71
  belongs_to :article
58
72
  end
@@ -67,14 +81,22 @@ if defined? CanCan::ModelAdapters::ActiveRecordAdapter
67
81
  end
68
82
 
69
83
  it "is for only active record classes" do
70
- expect(CanCan::ModelAdapters::ActiveRecordAdapter).to_not be_for_class(Object)
71
- expect(CanCan::ModelAdapters::ActiveRecordAdapter).to be_for_class(Article)
72
- expect(CanCan::ModelAdapters::AbstractAdapter.adapter_class(Article)).to eq(CanCan::ModelAdapters::ActiveRecordAdapter)
84
+ if ActiveRecord.respond_to?(:version) &&
85
+ ActiveRecord.version > Gem::Version.new("4")
86
+ expect(CanCan::ModelAdapters::ActiveRecord4Adapter).to_not be_for_class(Object)
87
+ expect(CanCan::ModelAdapters::ActiveRecord4Adapter).to be_for_class(Article)
88
+ expect(CanCan::ModelAdapters::AbstractAdapter.adapter_class(Article)).to eq(CanCan::ModelAdapters::ActiveRecord4Adapter)
89
+ else
90
+ expect(CanCan::ModelAdapters::ActiveRecord3Adapter).to_not be_for_class(Object)
91
+ expect(CanCan::ModelAdapters::ActiveRecord3Adapter).to be_for_class(Article)
92
+ expect(CanCan::ModelAdapters::AbstractAdapter.adapter_class(Article)).to eq(CanCan::ModelAdapters::ActiveRecord3Adapter)
93
+ end
73
94
  end
74
95
 
75
96
  it "finds record" do
76
97
  article = Article.create!
77
- expect(CanCan::ModelAdapters::ActiveRecordAdapter.find(Article, article.id)).to eq(article)
98
+ adapter = CanCan::ModelAdapters::AbstractAdapter.adapter_class(Article)
99
+ expect(adapter.find(Article, article.id)).to eq(article)
78
100
  end
79
101
 
80
102
  it "does not fetch any records when no abilities are defined" do
@@ -105,6 +127,16 @@ if defined? CanCan::ModelAdapters::ActiveRecordAdapter
105
127
  expect(Article.accessible_by(@ability)).to eq([article1, article2, article3])
106
128
  end
107
129
 
130
+ it "fetches any articles which we are cited in" do
131
+ user = User.create!
132
+ cited = Article.create!
133
+ not_cited = Article.create!
134
+ cited.mentioned_users << user
135
+ @ability.can :read, Article, { :mentioned_users => { :id => user.id } }
136
+ @ability.can :read, Article, { :mentions => { :user_id => user.id } }
137
+ expect(Article.accessible_by(@ability)).to eq([cited])
138
+ end
139
+
108
140
  it "fetches only the articles that are published and not secret" do
109
141
  @ability.can :read, Article, :published => true
110
142
  @ability.cannot :read, Article, :secret => true
@@ -337,7 +369,7 @@ if defined? CanCan::ModelAdapters::ActiveRecordAdapter
337
369
  end
338
370
 
339
371
  it "matches any MetaWhere condition" do
340
- adapter = CanCan::ModelAdapters::ActiveRecordAdapter
372
+ adapter = CanCan::ModelAdapters::AbstractAdapter.adapter_class(Article)
341
373
  article1 = Article.new(:priority => 1, :name => "Hello World")
342
374
  expect(adapter.matches_condition?(article1, :priority.eq, 1)).to be(true)
343
375
  expect(adapter.matches_condition?(article1, :priority.eq, 2)).to be(false)
@@ -7,7 +7,9 @@ require 'matchers'
7
7
  require 'cancan/matchers'
8
8
 
9
9
  # I8n setting to fix deprecation.
10
- I18n.enforce_available_locales = false if defined? I18n
10
+ if defined?(I18n) && I18n.respond_to?('enforce_available_locales=')
11
+ I18n.enforce_available_locales = false
12
+ end
11
13
 
12
14
  # Add support to load paths
13
15
  $:.unshift File.expand_path('../support', __FILE__)
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
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Rite
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-24 00:00:00.000000000 Z
12
+ date: 2014-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -88,6 +88,8 @@ files:
88
88
  - gemfiles/activerecord_3.0.gemfile
89
89
  - gemfiles/activerecord_3.1.gemfile
90
90
  - gemfiles/activerecord_3.2.gemfile
91
+ - gemfiles/activerecord_4.0.gemfile
92
+ - gemfiles/activerecord_4.1.gemfile
91
93
  - gemfiles/datamapper_1.x.gemfile
92
94
  - gemfiles/mongoid_2.x.gemfile
93
95
  - gemfiles/sequel_3.x.gemfile
@@ -100,6 +102,8 @@ files:
100
102
  - lib/cancan/inherited_resource.rb
101
103
  - lib/cancan/matchers.rb
102
104
  - lib/cancan/model_adapters/abstract_adapter.rb
105
+ - lib/cancan/model_adapters/active_record_3_adapter.rb
106
+ - lib/cancan/model_adapters/active_record_4_adapter.rb
103
107
  - lib/cancan/model_adapters/active_record_adapter.rb
104
108
  - lib/cancan/model_adapters/data_mapper_adapter.rb
105
109
  - lib/cancan/model_adapters/default_adapter.rb
@@ -158,6 +162,8 @@ test_files:
158
162
  - gemfiles/activerecord_3.0.gemfile
159
163
  - gemfiles/activerecord_3.1.gemfile
160
164
  - gemfiles/activerecord_3.2.gemfile
165
+ - gemfiles/activerecord_4.0.gemfile
166
+ - gemfiles/activerecord_4.1.gemfile
161
167
  - gemfiles/datamapper_1.x.gemfile
162
168
  - gemfiles/mongoid_2.x.gemfile
163
169
  - gemfiles/sequel_3.x.gemfile