Permalink
Browse files

Non-overriden parent dynamic methods should be assigned before the ch…

…ild's

Closes #173
  • Loading branch information...
1 parent 4b83b1e commit 2ccbf4561bbf61e9faf83e88c68b987bc1461ebd @twalpole twalpole committed with joshuaclayton Aug 8, 2011
Showing with 9 additions and 7 deletions.
  1. +1 −1 lib/factory_girl/factory.rb
  2. +8 −6 spec/acceptance/parent_spec.rb
View
2 lib/factory_girl/factory.rb
@@ -50,7 +50,7 @@ def inherit_from(parent) #:nodoc:
end
end
- @attributes += new_attributes
+ @attributes.unshift *new_attributes
@attributes.sort!
end
View
14 spec/acceptance/parent_spec.rb
@@ -3,7 +3,7 @@
describe "an instance generated by a factory that inherits from another factory" do
before do
- define_model("User", :name => :string, :admin => :boolean, :email => :string)
+ define_model("User", :name => :string, :admin => :boolean, :email => :string, :upper_email => :string)
FactoryGirl.define do
factory :user do
@@ -13,6 +13,7 @@
factory :admin do
name "admin"
admin true
+ upper_email { email.upcase }
end
factory :guest do
@@ -29,11 +30,12 @@
end
describe "the child class redefining parent's static method used by a dynamic method" do
- subject { FactoryGirl.create(:admin) }
- it { should be_kind_of(User) }
- it { should be_admin }
- its(:name) { should == "admin" }
- its(:email) { should == "admin@example.com" }
+ subject { FactoryGirl.create(:admin) }
+ it { should be_kind_of(User) }
+ it { should be_admin }
+ its(:name) { should == "admin" }
+ its(:email) { should == "admin@example.com" }
+ its(:upper_email) { should == "ADMIN@EXAMPLE.COM"}
end
describe "the child class redefining parent's dynamic method" do

0 comments on commit 2ccbf45

Please sign in to comment.