Skip to content

Commit

Permalink
Removed the build instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jan 2, 2009
1 parent 4313763 commit e80164e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 49 deletions.
4 changes: 0 additions & 4 deletions lib/factory_girl/factory.rb
Expand Up @@ -121,10 +121,6 @@ def association (name, options = {})
add_attribute(name) {|a| a.association(association_factory) }
end

def build (overrides = {}) #:nodoc:
run_strategy(Strategy::Build, overrides)
end

def create (overrides = {}) #:nodoc:
run_strategy(Strategy::Create, overrides)
end
Expand Down
49 changes: 4 additions & 45 deletions test/factory_test.rb
Expand Up @@ -14,7 +14,8 @@ def self.should_instantiate_class

should "override attributes using the passed hash" do
@value = 'Davis'
@instance = @factory.build(:first_name => @value)
@instance = @factory.run_strategy(Factory::Strategy::Build,
:first_name => @value)
assert_equal @value, @instance.first_name
end
end
Expand Down Expand Up @@ -150,7 +151,7 @@ def self.should_instantiate_class

should "create a block that builds the association" do
Factory.expects(:create).with(@name, {})
@factory.build
@factory.run_strategy(Factory::Strategy::Build, {})
end
end

Expand All @@ -170,7 +171,7 @@ def self.should_instantiate_class

should "create a block that builds the association" do
Factory.expects(:create).with(@factory_name, {})
@factory.build
@factory.run_strategy(Factory::Strategy::Build, {})
end
end

Expand Down Expand Up @@ -266,48 +267,6 @@ def self.should_instantiate_class
assert_equal @class, @factory.build_class
end
end

context "with some attributes added" do
setup do
@first_name = 'Billy'
@last_name = 'Idol'
@email = 'test@something.com'

@factory.add_attribute(:first_name, @first_name)
@factory.add_attribute(:last_name, @last_name)
@factory.add_attribute(:email, @email)
end

context "when building an instance" do
setup do
@instance = @factory.build
end

should_instantiate_class

should "not save the instance" do
assert @instance.new_record?
end
end

context "when creating an instance" do
setup do
@instance = @factory.create
end

should_instantiate_class

should "save the instance" do
assert !@instance.new_record?
end
end

should "raise an error for invalid instances" do
assert_raise(ActiveRecord::RecordInvalid) do
@factory.create(:first_name => nil)
end
end
end
end

context "a factory with a name ending in s" do
Expand Down

0 comments on commit e80164e

Please sign in to comment.