Permalink
Browse files

simplify and be more explicit about create and after_initialize tests

  • Loading branch information...
1 parent f956759 commit 6e3c0a5d9a22a4a08628b3f72a6b4072e0a23405 @cldwalker cldwalker committed Jul 22, 2011
Showing with 12 additions and 24 deletions.
  1. +10 −18 activerecord/test/cases/base_test.rb
  2. +2 −6 activerecord/test/models/wholesale_product.rb
@@ -261,26 +261,18 @@ def test_initialize_with_invalid_attribute
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
@@ -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
+end

0 comments on commit 6e3c0a5

Please sign in to comment.