1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Ensure that AR::Relation#exists? allows only permitted params

Clarify changelog entry
Related to #34891
This commit is contained in:
bogdanvlviv 2019-01-17 20:10:01 +00:00
parent 2dee59fed1
commit 6410c70f7c
No known key found for this signature in database
GPG key ID: E4ACD76A6DB6DFDD
3 changed files with 17 additions and 7 deletions

View file

@ -1,10 +1,10 @@
* Set polymorphic type column to NULL on `dependent: :nullify` strategy. * Set polymorphic type column to NULL on `dependent: :nullify` strategy.
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL. On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
*Laerti Papa* *Laerti Papa*
* Allow `ActionController::Params` as argument of `ActiveRecord::Base#exists?`. * Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
*Gannon McGibbon* *Gannon McGibbon*

View file

@ -226,11 +226,15 @@ class FinderTest < ActiveRecord::TestCase
end end
def test_exists_with_strong_parameters def test_exists_with_strong_parameters
assert_equal false, Subscriber.exists?(Parameters.new(nick: "foo")) assert_equal false, Subscriber.exists?(Parameters.new(nick: "foo").permit!)
Subscriber.create!(nick: "foo") Subscriber.create!(nick: "foo")
assert_equal true, Subscriber.exists?(Parameters.new(nick: "foo")) assert_equal true, Subscriber.exists?(Parameters.new(nick: "foo").permit!)
assert_raises(ActiveModel::ForbiddenAttributesError) do
Subscriber.exists?(Parameters.new(nick: "foo"))
end
end end
def test_exists_passing_active_record_object_is_not_permitted def test_exists_passing_active_record_object_is_not_permitted

View file

@ -3,10 +3,16 @@
class Parameters class Parameters
def initialize(parameters = {}) def initialize(parameters = {})
@parameters = parameters.with_indifferent_access @parameters = parameters.with_indifferent_access
@permitted = false
end end
def permitted? def permitted?
true @permitted
end
def permit!
@permitted = true
self
end end
def to_h def to_h