aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorEloy Duran <eloy.de.enige@gmail.com>2008-10-03 13:55:35 +0200
committerMichael Koziarski <michael@koziarski.com>2008-10-03 21:28:11 +0200
commit8d337e9ec2e25007d557150dbe7557ab3c3bd05f (patch)
tree35bc7945e1b9230a988238a7bdbbbd01e9069314 /activerecord/test/cases
parente69b506abd40222c87be28398c5191db160740cb (diff)
downloadrails-8d337e9ec2e25007d557150dbe7557ab3c3bd05f.tar.gz
rails-8d337e9ec2e25007d557150dbe7557ab3c3bd05f.tar.bz2
rails-8d337e9ec2e25007d557150dbe7557ab3c3bd05f.zip
Dynamic finders should use the ActiveRecord::Base::find method instead of ::find_initial, :find_last, and ::find_all.
This is so when people override ActiveRecord::Base::find, the new ::find method will also be invoked by the dynamic finders. Associations for instance do go through ::find, so this makes it more consistent. Also removed the unnecessary deprecation silence blocks. Signed-off-by: Michael Koziarski <michael@koziarski.com> [#1162 state:committed]
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/finder_test.rb27
1 files changed, 22 insertions, 5 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 292b88edbc..853474916c 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -21,7 +21,7 @@ class DynamicFinderMatchTest < ActiveRecord::TestCase
match = ActiveRecord::DynamicFinderMatch.match("find_by_age_and_sex_and_location")
assert_not_nil match
assert match.finder?
- assert_equal :find_initial, match.finder
+ assert_equal :first, match.finder
assert_equal %w(age sex location), match.attribute_names
end
@@ -30,7 +30,7 @@ class DynamicFinderMatchTest < ActiveRecord::TestCase
assert_not_nil match
assert match.finder?
assert match.bang?
- assert_equal :find_initial, match.finder
+ assert_equal :first, match.finder
assert_equal %w(age sex location), match.attribute_names
end
@@ -38,7 +38,7 @@ class DynamicFinderMatchTest < ActiveRecord::TestCase
match = ActiveRecord::DynamicFinderMatch.match("find_all_by_age_and_sex_and_location")
assert_not_nil match
assert match.finder?
- assert_equal :find_every, match.finder
+ assert_equal :all, match.finder
assert_equal %w(age sex location), match.attribute_names
end
@@ -47,7 +47,7 @@ class DynamicFinderMatchTest < ActiveRecord::TestCase
assert_not_nil match
assert !match.finder?
assert match.instantiator?
- assert_equal :find_initial, match.finder
+ assert_equal :first, match.finder
assert_equal :new, match.instantiator
assert_equal %w(age sex location), match.attribute_names
end
@@ -57,7 +57,7 @@ class DynamicFinderMatchTest < ActiveRecord::TestCase
assert_not_nil match
assert !match.finder?
assert match.instantiator?
- assert_equal :find_initial, match.finder
+ assert_equal :first, match.finder
assert_equal :create, match.instantiator
assert_equal %w(age sex location), match.attribute_names
end
@@ -500,6 +500,23 @@ class FinderTest < ActiveRecord::TestCase
assert_equal(2, Entrant.count_by_sql(["SELECT COUNT(*) FROM entrants WHERE id > ?", 1]))
end
+ uses_mocha('test_dynamic_finder_should_go_through_the_find_class_method') do
+ def test_dynamic_finders_should_go_through_the_find_class_method
+ Topic.expects(:find).with(:first, :conditions => { :title => 'The First Topic!' })
+ Topic.find_by_title("The First Topic!")
+
+ Topic.expects(:find).with(:last, :conditions => { :title => 'The Last Topic!' })
+ Topic.find_last_by_title("The Last Topic!")
+
+ Topic.expects(:find).with(:all, :conditions => { :title => 'A Topic.' })
+ Topic.find_all_by_title("A Topic.")
+
+ Topic.expects(:find).with(:first, :conditions => { :title => 'Does not exist yet for sure!' }).times(2)
+ Topic.find_or_initialize_by_title('Does not exist yet for sure!')
+ Topic.find_or_create_by_title('Does not exist yet for sure!')
+ end
+ end
+
def test_find_by_one_attribute
assert_equal topics(:first), Topic.find_by_title("The First Topic")
assert_nil Topic.find_by_title("The First Topic!")