Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/factory_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
require "active_support/notifications"

require "factory_bot/internal"
require "factory_bot/definition_hierarchy"
require "factory_bot/configuration"
require "factory_bot/errors"
require "factory_bot/factory_runner"
Expand Down
38 changes: 0 additions & 38 deletions lib/factory_bot/definition_hierarchy.rb

This file was deleted.

21 changes: 3 additions & 18 deletions lib/factory_bot/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def compile
parent.compile
inherit_parent_traits
@definition.compile(build_class)
build_hierarchy
@compiled = true
end
end
Expand Down Expand Up @@ -121,28 +120,16 @@ def attributes
end
end

def hierarchy_class
@hierarchy_class ||= Class.new(parent.hierarchy_class)
end

def hierarchy_instance
@hierarchy_instance ||= hierarchy_class.new
end

def build_hierarchy
hierarchy_class.build_from_definition definition
end

def callbacks
hierarchy_instance.callbacks
parent.callbacks + definition.callbacks
end

def compiled_to_create
hierarchy_instance.to_create
definition.to_create || parent.compiled_to_create
end

def compiled_constructor
hierarchy_instance.constructor
definition.constructor || parent.compiled_constructor
end

private
Expand Down Expand Up @@ -170,8 +157,6 @@ def initialize_copy(source)
super
@definition = @definition.clone
@evaluator_class = nil
@hierarchy_class = nil
@hierarchy_instance = nil
@compiled = false
end
end
Expand Down
15 changes: 11 additions & 4 deletions lib/factory_bot/null_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ def initialize
@definition = Definition.new(:null_factory)
end

delegate :defined_traits, :callbacks, :attributes, :constructor,
:to_create, to: :definition
delegate :defined_traits, :attributes, to: :definition

def compile
end
Expand All @@ -20,8 +19,16 @@ def evaluator_class
FactoryBot::Evaluator
end

def hierarchy_class
FactoryBot::DefinitionHierarchy
def callbacks
Internal.callbacks
end

def compiled_constructor
Internal.constructor
end

def compiled_to_create
Internal.to_create
end
end
end
18 changes: 12 additions & 6 deletions spec/factory_bot/null_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@
expect(null_factory).to delegate(:defined_traits).to(:definition)
end

it "delegates callbacks to its definition" do
it "delegates attributes to its definition" do
null_factory = FactoryBot::NullFactory.new

expect(null_factory).to delegate(:callbacks).to(:definition)
expect(null_factory).to delegate(:attributes).to(:definition)
end

it "delegates attributes to its definition" do
it "has the global callbacks as its callbacks" do
null_factory = FactoryBot::NullFactory.new

expect(null_factory).to delegate(:attributes).to(:definition)
expect(null_factory.callbacks).to eq FactoryBot::Internal.callbacks
end

it "has the global constructor as its compiled constructor" do
null_factory = FactoryBot::NullFactory.new

expect(null_factory.compiled_constructor).to eq FactoryBot::Internal.constructor
end

it "delegates constructor to its definition" do
it "has the global to_create as its compiled to_create" do
null_factory = FactoryBot::NullFactory.new

expect(null_factory).to delegate(:constructor).to(:definition)
expect(null_factory.compiled_to_create).to eq FactoryBot::Internal.to_create
end

it "has a nil value for its compile attribute" do
Expand Down
Loading