Use a null strategy so association behaves in a similar way across all strategy subclasses

This commit is contained in:
Joshua Clayton 2012-03-30 17:30:20 -04:00
parent 24d417d575
commit 7f5acac32c
4 changed files with 20 additions and 6 deletions

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,11 @@
module FactoryGirl
class Strategy
class Null
def association(runner)
end
def result(attribute_assigner, to_create)
end
end
end
end

View File

@ -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