Skip to content

Commit

Permalink
use existing model for testing Base.create with #after_initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Jul 24, 2011
1 parent 6e3c0a5 commit f5e4d13
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
16 changes: 7 additions & 9 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -21,7 +21,7 @@
require 'models/person' require 'models/person'
require 'models/edge' require 'models/edge'
require 'models/joke' require 'models/joke'
require 'models/wholesale_product' require 'models/bulb'
require 'rexml/document' require 'rexml/document'
require 'active_support/core_ext/exception' require 'active_support/core_ext/exception'


Expand Down Expand Up @@ -262,17 +262,15 @@ def test_initialize_with_invalid_attribute
end end


def test_create_after_initialize_without_block def test_create_after_initialize_without_block
wp = WholesaleProduct.create(:wholesale => 10) cb = CustomBulb.create(:name => 'Dude')
assert_equal(20, wp.msrp) assert_equal('Dude', cb.name)
assert_equal(10, wp.wholesale) assert_equal(true, cb.frickinawesome)
end end


def test_create_after_initialize_with_block def test_create_after_initialize_with_block
wp = WholesaleProduct.create do |w| cb = CustomBulb.create {|c| c.name = 'Dude' }
w.wholesale = 10 assert_equal('Dude', cb.name)
end assert_equal(true, cb.frickinawesome)
assert_equal(20, wp.msrp)
assert_equal(10, wp.wholesale)
end end


def test_load def test_load
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/models/bulb.rb
Expand Up @@ -33,4 +33,9 @@ def self.new(attributes = {}, options = {}, &block)
end end


class CustomBulb < Bulb class CustomBulb < Bulb
after_initialize :set_awesomeness

def set_awesomeness
self.frickinawesome = true if name == 'Dude'
end
end end
9 changes: 0 additions & 9 deletions activerecord/test/models/wholesale_product.rb

This file was deleted.

5 changes: 0 additions & 5 deletions activerecord/test/schema/schema.rb
Expand Up @@ -678,11 +678,6 @@ def create_table(*args, &block)
t.references :wheelable, :polymorphic => true t.references :wheelable, :polymorphic => true
end end


create_table :wholesale_products, :force => true do |t|
t.integer :msrp
t.integer :wholesale
end

create_table :zines, :force => true do |t| create_table :zines, :force => true do |t|
t.string :title t.string :title
end end
Expand Down

0 comments on commit f5e4d13

Please sign in to comment.