diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-10-27 23:20:13 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-10-27 23:20:13 +0900 |
commit | 09b7308c48c601efbfc7b445068f1fb0f748be3e (patch) | |
tree | e72bcf34292e5e9f1d62f08b6bbb5d7dc2f1370c | |
parent | 7fae9ba0544c092ecca7fac0856766a3c8100bcc (diff) | |
download | rails-09b7308c48c601efbfc7b445068f1fb0f748be3e.tar.gz rails-09b7308c48c601efbfc7b445068f1fb0f748be3e.tar.bz2 rails-09b7308c48c601efbfc7b445068f1fb0f748be3e.zip |
`exists?` with string argument is not invalid type
Any type can be a primary key, so blank string is also valid value.
Closes #26356.
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index dafbf67456..52fd9291b2 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -20,6 +20,7 @@ require "models/matey" require "models/dog" require "models/car" require "models/tyre" +require "models/subscriber" class FinderTest < ActiveRecord::TestCase fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :author_addresses, :customers, :categories, :categorizations, :cars @@ -167,6 +168,7 @@ class FinderTest < ActiveRecord::TestCase assert_equal true, Topic.exists?(id: [1, 9999]) assert_equal false, Topic.exists?(45) + assert_equal false, Topic.exists?(9999999999999999999999999999999) assert_equal false, Topic.exists?(Topic.new.id) assert_raise(NoMethodError) { Topic.exists?([1, 2]) } @@ -211,17 +213,23 @@ class FinderTest < ActiveRecord::TestCase assert_equal false, relation.exists?(false) end + def test_exists_with_string + assert_equal false, Subscriber.exists?("foo") + assert_equal false, Subscriber.exists?(" ") + + Subscriber.create!(id: "foo") + Subscriber.create!(id: " ") + + assert_equal true, Subscriber.exists?("foo") + assert_equal true, Subscriber.exists?(" ") + end + def test_exists_passing_active_record_object_is_not_permitted assert_raises(ArgumentError) do Topic.exists?(Topic.new) end end - def test_exists_returns_false_when_parameter_has_invalid_type - assert_equal false, Topic.exists?("foo") - assert_equal false, Topic.exists?(("9" * 53).to_i) # number that's bigger than int - end - def test_exists_does_not_select_columns_without_alias assert_sql(/SELECT\W+1 AS one FROM ["`]topics["`]/i) do Topic.exists? |