aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/wholesale_product.rb
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/models/wholesale_product.rb
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/models/wholesale_product.rb')
-rw-r--r--activerecord/test/models/wholesale_product.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/models/wholesale_product.rb b/activerecord/test/models/wholesale_product.rb
new file mode 100644
index 0000000000..e1a1a4c8b1
--- /dev/null
+++ b/activerecord/test/models/wholesale_product.rb
@@ -0,0 +1,13 @@
+class WholesaleProduct < ActiveRecord::Base
+
+ after_initialize :set_prices
+
+ def set_prices
+ if msrp.nil? && !wholesale.nil?
+ self.msrp = 2 * wholesale
+ elsif !msrp.nil? && wholesale.nil?
+ self.wholesale = msrp / 2
+ end
+ end
+
+end \ No newline at end of file