Skip to content
Open
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
6 changes: 3 additions & 3 deletions lib/factory_bot/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
module FactoryBot
# @api private
class Attribute
attr_reader :name, :ignored
attr_reader :name, :transient

def initialize(name, ignored)
def initialize(name, transient)
@name = name.to_sym
@ignored = ignored
@transient = transient
end

def to_proc
Expand Down
4 changes: 2 additions & 2 deletions lib/factory_bot/attribute/dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module FactoryBot
class Attribute
# @api private
class Dynamic < Attribute
def initialize(name, ignored, block)
super(name, ignored)
def initialize(name, transient, block)
super(name, transient)
@block = block
end

Expand Down
4 changes: 2 additions & 2 deletions lib/factory_bot/attribute/sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module FactoryBot
class Attribute
# @api private
class Sequence < Attribute
def initialize(name, sequence, ignored)
super(name, ignored)
def initialize(name, sequence, transient)
super(name, transient)
@sequence = sequence
end

Expand Down
4 changes: 2 additions & 2 deletions lib/factory_bot/attribute_assigner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def override_interrupts_association?(aliased_attribute, override)
# Does this override match the name of any declared attribute?
#
# @note Checking against the names of all attributes, resolves any issues with having both
# <attribute> and <attribute>_id in the same factory. This also takes into account ignored
# attributes that should not be assigned (aka transient attributes)
# <attribute> and <attribute>_id in the same factory. This also takes into account transient
# attributes that should not be assigned.
#
# @param [Symbol] override the name of an override
def override_matches_declared_attribute?(override)
Expand Down
4 changes: 2 additions & 2 deletions lib/factory_bot/attribute_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def associations
end

def transient
AttributeList.new(@name, select(&:ignored))
AttributeList.new(@name, select(&:transient))
end

def non_transient
AttributeList.new(@name, reject(&:ignored))
AttributeList.new(@name, reject(&:transient))
end

def apply_attributes(attributes_to_apply)
Expand Down
6 changes: 3 additions & 3 deletions lib/factory_bot/declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module FactoryBot
class Declaration
attr_reader :name

def initialize(name, ignored = false)
def initialize(name, transient = false)
@name = name
@ignored = ignored
@transient = transient
end

def to_attributes
Expand All @@ -18,6 +18,6 @@ def to_attributes

protected

attr_reader :ignored
attr_reader :transient
end
end
8 changes: 4 additions & 4 deletions lib/factory_bot/declaration/dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module FactoryBot
class Declaration
# @api private
class Dynamic < Declaration
def initialize(name, ignored = false, block = nil)
super(name, ignored)
def initialize(name, transient = false, block = nil)
super(name, transient)
@block = block
end

def ==(other)
self.class == other.class &&
name == other.name &&
ignored == other.ignored &&
transient == other.transient &&
block == other.block
end

Expand All @@ -21,7 +21,7 @@ def ==(other)
private

def build
[Attribute::Dynamic.new(name, @ignored, @block)]
[Attribute::Dynamic.new(name, @transient, @block)]
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/factory_bot/declaration/implicit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ module FactoryBot
class Declaration
# @api private
class Implicit < Declaration
def initialize(name, factory = nil, ignored = false)
super(name, ignored)
def initialize(name, factory = nil, transient = false)
super(name, transient)
@factory = factory
end

def ==(other)
self.class == other.class &&
name == other.name &&
factory == other.factory &&
ignored == other.ignored
transient == other.transient
end

protected
Expand All @@ -24,7 +24,7 @@ def build
if FactoryBot.factories.registered?(name)
[Attribute::Association.new(name, name, {})]
elsif FactoryBot::Internal.sequences.registered?(name)
[Attribute::Sequence.new(name, name, @ignored)]
[Attribute::Sequence.new(name, name, @transient)]
elsif @factory.name.to_s == name.to_s
message = "Self-referencing trait '#{@name}'"
raise TraitDefinitionError, message
Expand Down
8 changes: 4 additions & 4 deletions lib/factory_bot/definition_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class DefinitionProxy

attr_reader :child_factories

def initialize(definition, ignore = false)
def initialize(definition, transient = false)
@definition = definition
@ignore = ignore
@transient = transient
@child_factories = []
end

Expand All @@ -45,7 +45,7 @@ def singleton_method_added(name)
# The name of this attribute. This will be assigned using "name=" for
# generated instances.
def add_attribute(name, &block)
declaration = Declaration::Dynamic.new(name, @ignore, block)
declaration = Declaration::Dynamic.new(name, @transient, block)
@definition.declare_attribute(declaration)
end

Expand Down Expand Up @@ -246,7 +246,7 @@ def initialize_with(&block)

def __declare_attribute__(name, block)
if block.nil?
declaration = Declaration::Implicit.new(name, @definition, @ignore)
declaration = Declaration::Implicit.new(name, @definition, @transient)
@definition.declare_attribute(declaration)
else
add_attribute(name, &block)
Expand Down
8 changes: 8 additions & 0 deletions spec/factory_bot/attribute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@

expect(attribute).not_to be_association
end

it "tracks whether the attribute is transient" do
transient_attribute = FactoryBot::Attribute.new(:comments_count, true)
persistent_attribute = FactoryBot::Attribute.new(:email, false)

expect(transient_attribute.transient).to be true
expect(persistent_attribute.transient).to be false
end
end