diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2012-03-12 11:39:19 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-03-12 14:12:22 +0000 |
commit | 90d96353e6dcd962b182e03f53f2214acde00907 (patch) | |
tree | 8279d07b64cc468003f982847689a0ecb79b179f /activerecord/test/cases/relations_test.rb | |
parent | 2b9041ba96375467717a79b0d2c5e6ecca038b5e (diff) | |
download | rails-90d96353e6dcd962b182e03f53f2214acde00907.tar.gz rails-90d96353e6dcd962b182e03f53f2214acde00907.tar.bz2 rails-90d96353e6dcd962b182e03f53f2214acde00907.zip |
Add dynamic find_or_create_by_{attribute}! method.
(cherry picked from commit 5282485d310d1a6ffcf55e4e7f56ab234e16880d)
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/dynamic_finder_match.rb
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index bf1eb6386a..5e0caf5fce 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -449,6 +449,18 @@ class RelationTest < ActiveRecord::TestCase assert_equal authors(:david), authors.find_or_create_by_name(:name => 'David') end + def test_dynamic_find_or_create_by_attributes_bang + authors = Author.scoped + + assert_raises(ActiveRecord::RecordInvalid) { authors.find_or_create_by_name!('') } + + lifo = authors.find_or_create_by_name!('Lifo') + assert_equal "Lifo", lifo.name + assert lifo.persisted? + + assert_equal authors(:david), authors.find_or_create_by_name!(:name => 'David') + end + def test_find_id authors = Author.scoped |