aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-03 00:16:14 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-03 00:16:14 +0530
commitac1df91e5eac4959c0030e2b2ea39968f7f9ba1a (patch)
treead99ec835442f60f25d5055e1466080bc173c8a1 /activerecord/test/cases
parent65200d2933bd337b8347dd32502a12c2fddf24f0 (diff)
downloadrails-ac1df91e5eac4959c0030e2b2ea39968f7f9ba1a.tar.gz
rails-ac1df91e5eac4959c0030e2b2ea39968f7f9ba1a.tar.bz2
rails-ac1df91e5eac4959c0030e2b2ea39968f7f9ba1a.zip
Implement Relation#create and Relation#create!
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/relations_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index c4b2c21578..bea2946130 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -10,6 +10,7 @@ require 'models/comment'
require 'models/entrant'
require 'models/developer'
require 'models/company'
+require 'models/bird'
class RelationTest < ActiveRecord::TestCase
fixtures :authors, :topics, :entrants, :developers, :companies, :developers_projects, :accounts, :categories, :categorizations, :posts, :comments,
@@ -493,4 +494,27 @@ class RelationTest < ActiveRecord::TestCase
assert_equal 'You told a lie', post.title
end
+ def test_create
+ birds = Bird.scoped
+
+ sparrow = birds.create
+ assert_kind_of Bird, sparrow
+ assert sparrow.new_record?
+
+ hen = birds.where(:name => 'hen').create
+ assert ! hen.new_record?
+ assert_equal 'hen', hen.name
+ end
+
+ def test_create_bang
+ birds = Bird.scoped
+
+ assert_raises(ActiveRecord::RecordInvalid) { birds.create! }
+
+ hen = birds.where(:name => 'hen').create!
+ assert_kind_of Bird, hen
+ assert ! hen.new_record?
+ assert_equal 'hen', hen.name
+ end
+
end