From 90d96353e6dcd962b182e03f53f2214acde00907 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 12 Mar 2012 11:39:19 +0000 Subject: 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 --- activerecord/test/cases/relations_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/test/cases/relations_test.rb') 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 -- cgit v1.2.3