Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding test cases for the dynamic finder matcher match method
- Loading branch information
1 parent
65d7431
commit 526ade1
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |