aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-04-28 11:03:18 +0200
committerYves Senn <yves.senn@gmail.com>2015-04-28 11:06:53 +0200
commitcdf3548a452bbe5cddaad0a398d4266b36f9e388 (patch)
tree690f96ea92f7fd0bee4f52341bec3f9c3674b7e6 /activerecord/test
parent7edf52062a1f12bbfdf831665e8c36bd24db793d (diff)
parent28375dd621befc495dfc77a6558534951be5ef54 (diff)
downloadrails-cdf3548a452bbe5cddaad0a398d4266b36f9e388.tar.gz
rails-cdf3548a452bbe5cddaad0a398d4266b36f9e388.tar.bz2
rails-cdf3548a452bbe5cddaad0a398d4266b36f9e388.zip
Merge pull request #19718 from eagletmt/find_by-without-arg
Raise ArgumentError when find_by receives no arguments
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/relations_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 0cf44388fa..b8e2041b6d 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1657,6 +1657,10 @@ class RelationTest < ActiveRecord::TestCase
assert_sql(/^((?!ORDER).)*$/) { Post.all.find_by(author_id: 2) }
end
+ test "find_by requires at least one argument" do
+ assert_raises(ArgumentError) { Post.all.find_by }
+ end
+
test "find_by! with hash conditions returns the first matching record" do
assert_equal posts(:eager_other), Post.order(:id).find_by!(author_id: 2)
end
@@ -1679,6 +1683,10 @@ class RelationTest < ActiveRecord::TestCase
end
end
+ test "find_by! requires at least one argument" do
+ assert_raises(ArgumentError) { Post.all.find_by! }
+ end
+
test "loaded relations cannot be mutated by multi value methods" do
relation = Post.all
relation.to_a