Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reset evaluator class when cloning a FactoryGirl::Factory

Applying traits inline modifies the evaluator class, so it needs to be
reset when cloning in order to ensure that the attributes are correct.

Closes #268
  • Loading branch information...
commit 70a80fde5845749ae8404bd70b81c5d6183f68fd 1 parent a883315
@joshuaclayton joshuaclayton authored
Showing with 27 additions and 0 deletions.
  1. +1 −0  lib/factory_girl/factory.rb
  2. +26 −0 spec/acceptance/traits_spec.rb
View
1  lib/factory_girl/factory.rb
@@ -152,6 +152,7 @@ def parent
def initialize_copy(source)
super
@definition = @definition.clone
+ @evaluator_class = nil
end
end
end
View
26 spec/acceptance/traits_spec.rb
@@ -286,3 +286,29 @@
its(:email) { should == "John@example.com" }
its(:combined) { should == "John <John@example.com>" }
end
+
+describe "applying inline traits" do
+ before do
+ define_model("User") do
+ has_many :posts
+ end
+
+ define_model("Post", :user_id => :integer) do
+ belongs_to :user
+ end
+
+ FactoryGirl.define do
+ factory :user do
+ trait :with_post do
+ posts { [ Post.new ] }
+ end
+ end
+ end
+ end
+
+ it "applies traits only to the instance generated for that call" do
+ FactoryGirl.create(:user, :with_post).posts.should_not be_empty
+ FactoryGirl.create(:user).posts.should be_empty
+ FactoryGirl.create(:user, :with_post).posts.should_not be_empty
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.