1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Don't refer to strategies by class anywhere

This commit is contained in:
Joshua Clayton 2012-04-25 14:29:02 -05:00
parent b84ccd9d09
commit 731a24e84a
7 changed files with 13 additions and 13 deletions

View file

@ -108,6 +108,7 @@ module FactoryGirl
FactoryGirl.register_strategy(:create, FactoryGirl::Strategy::Create)
FactoryGirl.register_strategy(:attributes_for, FactoryGirl::Strategy::AttributesFor)
FactoryGirl.register_strategy(:build_stubbed, FactoryGirl::Strategy::Stub)
FactoryGirl.register_strategy(:null, FactoryGirl::Strategy::Null)
end
def self.callback_names

View file

@ -31,10 +31,9 @@ module FactoryGirl
delegate :new, to: :@build_class
def association(factory_name, overrides = {})
strategy_override = overrides.fetch(:strategy) { FactoryGirl.strategy_by_name(:create) }
strategy_override = overrides.fetch(:strategy) { :create }
build_strategy = StrategyCalculator.new(strategy_override).strategy
runner = FactoryRunner.new(factory_name, build_strategy, [overrides.except(:strategy)])
runner = FactoryRunner.new(factory_name, strategy_override, [overrides.except(:strategy)])
@build_strategy.association(runner)
end

View file

@ -8,8 +8,7 @@ module FactoryGirl
@traits = traits_and_overrides
end
def run(strategy_override = nil, &block)
strategy_override ||= @strategy
def run(runner_strategy = @strategy, &block)
factory = FactoryGirl.factory_by_name(@name)
factory.compile
@ -18,7 +17,8 @@ module FactoryGirl
factory = factory.with_traits(@traits)
end
factory.run(strategy_override, @overrides, &block)
strategy = StrategyCalculator.new(runner_strategy).strategy
factory.run(strategy, @overrides, &block)
end
end
end

View file

@ -2,7 +2,7 @@ module FactoryGirl
module Strategy
class AttributesFor
def association(runner)
runner.run(Strategy::Null)
runner.run(:null)
end
def result(evaluation)

View file

@ -4,7 +4,7 @@ module FactoryGirl
@@next_id = 1000
def association(runner)
runner.run(Strategy::Stub)
runner.run(:build_stubbed)
end
def result(evaluation)

View file

@ -43,7 +43,7 @@ module FactoryGirl
def generate(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.generate is deprecated; use the FactoryGirl.define syntax instead", caller
instance = FactoryRunner.new(name.underscore, FactoryGirl.strategy_by_name(:build), [overrides]).run
instance = FactoryRunner.new(name.underscore, :build, [overrides]).run
instance.save
yield(instance) if block_given?
instance
@ -51,14 +51,14 @@ module FactoryGirl
def generate!(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.generate! is deprecated; use the FactoryGirl.define syntax instead", caller
instance = FactoryRunner.new(name.underscore, FactoryGirl.strategy_by_name(:create), [overrides]).run
instance = FactoryRunner.new(name.underscore, :create, [overrides]).run
yield(instance) if block_given?
instance
end
def spawn(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.spawn is deprecated; use the FactoryGirl.define syntax instead", caller
instance = FactoryRunner.new(name.underscore, FactoryGirl.strategy_by_name(:build), [overrides]).run
instance = FactoryRunner.new(name.underscore, :build, [overrides]).run
yield(instance) if block_given?
instance
end

View file

@ -29,12 +29,12 @@ module FactoryGirl
def make(overrides = {})
ActiveSupport::Deprecation.warn "Model.make is deprecated; use the FactoryGirl.define syntax instead", caller
FactoryRunner.new(name.underscore, FactoryGirl.strategy_by_name(:build), [overrides]).run
FactoryRunner.new(name.underscore, :build, [overrides]).run
end
def make!(overrides = {})
ActiveSupport::Deprecation.warn "Model.make! is deprecated; use the FactoryGirl.define syntax instead", caller
FactoryRunner.new(name.underscore, FactoryGirl.strategy_by_name(:create), [overrides]).run
FactoryRunner.new(name.underscore, :create, [overrides]).run
end
end