diff --git a/lib/factory_bot/attribute.rb b/lib/factory_bot/attribute.rb index 366f24edd..8a98e69a2 100644 --- a/lib/factory_bot/attribute.rb +++ b/lib/factory_bot/attribute.rb @@ -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 diff --git a/lib/factory_bot/attribute/dynamic.rb b/lib/factory_bot/attribute/dynamic.rb index 9467ed677..5cd936c97 100644 --- a/lib/factory_bot/attribute/dynamic.rb +++ b/lib/factory_bot/attribute/dynamic.rb @@ -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 diff --git a/lib/factory_bot/attribute/sequence.rb b/lib/factory_bot/attribute/sequence.rb index e5c8ec6a8..ac1d47e9a 100644 --- a/lib/factory_bot/attribute/sequence.rb +++ b/lib/factory_bot/attribute/sequence.rb @@ -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 diff --git a/lib/factory_bot/attribute_assigner.rb b/lib/factory_bot/attribute_assigner.rb index f996f430a..886812aa3 100644 --- a/lib/factory_bot/attribute_assigner.rb +++ b/lib/factory_bot/attribute_assigner.rb @@ -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 - # and _id in the same factory. This also takes into account ignored - # attributes that should not be assigned (aka transient attributes) + # and _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) diff --git a/lib/factory_bot/attribute_list.rb b/lib/factory_bot/attribute_list.rb index 55538ef79..7ec4ff02e 100644 --- a/lib/factory_bot/attribute_list.rb +++ b/lib/factory_bot/attribute_list.rb @@ -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) diff --git a/lib/factory_bot/declaration.rb b/lib/factory_bot/declaration.rb index 35b8b581a..999341805 100644 --- a/lib/factory_bot/declaration.rb +++ b/lib/factory_bot/declaration.rb @@ -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 @@ -18,6 +18,6 @@ def to_attributes protected - attr_reader :ignored + attr_reader :transient end end diff --git a/lib/factory_bot/declaration/dynamic.rb b/lib/factory_bot/declaration/dynamic.rb index 3a67a30bb..a68fb97c4 100644 --- a/lib/factory_bot/declaration/dynamic.rb +++ b/lib/factory_bot/declaration/dynamic.rb @@ -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 @@ -21,7 +21,7 @@ def ==(other) private def build - [Attribute::Dynamic.new(name, @ignored, @block)] + [Attribute::Dynamic.new(name, @transient, @block)] end end end diff --git a/lib/factory_bot/declaration/implicit.rb b/lib/factory_bot/declaration/implicit.rb index 61ff92652..ac62c1355 100644 --- a/lib/factory_bot/declaration/implicit.rb +++ b/lib/factory_bot/declaration/implicit.rb @@ -2,8 +2,8 @@ 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 @@ -11,7 +11,7 @@ def ==(other) self.class == other.class && name == other.name && factory == other.factory && - ignored == other.ignored + transient == other.transient end protected @@ -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 diff --git a/lib/factory_bot/definition_proxy.rb b/lib/factory_bot/definition_proxy.rb index efa71b1e0..a04c597c5 100644 --- a/lib/factory_bot/definition_proxy.rb +++ b/lib/factory_bot/definition_proxy.rb @@ -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 @@ -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 @@ -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) diff --git a/spec/factory_bot/attribute_spec.rb b/spec/factory_bot/attribute_spec.rb index 7a4be81d6..68acc06c2 100644 --- a/spec/factory_bot/attribute_spec.rb +++ b/spec/factory_bot/attribute_spec.rb @@ -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