aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2008-08-25 19:32:19 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-08-25 23:32:20 -0700
commit143f5fbb21b6dfcaab63d67b44afd922dab9dcf5 (patch)
tree25551d412c07795edc2782035228f430c0290927 /activerecord/test
parent3beed9cdb7cf2cf75fb043b72ca99cc23fc11556 (diff)
downloadrails-143f5fbb21b6dfcaab63d67b44afd922dab9dcf5.tar.gz
rails-143f5fbb21b6dfcaab63d67b44afd922dab9dcf5.tar.bz2
rails-143f5fbb21b6dfcaab63d67b44afd922dab9dcf5.zip
refactor dynamic finder name matching into its own class
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/finder_test.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index b97db73b68..875d56f6c1 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -12,6 +12,48 @@ require 'models/customer'
require 'models/job'
require 'models/categorization'
+class DynamicFinderMatchTest < ActiveRecord::TestCase
+ def test_find_no_match
+ assert_nil ActiveRecord::DynamicFinderMatch.match("not_a_finder")
+ end
+
+ def test_find_by
+ 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 %w(age sex location), match.attribute_names
+ end
+
+ def test_find_all_by
+ 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 %w(age sex location), match.attribute_names
+ end
+
+ def test_find_or_initialize_by
+ match = ActiveRecord::DynamicFinderMatch.match("find_or_initialize_by_age_and_sex_and_location")
+ assert_not_nil match
+ assert !match.finder?
+ assert match.instantiator?
+ assert_equal :find_initial, match.finder
+ assert_equal :new, match.instantiator
+ assert_equal %w(age sex location), match.attribute_names
+ end
+
+ def test_find_or_create_by
+ match = ActiveRecord::DynamicFinderMatch.match("find_or_create_by_age_and_sex_and_location")
+ assert_not_nil match
+ assert !match.finder?
+ assert match.instantiator?
+ assert_equal :find_initial, match.finder
+ assert_equal :create, match.instantiator
+ assert_equal %w(age sex location), match.attribute_names
+ end
+end
+
class FinderTest < ActiveRecord::TestCase
fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers