aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorMarcelo Silveira <marcelo@mhfs.com.br>2012-05-05 12:07:20 -0300
committerMarcelo Silveira <marcelo@mhfs.com.br>2012-05-05 12:10:52 -0300
commit56bf1f74557e68455552eeac1bc975cf9ba57766 (patch)
tree5f3f5013aba1129a035b074a49e17fd59f3fe25b /activerecord/test/cases/relations_test.rb
parentacb39848ae4cfe1d22cd8a83c5db636d80c22b47 (diff)
downloadrails-56bf1f74557e68455552eeac1bc975cf9ba57766.tar.gz
rails-56bf1f74557e68455552eeac1bc975cf9ba57766.tar.bz2
rails-56bf1f74557e68455552eeac1bc975cf9ba57766.zip
Use `take` instead of `first` to avoid unwanted implicit ordering (fixes #6147)
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 3ef357e297..8cef4423c5 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -255,7 +255,7 @@ class RelationTest < ActiveRecord::TestCase
assert_equal nil, Developer.none.calculate(:average, 'salary')
end
end
-
+
def test_null_relation_metadata_methods
assert_equal "", Developer.none.to_sql
assert_equal({}, Developer.none.where_values_hash)
@@ -1287,6 +1287,10 @@ class RelationTest < ActiveRecord::TestCase
assert_equal nil, Post.scoped.find_by("1 = 0")
end
+ test "find_by doesn't have implicit ordering" do
+ assert_sql(/^((?!ORDER).)*$/) { Post.find_by(author_id: 2) }
+ 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
@@ -1299,6 +1303,10 @@ class RelationTest < ActiveRecord::TestCase
assert_equal posts(:eager_other), Post.order(:id).find_by!('author_id = ?', 2)
end
+ test "find_by! doesn't have implicit ordering" do
+ assert_sql(/^((?!ORDER).)*$/) { Post.find_by!(author_id: 2) }
+ end
+
test "find_by! raises RecordNotFound if the record is missing" do
assert_raises(ActiveRecord::RecordNotFound) do
Post.scoped.find_by!("1 = 0")