1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Ensure callbacks on traits are executed in the correct order

This commit is contained in:
Joshua Clayton 2011-11-23 18:40:35 -05:00
parent c93dea5ad6
commit 65e5e25fc2
2 changed files with 10 additions and 1 deletions

View file

@ -115,7 +115,7 @@ module FactoryGirl
end
def callbacks
[parent.callbacks, traits.map(&:callbacks), @definition.callbacks].flatten
[parent.callbacks, traits.map(&:callbacks).reverse, @definition.callbacks].flatten
end
private

View file

@ -181,7 +181,12 @@ describe "traits with callbacks" do
after_create {|user| user.name.upcase! }
end
trait :awesome do
after_create {|user| user.name = "awesome" }
end
factory :caps_user, :traits => [:great]
factory :awesome_user, :traits => [:great, :awesome]
factory :caps_user_implicit_trait do
great
@ -199,6 +204,10 @@ describe "traits with callbacks" do
subject { FactoryGirl.create(:caps_user_implicit_trait) }
its(:name) { should == "JOHN" }
end
it "executes callbacks in the order assigned" do
FactoryGirl.create(:awesome_user).name.should == "awesome"
end
end
describe "traits added via proxy" do