Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove dependency on build_class in Evaluator

  • Loading branch information...
commit 8209a461ee6be587f753b29230d30dd056795602 1 parent 40fc48d
@joshuaclayton joshuaclayton authored
View
1  lib/factory_girl.rb
@@ -42,6 +42,7 @@
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
View
8 lib/factory_girl/attribute_assigner.rb
@@ -31,7 +31,13 @@ def hash
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
View
12 lib/factory_girl/decorator/new_constructor.rb
@@ -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
View
5 lib/factory_girl/evaluator.rb
@@ -10,8 +10,7 @@ class Evaluator
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 @@ def initialize(build_class, build_strategy, overrides = {})
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 }
View
2  lib/factory_girl/factory.rb
@@ -33,7 +33,7 @@ def run(build_strategy, overrides, &block)
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)
View
2  spec/factory_girl/evaluator_class_definer_spec.rb
@@ -7,7 +7,7 @@
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)
Please sign in to comment.
Something went wrong with that request. Please try again.