Permalink
Browse files

fix FactoryRunner#run bug re: uncompiled factory

  • Loading branch information...
barunio authored and joshuaclayton committed Mar 9, 2012
1 parent 87c1ddb commit 68ca50f4a6a2f05f200fb19432a59c77c2f35ee9
Showing with 28 additions and 0 deletions.
  1. +2 −0 lib/factory_girl/factory_runner.rb
  2. +24 −0 spec/acceptance/traits_spec.rb
  3. +2 −0 spec/support/shared_examples/strategy.rb
@@ -16,6 +16,8 @@ def run(strategy_override = nil, &block)
strategy_override ||= @strategy
factory = FactoryGirl.factory_by_name(@name)
+ factory.compile
+
if @traits.any?
factory = factory.with_traits(@traits)
end
@@ -395,3 +395,27 @@
FactoryGirl.build(:extended_declined_user, :accepted, :status => "completely overridden").status.should == "completely overridden"
end
end
+
+describe "making sure the factory is properly compiled the first time we want to instantiate it" do
+ before do
+ define_model("User", :role => :string, :gender => :string, :age => :integer)
+
+ FactoryGirl.define do
+ factory :user do
+ trait(:female) { gender "female" }
+ trait(:admin) { role "admin" }
+
+ factory :female_user do
+ female
+ end
+ end
+ end
+ end
+
+ it "can honor traits on the very first call" do
+ user = FactoryGirl.build(:female_user, :admin, :age => 30)
+ user.gender.should == 'female'
+ user.age.should == 30
+ user.role.should == 'admin'
+ end
+end
@@ -27,6 +27,7 @@ def association_named(name, strategy, overrides)
before do
FactoryGirl.stubs(:factory_by_name => factory)
+ factory.stubs(:compile)
factory.stubs(:run)
end
@@ -52,6 +53,7 @@ def association_named(name, overrides)
before do
FactoryGirl.stubs(:factory_by_name => factory)
+ factory.stubs(:compile)
factory.stubs(:run)
end

0 comments on commit 68ca50f

Please sign in to comment.