aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorLes Fletcher <les.fletcher@gmail.com>2011-07-21 01:36:02 -0700
committerGabriel Horner <gabriel.horner@gmail.com>2011-07-24 00:31:28 -0400
commitf956759f8ab656484add2d5bc6e8f6f4add79469 (patch)
tree3783716dfd568e2b9c61dfb4daf310031ebb0ef1 /activerecord/test/cases
parentd33eb07543aed1a07f9efe40ff7edc983b401957 (diff)
downloadrails-f956759f8ab656484add2d5bc6e8f6f4add79469.tar.gz
rails-f956759f8ab656484add2d5bc6e8f6f4add79469.tar.bz2
rails-f956759f8ab656484add2d5bc6e8f6f4add79469.zip
fix after_initialize edge case (close #2074 and close #2175)
fix behavior when after_initialize is defined and a block is passed to Base.create
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/base_test.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 8b4e7dd799..934f0c8f74 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -21,6 +21,7 @@ require 'models/parrot'
require 'models/person'
require 'models/edge'
require 'models/joke'
+require 'models/wholesale_product'
require 'rexml/document'
require 'active_support/core_ext/exception'
@@ -260,6 +261,28 @@ class BasicsTest < ActiveRecord::TestCase
end
end
+ def test_create_with_after_initialize
+ wp1 = WholesaleProduct.create(:msrp => 10)
+ assert_equal(10, wp1.msrp)
+ assert_equal(5, wp1.wholesale)
+
+ wp2 = WholesaleProduct.create(:wholesale => 10)
+ assert_equal(20, wp2.msrp)
+ assert_equal(10, wp2.wholesale)
+
+ wp3 = WholesaleProduct.create do |wp|
+ wp.msrp = 10
+ end
+ assert_equal(10, wp3.msrp)
+ assert_equal(5, wp3.wholesale)
+
+ wp4 = WholesaleProduct.create do |wp|
+ wp.wholesale = 10
+ end
+ assert_equal(20, wp4.msrp)
+ assert_equal(10, wp4.wholesale)
+ end
+
def test_load
topics = Topic.find(:all, :order => 'id')
assert_equal(4, topics.size)