mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Remove dependency on build_class in Evaluator
This commit is contained in:
parent
40fc48d488
commit
8209a461ee
6 changed files with 23 additions and 7 deletions
|
@ -42,6 +42,7 @@ require 'factory_girl/decorator/class_key_hash'
|
|||
require 'factory_girl/decorator/disallows_duplicates_registry'
|
||||
require 'factory_girl/decorator/invocation_tracker'
|
||||
require 'factory_girl/decorator/invocation_ignorer'
|
||||
require 'factory_girl/decorator/new_constructor'
|
||||
require 'factory_girl/version'
|
||||
|
||||
module FactoryGirl
|
||||
|
|
|
@ -31,7 +31,13 @@ module FactoryGirl
|
|||
private
|
||||
|
||||
def method_tracking_evaluator
|
||||
@method_tracking_evaluator ||= Decorator::AttributeHash.new(invocation_decorator.new(@evaluator), attribute_names_to_assign)
|
||||
@method_tracking_evaluator ||= Decorator::AttributeHash.new(decorated_evaluator, attribute_names_to_assign)
|
||||
end
|
||||
|
||||
def decorated_evaluator
|
||||
invocation_decorator.new(
|
||||
Decorator::NewConstructor.new(@evaluator, @build_class)
|
||||
)
|
||||
end
|
||||
|
||||
def invocation_decorator
|
||||
|
|
12
lib/factory_girl/decorator/new_constructor.rb
Normal file
12
lib/factory_girl/decorator/new_constructor.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
module FactoryGirl
|
||||
class Decorator
|
||||
class NewConstructor < Decorator
|
||||
def initialize(component, build_class)
|
||||
super(component)
|
||||
@build_class = build_class
|
||||
end
|
||||
|
||||
delegate :new, to: :@build_class
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,8 +10,7 @@ module FactoryGirl
|
|||
undef_method(method) unless method =~ /^__|initialize/
|
||||
end
|
||||
|
||||
def initialize(build_class, build_strategy, overrides = {})
|
||||
@build_class = build_class
|
||||
def initialize(build_strategy, overrides = {})
|
||||
@build_strategy = build_strategy
|
||||
@overrides = overrides
|
||||
@cached_attributes = overrides
|
||||
|
@ -21,8 +20,6 @@ module FactoryGirl
|
|||
end
|
||||
end
|
||||
|
||||
delegate :new, to: :@build_class
|
||||
|
||||
def association(factory_name, *traits_and_overrides)
|
||||
overrides = traits_and_overrides.extract_options!
|
||||
strategy_override = overrides.fetch(:strategy) { :create }
|
||||
|
|
|
@ -33,7 +33,7 @@ module FactoryGirl
|
|||
|
||||
strategy = StrategyCalculator.new(build_strategy).strategy.new
|
||||
|
||||
evaluator = evaluator_class.new(build_class, strategy, overrides.symbolize_keys)
|
||||
evaluator = evaluator_class.new(strategy, overrides.symbolize_keys)
|
||||
attribute_assigner = AttributeAssigner.new(evaluator, build_class, &compiled_constructor)
|
||||
|
||||
evaluation = Evaluation.new(attribute_assigner, compiled_to_create)
|
||||
|
|
|
@ -7,7 +7,7 @@ describe FactoryGirl::EvaluatorClassDefiner do
|
|||
|
||||
let(:attributes) { [simple_attribute, relative_attribute, attribute_that_raises_a_second_time] }
|
||||
let(:class_definer) { FactoryGirl::EvaluatorClassDefiner.new(attributes, FactoryGirl::Evaluator) }
|
||||
let(:evaluator) { class_definer.evaluator_class.new(Object, stub("build strategy", add_observer: true)) }
|
||||
let(:evaluator) { class_definer.evaluator_class.new(stub("build strategy", add_observer: true)) }
|
||||
|
||||
it "returns an evaluator when accessing the evaluator class" do
|
||||
evaluator.should be_a(FactoryGirl::Evaluator)
|
||||
|
|
Loading…
Reference in a new issue