aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorNikita Afanasenko <nafanasenko@spbtv.com>2012-11-13 21:19:48 +0400
committerNikita Afanasenko <nafanasenko@spbtv.com>2012-11-13 21:24:58 +0400
commitb56376b4509073a0ef7fc0a44e51619f1bf11d8e (patch)
tree5fa67deccfb2488297c1687deebcdf883cf1b5d1 /activerecord/test
parent5ed0381db5e6dff1269f3f22ec4fa69c203c37d9 (diff)
downloadrails-b56376b4509073a0ef7fc0a44e51619f1bf11d8e.tar.gz
rails-b56376b4509073a0ef7fc0a44e51619f1bf11d8e.tar.bz2
rails-b56376b4509073a0ef7fc0a44e51619f1bf11d8e.zip
Use nil? instead of blank? to check dynamic finder result
It's safe to use `nil?` instead of `blank?` because it's impossible to get an array on finder with bang; `all_by` finder matches against regex without bang: `when /^find_(all_|last_)?by_([_a-zA-Z]\w*)$/`. Fixes #7238
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/finder_test.rb5
-rw-r--r--activerecord/test/models/topic.rb6
2 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 5d72e35c60..e50a334958 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -652,6 +652,11 @@ class FinderTest < ActiveRecord::TestCase
assert_raise(ActiveRecord::RecordNotFound) { Topic.find_by_title!("The First Topic!") }
end
+ def test_find_by_one_attribute_bang_with_blank_defined
+ blank_topic = BlankTopic.create(:title => "The Blank One")
+ assert_equal blank_topic, BlankTopic.find_by_title!("The Blank One")
+ end
+
def test_find_by_one_attribute_with_order_option
assert_equal accounts(:signals37), Account.find_by_credit_limit(50, :order => 'id')
assert_equal accounts(:rails_core_account), Account.find_by_credit_limit(50, :order => 'id DESC')
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb
index 1a1a18166a..5166fefe81 100644
--- a/activerecord/test/models/topic.rb
+++ b/activerecord/test/models/topic.rb
@@ -112,6 +112,12 @@ class ImportantTopic < Topic
serialize :important, Hash
end
+class BlankTopic < Topic
+ def blank?
+ true
+ end
+end
+
module Web
class Topic < ActiveRecord::Base
has_many :replies, :dependent => :destroy, :foreign_key => "parent_id", :class_name => 'Web::Reply'