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:
parent
c93dea5ad6
commit
65e5e25fc2
2 changed files with 10 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue