Skip to content
Browse files

Default strategy is inherited from parent unless overridden

  • Loading branch information...
1 parent 3e577f3 commit 434f67b236382cb9e5f69f6a695e190d46098f1e @jtrupiano jtrupiano committed with tristandunn
Showing with 22 additions and 1 deletion.
  1. +2 −1 lib/factory_girl/factory.rb
  2. +20 −0 spec/factory_girl/factory_spec.rb
View
3 lib/factory_girl/factory.rb
@@ -83,7 +83,8 @@ def initialize (name, options = {}) #:nodoc:
end
def inherit_from(parent) #:nodoc:
- @options[:class] ||= parent.class_name
+ @options[:class] ||= parent.class_name
+ @options[:default_strategy] ||= parent.default_strategy
parent.attributes.each do |attribute|
unless attribute_defined?(attribute.name)
@attributes << attribute.clone
View
20 spec/factory_girl/factory_spec.rb
@@ -545,6 +545,26 @@ class Other; end
factory = Factory.define(:object, :default_strategy => :stub) {}
factory.default_strategy.should == :stub
end
+
+ describe 'defining a child factory without setting default strategy' do
+ before do
+ @child = Factory.define(:child_object, :parent => :object) {}
+ end
+
+ it "should inherit default strategy from its parent" do
+ @child.default_strategy.should == :stub
+ end
+ end
+
+ describe 'defining a child factory with a default strategy' do
+ before do
+ @child2 = Factory.define(:child_object2, :parent => :object, :default_strategy => :build) {}
+ end
+
+ it "should not inherit default strategy from parent" do
+ @child2.default_strategy.should == :build
+ end
+ end
end
def self.in_directory_with_files(*files)

0 comments on commit 434f67b

Please sign in to comment.
Something went wrong with that request. Please try again.