aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-08-12 21:37:48 -0400
committerJosé Valim <jose.valim@gmail.com>2010-08-19 14:52:15 -0300
commit2e455429427a4078d2888cc39305f951bdf1e643 (patch)
treeb67aa66e66704aca116fd90f72144528aab563b4 /activerecord/test/cases
parent43f44c1a034497fef0a9ed64e0da6f090b5c3b7e (diff)
downloadrails-2e455429427a4078d2888cc39305f951bdf1e643.tar.gz
rails-2e455429427a4078d2888cc39305f951bdf1e643.tar.bz2
rails-2e455429427a4078d2888cc39305f951bdf1e643.zip
While creating a new record using has_many create method default scope of child should be respected.
author.posts.create should take into account default_scope defined on post. [#3939: state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 7e10a8ceeb..63fc15bca3 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -13,6 +13,8 @@ require 'models/reader'
require 'models/tagging'
require 'models/invoice'
require 'models/line_item'
+require 'models/car'
+require 'models/bulb'
class HasManyAssociationsTestForCountWithFinderSql < ActiveRecord::TestCase
class Invoice < ActiveRecord::Base
@@ -47,6 +49,23 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
Client.destroyed_client_ids.clear
end
+ def test_create_from_association_should_respect_default_scope
+ car = Car.create(:name => 'honda')
+ assert_equal 'honda', car.name
+
+ bulb = Bulb.create
+ assert_equal 'defaulty', bulb.name
+
+ bulb = car.bulbs.build
+ assert_equal 'defaulty', bulb.name
+
+ bulb = car.bulbs.create
+ assert_equal 'defaulty', bulb.name
+
+ bulb = car.bulbs.create(:name => 'exotic')
+ assert_equal 'exotic', bulb.name
+ end
+
def test_create_resets_cached_counters
person = Person.create!(:first_name => 'tenderlove')
post = Post.first