Use a null strategy so association behaves in a similar way across all strategy subclasses
This commit is contained in:
parent
24d417d575
commit
7f5acac32c
|
@ -2,6 +2,7 @@ require "factory_girl/strategy/build"
|
||||||
require "factory_girl/strategy/create"
|
require "factory_girl/strategy/create"
|
||||||
require "factory_girl/strategy/attributes_for"
|
require "factory_girl/strategy/attributes_for"
|
||||||
require "factory_girl/strategy/stub"
|
require "factory_girl/strategy/stub"
|
||||||
|
require "factory_girl/strategy/null"
|
||||||
require "observer"
|
require "observer"
|
||||||
|
|
||||||
module FactoryGirl
|
module FactoryGirl
|
||||||
|
|
|
@ -2,6 +2,7 @@ module FactoryGirl
|
||||||
class Strategy #:nodoc:
|
class Strategy #:nodoc:
|
||||||
class AttributesFor < Strategy #:nodoc:
|
class AttributesFor < Strategy #:nodoc:
|
||||||
def association(runner)
|
def association(runner)
|
||||||
|
runner.run(Strategy::Null)
|
||||||
end
|
end
|
||||||
|
|
||||||
def result(attribute_assigner, to_create)
|
def result(attribute_assigner, to_create)
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
module FactoryGirl
|
||||||
|
class Strategy
|
||||||
|
class Null
|
||||||
|
def association(runner)
|
||||||
|
end
|
||||||
|
|
||||||
|
def result(attribute_assigner, to_create)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,5 @@
|
||||||
shared_examples_for "strategy without association support" do
|
shared_examples_for "strategy without association support" do
|
||||||
|
let(:factory) { stub("associate_factory") }
|
||||||
let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) }
|
let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) }
|
||||||
|
|
||||||
def association_named(name, overrides)
|
def association_named(name, overrides)
|
||||||
|
@ -6,14 +7,14 @@ shared_examples_for "strategy without association support" do
|
||||||
subject.association(runner)
|
subject.association(runner)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil when accessing an association" do
|
before do
|
||||||
association_named(:user, {}).should be_nil
|
FactoryGirl.stubs(factory_by_name: factory)
|
||||||
|
factory.stubs(:compile)
|
||||||
|
factory.stubs(:run)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not attempt to look up the factory when accessing the association" do
|
it "returns nil when accessing an association" do
|
||||||
FactoryGirl.stubs(:factory_by_name)
|
association_named(:user, {}).should be_nil
|
||||||
association_named(:awesome, {})
|
|
||||||
FactoryGirl.should have_received(:factory_by_name).never
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue