mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
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
This commit is contained in:
parent
a883315bc4
commit
70a80fde58
2 changed files with 27 additions and 0 deletions
|
@ -152,6 +152,7 @@ module FactoryGirl
|
|||
def initialize_copy(source)
|
||||
super
|
||||
@definition = @definition.clone
|
||||
@evaluator_class = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -286,3 +286,29 @@ describe "traits and dynamic attributes that are applied simultaneously" do
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue