diff options
author | Gabriel Horner <gabriel.horner@gmail.com> | 2011-07-24 16:36:06 -0400 |
---|---|---|
committer | Gabriel Horner <gabriel.horner@gmail.com> | 2011-07-24 16:36:06 -0400 |
commit | f5e4d13270dbce2bb880ef6529da68aaee017910 (patch) | |
tree | cf096170ba99ed75c7444a4aadf33e859549ed9f | |
parent | 6e3c0a5d9a22a4a08628b3f72a6b4072e0a23405 (diff) | |
download | rails-f5e4d13270dbce2bb880ef6529da68aaee017910.tar.gz rails-f5e4d13270dbce2bb880ef6529da68aaee017910.tar.bz2 rails-f5e4d13270dbce2bb880ef6529da68aaee017910.zip |
use existing model for testing Base.create with #after_initialize
-rw-r--r-- | activerecord/test/cases/base_test.rb | 16 | ||||
-rw-r--r-- | activerecord/test/models/bulb.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/wholesale_product.rb | 9 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 5 |
4 files changed, 12 insertions, 23 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 5a64a1163b..f2f5b73626 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -21,7 +21,7 @@ require 'models/parrot' 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 @@ class BasicsTest < ActiveRecord::TestCase 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 diff --git a/activerecord/test/models/bulb.rb b/activerecord/test/models/bulb.rb index efb98b66e7..888afc7604 100644 --- a/activerecord/test/models/bulb.rb +++ b/activerecord/test/models/bulb.rb @@ -33,4 +33,9 @@ class Bulb < ActiveRecord::Base end class CustomBulb < Bulb + after_initialize :set_awesomeness + + def set_awesomeness + self.frickinawesome = true if name == 'Dude' + end end diff --git a/activerecord/test/models/wholesale_product.rb b/activerecord/test/models/wholesale_product.rb deleted file mode 100644 index 5c6c15391c..0000000000 --- a/activerecord/test/models/wholesale_product.rb +++ /dev/null @@ -1,9 +0,0 @@ -class WholesaleProduct < ActiveRecord::Base - - after_initialize :set_prices - - def set_prices - self.msrp = 2 * wholesale if wholesale - end - -end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index d2a41ed87a..64e0452100 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -678,11 +678,6 @@ ActiveRecord::Schema.define do 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 |