aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2012-03-12 11:39:19 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2012-03-12 14:16:19 +0000
commiteee32af45e7909c02370324833d7117fe9b6eb37 (patch)
tree628b5bb0a1babe14985122e18ef6ebd4b4a6d34c /activerecord/test/cases/relations_test.rb
parent1e2de2cb74088a4dda5799587530be63279cc9c8 (diff)
downloadrails-eee32af45e7909c02370324833d7117fe9b6eb37.tar.gz
rails-eee32af45e7909c02370324833d7117fe9b6eb37.tar.bz2
rails-eee32af45e7909c02370324833d7117fe9b6eb37.zip
Add dynamic find_or_create_by_{attribute}! method.
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 7b1d65c6db..acec230c72 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -462,6 +462,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