Skip to content

Commit

Permalink
Merge branch 'develop' into mtsmfm-fix-breaking-change
Browse files Browse the repository at this point in the history
  • Loading branch information
coorasse authored Jan 18, 2020
2 parents 5ecd265 + cebd36d commit 9cc8377
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rvm:
- 2.4.2
- 2.5.1
- 2.6.3
- 2.7.0
- ruby-head
- jruby-9.1.17.0
- jruby-9.2.7.0
Expand All @@ -32,6 +33,8 @@ matrix:
gemfile: gemfiles/activerecord_6.0.0.gemfile
- rvm: 2.4.2
gemfile: gemfiles/activerecord_6.0.0.gemfile
- rvm: 2.7.0
gemfile: gemfiles/activerecord_4.2.0.gemfile
- rvm: jruby-9.1.17.0
gemfile: gemfiles/activerecord_5.0.2.gemfile
- rvm: jruby-9.1.17.0
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

* [#571](https://github.com/CanCanCommunity/cancancan/pull/571): allows to check ability even the object implements `#to_a`. ([@mtsmfm][])
* [#612](https://github.com/CanCanCommunity/cancancan/pull/612): Suppress keyword arguments warning for Ruby 2.7.0. ([@koic][])

## 3.0.2

Expand Down Expand Up @@ -655,3 +656,4 @@ Please read the [guide on migrating from CanCanCan 2.x to 3.0](https://github.co
[@frostblooded]: https://github.com/frostblooded
[@eloyesp]: https://github.com/eloyesp
[@mtsmfm]: https://github.com/mtsmfm
[@koic]: https://github.com/koic
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ When first developing, you need to run `bundle install` and then `appraisal inst

You can then run all appraisal files (like CI does), with `appraisal rake` or just run a specific set `appraisal activerecord_5.0 rake`.

See the [CONTRIBUTING](https://github.com/CanCanCommunity/cancancan/blob/develop/CONTRIBUTING.md) and
[spec/README](https://github.com/CanCanCommunity/cancancan/blob/master/spec/README.rdoc) for more information.
See the [CONTRIBUTING](https://github.com/CanCanCommunity/cancancan/blob/develop/CONTRIBUTING.md) for more information.


## Special Thanks
Expand Down
2 changes: 1 addition & 1 deletion lib/cancan/unauthorized_message_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def unauthorized_message(action, subject)
keys = unauthorized_message_keys(action, subject)
variables = { action: action.to_s }
variables[:subject] = translate_subject(subject)
message = I18n.translate(keys.shift, variables.merge(scope: :unauthorized, default: keys + ['']))
message = I18n.translate(keys.shift, **variables.merge(scope: :unauthorized, default: keys + ['']))
message.blank? ? nil : message
end

Expand Down
19 changes: 0 additions & 19 deletions spec/README.md

This file was deleted.

38 changes: 38 additions & 0 deletions spec/cancan/model_adapters/active_record_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,42 @@ class Transaction < ActiveRecord::Base
end
end
end

context 'when a model have renamed primary_key' do
before do
ActiveRecord::Schema.define do
create_table(:custom_pk_users, primary_key: :gid) do |t|
t.string :name
end

create_table(:custom_pk_transactions, primary_key: :gid) do |t|
t.integer :custom_pk_user_id
t.string :data
end
end

class CustomPkUser < ActiveRecord::Base
self.primary_key = 'gid'
end

class CustomPkTransaction < ActiveRecord::Base
self.primary_key = 'gid'

belongs_to :custom_pk_user
end
end

it 'can filter correctly' do
user1 = CustomPkUser.create!
user2 = CustomPkUser.create!

transaction1 = CustomPkTransaction.create!(custom_pk_user: user1)
CustomPkTransaction.create!(custom_pk_user: user2)

ability = Ability.new(user1)
ability.can :read, CustomPkTransaction, custom_pk_user: { gid: user1.gid }

expect(CustomPkTransaction.accessible_by(ability)).to match_array([transaction1])
end
end
end

0 comments on commit 9cc8377

Please sign in to comment.