Permalink
Browse files

use existing model for testing Base.create with #after_initialize

  • Loading branch information...
1 parent 6e3c0a5 commit f5e4d13270dbce2bb880ef6529da68aaee017910 @cldwalker committed Jul 24, 2011
@@ -21,7 +21,7 @@
require 'models/person'
require 'models/edge'
require 'models/joke'
-require 'models/wholesale_product'
+require 'models/bulb'
require 'rexml/document'
require 'active_support/core_ext/exception'
@@ -262,17 +262,15 @@ def test_initialize_with_invalid_attribute
end
def test_create_after_initialize_without_block
- wp = WholesaleProduct.create(:wholesale => 10)
- assert_equal(20, wp.msrp)
- assert_equal(10, wp.wholesale)
+ cb = CustomBulb.create(:name => 'Dude')
+ assert_equal('Dude', cb.name)
+ assert_equal(true, cb.frickinawesome)
end
def test_create_after_initialize_with_block
- wp = WholesaleProduct.create do |w|
- w.wholesale = 10
- end
- assert_equal(20, wp.msrp)
- assert_equal(10, wp.wholesale)
+ cb = CustomBulb.create {|c| c.name = 'Dude' }
+ assert_equal('Dude', cb.name)
+ assert_equal(true, cb.frickinawesome)
end
def test_load
@@ -33,4 +33,9 @@ def self.new(attributes = {}, options = {}, &block)
end
class CustomBulb < Bulb
+ after_initialize :set_awesomeness
+
+ def set_awesomeness
+ self.frickinawesome = true if name == 'Dude'
+ end
end
@@ -1,9 +0,0 @@
-class WholesaleProduct < ActiveRecord::Base
-
- after_initialize :set_prices
-
- def set_prices
- self.msrp = 2 * wholesale if wholesale
- end
-
-end
@@ -678,11 +678,6 @@ def create_table(*args, &block)
t.references :wheelable, :polymorphic => true
end
- create_table :wholesale_products, :force => true do |t|
- t.integer :msrp
- t.integer :wholesale
- end
-
create_table :zines, :force => true do |t|
t.string :title
end

0 comments on commit f5e4d13

Please sign in to comment.