diff options
author | Gabriel Horner <gabriel.horner@gmail.com> | 2011-07-22 18:43:27 -0400 |
---|---|---|
committer | Gabriel Horner <gabriel.horner@gmail.com> | 2011-07-24 00:31:37 -0400 |
commit | 6e3c0a5d9a22a4a08628b3f72a6b4072e0a23405 (patch) | |
tree | 268ebfc61175f3afabeb6a5967887db0c12b87c3 /activerecord | |
parent | f956759f8ab656484add2d5bc6e8f6f4add79469 (diff) | |
download | rails-6e3c0a5d9a22a4a08628b3f72a6b4072e0a23405.tar.gz rails-6e3c0a5d9a22a4a08628b3f72a6b4072e0a23405.tar.bz2 rails-6e3c0a5d9a22a4a08628b3f72a6b4072e0a23405.zip |
simplify and be more explicit about create and after_initialize tests
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 28 | ||||
-rw-r--r-- | activerecord/test/models/wholesale_product.rb | 8 |
2 files changed, 12 insertions, 24 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 934f0c8f74..5a64a1163b 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -261,26 +261,18 @@ 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) + def test_create_after_initialize_without_block + wp = WholesaleProduct.create(:wholesale => 10) + assert_equal(20, wp.msrp) + assert_equal(10, wp.wholesale) + end - wp4 = WholesaleProduct.create do |wp| - wp.wholesale = 10 + def test_create_after_initialize_with_block + wp = WholesaleProduct.create do |w| + w.wholesale = 10 end - assert_equal(20, wp4.msrp) - assert_equal(10, wp4.wholesale) + assert_equal(20, wp.msrp) + assert_equal(10, wp.wholesale) end def test_load diff --git a/activerecord/test/models/wholesale_product.rb b/activerecord/test/models/wholesale_product.rb index e1a1a4c8b1..5c6c15391c 100644 --- a/activerecord/test/models/wholesale_product.rb +++ b/activerecord/test/models/wholesale_product.rb @@ -3,11 +3,7 @@ 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 + self.msrp = 2 * wholesale if wholesale end -end
\ No newline at end of file +end |