diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-27 14:28:19 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-27 14:28:19 +0530 |
commit | d511de0261003aae4913e3c24f76df6e03a35916 (patch) | |
tree | 56b9885b07709efd1df16611fa733030df5c29ea /activerecord/test/cases | |
parent | 8829d6ecc6b3e1a36a41decaf8237f6024be2c06 (diff) | |
download | rails-d511de0261003aae4913e3c24f76df6e03a35916.tar.gz rails-d511de0261003aae4913e3c24f76df6e03a35916.tar.bz2 rails-d511de0261003aae4913e3c24f76df6e03a35916.zip |
Add find_or_create_by_* and find_or_initialize_by_* to relations
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index f94402f57e..893ac9caf8 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -254,5 +254,26 @@ class RelationTest < ActiveRecord::TestCase assert_kind_of Array, davids assert_equal [authors(:david)], davids end + + def test_dynamic_find_or_initialize_by_attributes + authors = Author.scoped + + lifo = authors.find_or_initialize_by_name('Lifo') + assert_equal "Lifo", lifo.name + assert lifo.new_record? + + assert_equal authors(:david), authors.find_or_initialize_by_name(:name => 'David') + end + + def test_dynamic_find_or_create_by_attributes + authors = Author.scoped + + lifo = authors.find_or_create_by_name('Lifo') + assert_equal "Lifo", lifo.name + assert ! lifo.new_record? + + assert_equal authors(:david), authors.find_or_create_by_name(:name => 'David') + end + end |