cancancan 1.10.0 → 1.10.1

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: 2e578e1005885c6f192bb9796d1beaa98878b01e
4
- data.tar.gz: 8f4f962696dedc14dd038489dc46054c523c55a2
3
+ metadata.gz: 21431fc240e1b6a6093c6b9020f3804be1dc4b92
4
+ data.tar.gz: 604de9f26326c369c30746aee8103e9761c8319f
5
5
  SHA512:
6
- metadata.gz: 5737784c038345e4ff19c5dc519c828cb36268f77bafef9fa9d40ba3ae396fe030b2c3fc60f3e755903c9d398a59b450690cc0564b22aef1a1f46826c753aa35
7
- data.tar.gz: b4faa7beedaba71e8303aafb358a4ecd02b8d4be7abb2730c2f7b8bc9e13c46650acfa77e0ab4ecd81da381e166ddd9ab9fb098c79e7a9d3fa95dbaf5e24c0e4
6
+ metadata.gz: 05de9daae982bbf29448fbbcc5f15ea074ab8d33a4cef3b84555c494c9a2f8fabe759b09241d593de05ffb83c7c579de25445c6b88cc398cf9f4da39008ba57e
7
+ data.tar.gz: 040dbc4c5450a992bd3ce233435a44faac4aedba9cbec03387242bb8e84933f315135955765d318da58b0f0b40d9f0825c2bccf9bf2a6b2e1a552e613ed88826
data/Appraisals CHANGED
@@ -86,6 +86,7 @@ appraise "activerecord_4.2" do
86
86
 
87
87
  gemfile.platforms :ruby, :mswin, :mingw do
88
88
  gem "sqlite3"
89
+ gem "pg"
89
90
  end
90
91
  end
91
92
 
@@ -1,6 +1,11 @@
1
1
  Develop
2
2
 
3
3
 
4
+ 1.10.1 (January 13th, 2015)
5
+
6
+ * Fix cancancan#168 - A bug with ActiveRecord 4.2 support causing ProtocolViolation due to named parameters not being passed in.
7
+
8
+
4
9
  1.10.0 (January 7th, 2015)
5
10
 
6
11
  * Fix i18n issue for Ruby < 1.9.3 (bryanrite)
data/README.md CHANGED
@@ -134,7 +134,7 @@ You can also use a string that will be evaluated in the context of the controlle
134
134
 
135
135
  Finally, it's possible to associate `param_method` with a Proc object which will be called with the controller as the only argument:
136
136
 
137
- load_and_authorize_resource param_method: Proc.new [ |c| c.params.require(:article).permit(:name) ]
137
+ load_and_authorize_resource param_method: Proc.new { |c| c.params.require(:article).permit(:name) }
138
138
 
