aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-27 17:59:28 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-27 17:59:28 -0700
commit526ade1ff63ba1fcb32250841b29c95ae4cb9de9 (patch)
tree790155c13d362712ec5d5275a7203f9c0329f400 /activerecord/test
parent65d74312c86c09ab59af7ff9414db901aa6164f0 (diff)
downloadrails-526ade1ff63ba1fcb32250841b29c95ae4cb9de9.tar.gz
rails-526ade1ff63ba1fcb32250841b29c95ae4cb9de9.tar.bz2
rails-526ade1ff63ba1fcb32250841b29c95ae4cb9de9.zip
adding test cases for the dynamic finder matcher match method
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/dynamic_finder_match_test.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/activerecord/test/cases/dynamic_finder_match_test.rb b/activerecord/test/cases/dynamic_finder_match_test.rb
new file mode 100644
index 0000000000..64bf6cb508
--- /dev/null
+++ b/activerecord/test/cases/dynamic_finder_match_test.rb
@@ -0,0 +1,49 @@
+require "cases/helper"
+
+module ActiveRecord
+ class DynamicFinderMatchTest < ActiveRecord::TestCase
+ def test_find_by
+ m = DynamicFinderMatch.match(:find_by_foo)
+ assert_equal :first, m.finder
+ assert_equal %w{ foo }, m.attribute_names
+ end
+
+ def test_find_all_by
+ m = DynamicFinderMatch.match(:find_all_by_foo)
+ assert_equal :all, m.finder
+ assert_equal %w{ foo }, m.attribute_names
+ end
+
+ def test_find_last_by
+ m = DynamicFinderMatch.match(:find_last_by_foo)
+ assert_equal :last, m.finder
+ assert_equal %w{ foo }, m.attribute_names
+ end
+
+ def test_find_by!
+ m = DynamicFinderMatch.match(:find_by_foo!)
+ assert_equal :first, m.finder
+ assert m.bang?, 'should be banging'
+ assert_equal %w{ foo }, m.attribute_names
+ end
+
+ def test_find_or_create
+ m = DynamicFinderMatch.match(:find_or_create_by_foo)
+ assert_equal :first, m.finder
+ assert_equal %w{ foo }, m.attribute_names
+ assert_equal :create, m.instantiator
+ end
+
+ def test_find_or_initialize
+ m = DynamicFinderMatch.match(:find_or_initialize_by_foo)
+ assert_equal :first, m.finder
+ assert_equal %w{ foo }, m.attribute_names
+ assert_equal :new, m.instantiator
+ end
+
+ def test_garbage
+ assert !DynamicFinderMatch.match(:fooo), 'should be false'
+ assert !DynamicFinderMatch.match(:find_by), 'should be false'
+ end
+ end
+end