mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #42287 from martinjaimem/enhancement/add-tests-for-argument-error-on-finder-methods
Add tests for ArgumentError errors in finder methods
This commit is contained in:
commit
a8461b7217
2 changed files with 19 additions and 2 deletions
|
@ -145,9 +145,12 @@ class FinderTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_find_passing_active_record_object_is_not_permitted
|
def test_find_passing_active_record_object_is_not_permitted
|
||||||
assert_raises(ArgumentError) do
|
error = assert_raises(ArgumentError) do
|
||||||
Topic.find(Topic.last)
|
Topic.find(Topic.last)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert_equal "You are passing an instance of ActiveRecord::Base to `find`. " \
|
||||||
|
"Please pass the id of the object by calling `.id`.", error.message
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_symbols_table_ref
|
def test_symbols_table_ref
|
||||||
|
@ -245,9 +248,12 @@ class FinderTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_exists_passing_active_record_object_is_not_permitted
|
def test_exists_passing_active_record_object_is_not_permitted
|
||||||
assert_raises(ArgumentError) do
|
error = assert_raises(ArgumentError) do
|
||||||
Topic.exists?(Topic.new)
|
Topic.exists?(Topic.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert_equal "You are passing an instance of ActiveRecord::Base to `exists?`. " \
|
||||||
|
"Please pass the id of the object by calling `.id`.", error.message
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_exists_does_not_select_columns_without_alias
|
def test_exists_does_not_select_columns_without_alias
|
||||||
|
|
|
@ -53,6 +53,17 @@ class PersistenceTest < ActiveRecord::TestCase
|
||||||
assert_not_equal "2 updated", Topic.find(2).content
|
assert_not_equal "2 updated", Topic.find(2).content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_update_many_with_active_record_base_object
|
||||||
|
error = assert_raises(ArgumentError) do
|
||||||
|
Topic.update(Topic.first, "content" => "1 updated")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal "You are passing an instance of ActiveRecord::Base to `update`. " \
|
||||||
|
"Please pass the id of the object by calling `.id`.", error.message
|
||||||
|
|
||||||
|
assert_not_equal "1 updated", Topic.first.content
|
||||||
|
end
|
||||||
|
|
||||||
def test_class_level_update_without_ids
|
def test_class_level_update_without_ids
|
||||||
topics = Topic.all
|
topics = Topic.all
|
||||||
assert_equal 5, topics.length
|
assert_equal 5, topics.length
|
||||||
|
|
Loading…
Reference in a new issue