139
139
  See [Strong Parameters](https://github.com/CanCanCommunity/cancancan/wiki/Strong-Parameters) for more information.
140
140
 
@@ -12,6 +12,7 @@ end
12
12
 
13
13
  platforms :ruby, :mswin, :mingw do
14
14
  gem "sqlite3"
15
+ gem "pg"
15
16
  end
16
17
 
17
18
  gemspec :path => "../"
@@ -21,13 +21,17 @@ module CanCan
21
21
  # Rails 4.2 deprecates `sanitize_sql_hash_for_conditions`
22
22
  def sanitize_sql(conditions)
23
23
  if ActiveRecord::VERSION::MINOR >= 2 && Hash === conditions
24
- relation = @model_class.unscoped.where(conditions)
25
- predicates = relation.where_values
26
- bind_values = relation.bind_values
27
- query = Arel::Nodes::And.new(predicates).to_sql
28
- conditions = [query, *bind_values.map { |col, val| val }]
24
+ table = Arel::Table.new(@model_class.send(:table_name))
25
+
26
+ conditions = ActiveRecord::PredicateBuilder.resolve_column_aliases @model_class, conditions
27
+ conditions = @model_class.send(:expand_hash_conditions_for_aggregates, conditions)
28
+
29
+ ActiveRecord::PredicateBuilder.build_from_hash(@model_class, conditions, table).map { |b|
30
+ @model_class.send(:connection).visitor.compile b
31
+ }.join(' AND ')
32
+ else
33
+ @model_class.send(:sanitize_sql, conditions)
29
34
  end
30
- @model_class.send(:sanitize_sql, conditions)
31
35
  end
32
36
  end
33
37
  end
@@ -1,3 +1,3 @@
1
1
  module CanCan
2
- VERSION = "1.10.0"
2
+ VERSION = "1.10.1"
3
3
  end
@@ -2,39 +2,84 @@ require "spec_helper"
2
2
 
3
3
  if defined? CanCan::ModelAdapters::ActiveRecord4Adapter
4
4
  describe CanCan::ModelAdapters::ActiveRecord4Adapter do
5
- before :each do
6
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
7
- ActiveRecord::Migration.verbose = false
8
- ActiveRecord::Schema.define do
9
- create_table(:parents) do |t|
10
- t.timestamps :null => false
5
+ context 'with sqlite3' do
6
+ before :each do
7
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
8
+ ActiveRecord::Migration.verbose = false
9
+ ActiveRecord::Schema.define do
10
+ create_table(:parents) do |t|
11
+ t.timestamps :null => false
12
+ end
13
+
14
+ create_table(:children) do |t|
15
+ t.timestamps :null => false
16
+ t.integer :parent_id
17
+ end
11
18
  end
12
19
 
13
- create_table(:children) do |t|
14
- t.timestamps :null => false
15
- t.integer :parent_id
20
+ class Parent < ActiveRecord::Base
21
+ has_many :children, lambda { order(:id => :desc) }
16
22
  end
17
- end
18
23
 
19
- class Parent < ActiveRecord::Base
20
- has_many :children, lambda { order(:id => :desc) }
21
- end
24
+ class Child < ActiveRecord::Base
25
+ belongs_to :parent
26
+ end
22
27
 
23
- class Child < ActiveRecord::Base
24
- belongs_to :parent
28
+ (@ability = double).extend(CanCan::Ability)
25
29
  end
26
30
 
27
- (@ability = double).extend(CanCan::Ability)
31
+ it "respects scope on included associations" do
32
+ @ability.can :read, [Parent, Child]
33
+
34
+ parent = Parent.create!
35
+ child1 = Child.create!(:parent => parent, :created_at => 1.hours.ago)
36
+ child2 = Child.create!(:parent => parent, :created_at => 2.hours.ago)
37
+
38
+ expect(Parent.accessible_by(@ability).order(:created_at => :asc).includes(:children).first.children).to eq [child2, child1]
39
+ end
28
40
  end
29
41
 
30
- it "respects scope on included associations" do
31
- @ability.can :read, [Parent, Child]
42
+ if Gem::Specification.find_all_by_name('pg').any?
43
+ context 'with postgresql' do
44
+ before :each do
45
+ ActiveRecord::Base.establish_connection(:adapter => "postgresql", :database => "postgres", :schema_search_path => 'public')
46
+ ActiveRecord::Base.connection.drop_database('cancan_postgresql_spec')
47
+ ActiveRecord::Base.connection.create_database 'cancan_postgresql_spec', 'encoding' => 'utf-8', 'adapter' => 'postgresql'
48
+ ActiveRecord::Base.establish_connection(:adapter => "postgresql", :database => "cancan_postgresql_spec")
49
+ ActiveRecord::Migration.verbose = false
50
+ ActiveRecord::Schema.define do
51
+ create_table(:parents) do |t|
52
+ t.timestamps :null => false
53
+ end
54
+
55
+ create_table(:children) do |t|
56
+ t.timestamps :null => false
57
+ t.integer :parent_id
58
+ end
59
+ end
32
60
 
33
- parent = Parent.create!
34
- child1 = Child.create!(:parent => parent, :created_at => 1.hours.ago)
35
- child2 = Child.create!(:parent => parent, :created_at => 2.hours.ago)
61
+ class Parent < ActiveRecord::Base
62
+ has_many :children, lambda { order(:id => :desc) }
63
+ end
36
64
 
37
- expect(Parent.accessible_by(@ability).order(:created_at => :asc).includes(:children).first.children).to eq [child2, child1]
65
+ class Child < ActiveRecord::Base
66
+ belongs_to :parent
67
+ end
68
+
69
+ (@ability = double).extend(CanCan::Ability)
70
+ end
71
+
72
+ it "allows overlapping conditions in SQL and merge with hash conditions" do
73
+ @ability.can :read, Parent, :children => {:parent_id => 1}
74
+ @ability.can :read, Parent, :children => {:parent_id => 1}
75
+
76
+ parent = Parent.create!
77
+ child1 = Child.create!(:parent => parent, :created_at => 1.hours.ago)
78
+ child2 = Child.create!(:parent => parent, :created_at => 2.hours.ago)
79
+
80
+ expect(Parent.accessible_by(@ability)).to eq([parent])
81
+ end
82
+ end
38
83
  end
39
84
  end
40
85
  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.10.0
4
+ version: 1.10.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: 2015-01-07 00:00:00.000000000 Z
12
+ date: 2015-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler