diff --git a/lib/factory_girl/strategy.rb b/lib/factory_girl/strategy.rb index 7944c71..89cb5d6 100644 --- a/lib/factory_girl/strategy.rb +++ b/lib/factory_girl/strategy.rb @@ -2,6 +2,7 @@ require "factory_girl/strategy/build" require "factory_girl/strategy/create" require "factory_girl/strategy/attributes_for" require "factory_girl/strategy/stub" +require "factory_girl/strategy/null" require "observer" module FactoryGirl diff --git a/lib/factory_girl/strategy/attributes_for.rb b/lib/factory_girl/strategy/attributes_for.rb index 6fb51fc..cc17a32 100644 --- a/lib/factory_girl/strategy/attributes_for.rb +++ b/lib/factory_girl/strategy/attributes_for.rb @@ -2,6 +2,7 @@ module FactoryGirl class Strategy #:nodoc: class AttributesFor < Strategy #:nodoc: def association(runner) + runner.run(Strategy::Null) end def result(attribute_assigner, to_create) diff --git a/lib/factory_girl/strategy/null.rb b/lib/factory_girl/strategy/null.rb new file mode 100644 index 0000000..a74afd2 --- /dev/null +++ b/lib/factory_girl/strategy/null.rb @@ -0,0 +1,11 @@ +module FactoryGirl + class Strategy + class Null + def association(runner) + end + + def result(attribute_assigner, to_create) + end + end + end +end diff --git a/spec/support/shared_examples/strategy.rb b/spec/support/shared_examples/strategy.rb index ffdea62..0aa7408 100644 --- a/spec/support/shared_examples/strategy.rb +++ b/spec/support/shared_examples/strategy.rb @@ -1,4 +1,5 @@ shared_examples_for "strategy without association support" do + let(:factory) { stub("associate_factory") } let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) } def association_named(name, overrides) @@ -6,14 +7,14 @@ shared_examples_for "strategy without association support" do subject.association(runner) end - it "returns nil when accessing an association" do - association_named(:user, {}).should be_nil + before do + FactoryGirl.stubs(factory_by_name: factory) + factory.stubs(:compile) + factory.stubs(:run) end - it "does not attempt to look up the factory when accessing the association" do - FactoryGirl.stubs(:factory_by_name) - association_named(:awesome, {}) - FactoryGirl.should have_received(:factory_by_name).never + it "returns nil when accessing an association" do + association_named(:user, {}).should be_nil end end