Permalink
Browse files

Ensure callbacks on traits are executed in the correct order

  • Loading branch information...
1 parent c93dea5 commit 65e5e25fc23f5790b695bc149e8e298de41e6d70 @joshuaclayton joshuaclayton committed Nov 23, 2011
Showing with 10 additions and 1 deletion.
  1. +1 −1 lib/factory_girl/factory.rb
  2. +9 −0 spec/acceptance/traits_spec.rb
@@ -115,7 +115,7 @@ def attributes
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 @@
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 @@
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

0 comments on commit 65e5e25

Please sign in to comment.