Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

simplify and be more explicit about create and after_initialize tests

  • Loading branch information...
commit 6e3c0a5d9a22a4a08628b3f72a6b4072e0a23405 1 parent f956759
@cldwalker authored
View
28 activerecord/test/cases/base_test.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
View
8 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
+end
Please sign in to comment.
Something went wrong with that request. Please try again.