Skip to content

Commit

Permalink
Non-overriden parent dynamic methods should be assigned before the ch…
Browse files Browse the repository at this point in the history
…ild's

Closes #173
  • Loading branch information
twalpole authored and joshuaclayton committed Aug 9, 2011
1 parent 4b83b1e commit 2ccbf45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/factory_girl/factory.rb
Expand Up @@ -50,7 +50,7 @@ def inherit_from(parent) #:nodoc:
end
end

@attributes += new_attributes
@attributes.unshift *new_attributes
@attributes.sort!
end

Expand Down
14 changes: 8 additions & 6 deletions spec/acceptance/parent_spec.rb
Expand Up @@ -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
Expand All @@ -13,6 +13,7 @@
factory :admin do
name "admin"
admin true
upper_email { email.upcase }
end

factory :guest do
Expand All @@ -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
Expand Down

0 comments on commit 2ccbf45

Please sign in to comment.