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
14 changes: 7 additions & 7 deletions lib/factory_bot/attribute_assigner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ def attributes_to_set_on_hash
def attribute_names_to_assign
@attribute_names_to_assign ||= begin
# start a list of candidates containing non-transient attributes and overrides
assignment_candidates = non_ignored_attribute_names + override_names
assignment_candidates = non_transient_attribute_names + override_names
# then remove any transient attributes (potentially reintroduced by the overrides),
# and remove ignorable aliased attributes from the candidate list
assignment_candidates - ignored_attribute_names - attribute_names_overriden_by_alias
assignment_candidates - transient_attribute_names - attribute_names_overriden_by_alias
end
end

def non_ignored_attribute_names
@attribute_list.non_ignored.names
def non_transient_attribute_names
@attribute_list.non_transient.names
end

def ignored_attribute_names
@attribute_list.ignored.names
def transient_attribute_names
@attribute_list.transient.names
end

def association_names
Expand All @@ -109,7 +109,7 @@ def hash_instance_methods_to_respond_to
# Builds a list of attribute names which are slated to be interrupted by an override.
def attribute_names_overriden_by_alias
@attribute_list
.non_ignored
.non_transient
.flat_map { |attribute|
override_names.map do |override|
attribute.name if ignorable_alias?(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 @@ -27,11 +27,11 @@ def associations
AttributeList.new(@name, select(&:association?))
end

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

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

Expand Down
8 changes: 4 additions & 4 deletions spec/acceptance/initialize_with_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ def initialize(name)
describe "initialize_with has access to all attributes for construction" do
it "assigns attributes correctly" do
define_class("User") do
attr_reader :name, :email, :ignored
attr_reader :name, :email, :transient_text

def initialize(attributes = {})
@name = attributes[:name]
@email = attributes[:email]
@ignored = attributes[:ignored]
@transient_text = attributes[:transient_text]
end
end

Expand All @@ -194,7 +194,7 @@ def initialize(attributes = {})

factory :user do
transient do
ignored { "of course!" }
transient_text { "of course!" }
end

email
Expand All @@ -208,7 +208,7 @@ def initialize(attributes = {})
user_with_attributes = FactoryBot.build(:user)
expect(user_with_attributes.email).to eq "person1@example.com"
expect(user_with_attributes.name).to eq "person1"
expect(user_with_attributes.ignored).to be_nil
expect(user_with_attributes.transient_text).to be_nil
end
end

Expand Down
50 changes: 25 additions & 25 deletions spec/factory_bot/attribute_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,44 +91,44 @@ def build_attribute_list(*attributes)
end
end

describe FactoryBot::AttributeList, "filter based on ignored attributes" do
describe FactoryBot::AttributeList, "filter based on transient attributes" do
include AttributeList

def build_ignored_attribute(name)
def build_transient_attribute(name)
FactoryBot::Attribute::Dynamic.new(name, true, -> { "value" })
end

def build_non_ignored_attribute(name)
def build_non_transient_attribute(name)
FactoryBot::Attribute::Dynamic.new(name, false, -> { "value" })
end

it "filters #ignored attributes" do
it "filters #transient attributes" do
list = build_attribute_list(
build_ignored_attribute(:comments_count),
build_non_ignored_attribute(:email)
build_transient_attribute(:comments_count),
build_non_transient_attribute(:email)
)

expect(list.ignored.names).to eq [:comments_count]
expect(list.transient.names).to eq [:comments_count]
end

it "filters #non_ignored attributes" do
it "filters #non_transient attributes" do
list = build_attribute_list(
build_ignored_attribute(:comments_count),
build_non_ignored_attribute(:email)
build_transient_attribute(:comments_count),
build_non_transient_attribute(:email)
)

expect(list.non_ignored.names).to eq [:email]
expect(list.non_transient.names).to eq [:email]
end
end

describe FactoryBot::AttributeList, "generating names" do
include AttributeList

def build_ignored_attribute(name)
def build_transient_attribute(name)
FactoryBot::Attribute::Dynamic.new(name, true, -> { "value" })
end

def build_non_ignored_attribute(name)
def build_non_transient_attribute(name)
FactoryBot::Attribute::Dynamic.new(name, false, -> { "value" })
end

Expand All @@ -138,38 +138,38 @@ def build_association(name)

it "knows all its #names" do
list = build_attribute_list(
build_ignored_attribute(:comments_count),
build_non_ignored_attribute(:last_name),
build_transient_attribute(:comments_count),
build_non_transient_attribute(:last_name),
build_association(:avatar)
)

expect(list.names).to eq [:comments_count, :last_name, :avatar]
end

it "knows all its #names for #ignored attributes" do
it "knows all its #names for #transient attributes" do
list = build_attribute_list(
build_ignored_attribute(:posts_count),
build_non_ignored_attribute(:last_name),
build_transient_attribute(:posts_count),
build_non_transient_attribute(:last_name),
build_association(:avatar)
)

expect(list.ignored.names).to eq [:posts_count]
expect(list.transient.names).to eq [:posts_count]
end

it "knows all its #names for #non_ignored attributes" do
it "knows all its #names for #non_transient attributes" do
list = build_attribute_list(
build_ignored_attribute(:posts_count),
build_non_ignored_attribute(:last_name),
build_transient_attribute(:posts_count),
build_non_transient_attribute(:last_name),
build_association(:avatar)
)

expect(list.non_ignored.names).to eq [:last_name, :avatar]
expect(list.non_transient.names).to eq [:last_name, :avatar]
end

it "knows all its #names for #associations" do
list = build_attribute_list(
build_ignored_attribute(:posts_count),
build_non_ignored_attribute(:last_name),
build_transient_attribute(:posts_count),
build_non_transient_attribute(:last_name),
build_association(:avatar)
)

Expand Down
2 changes: 1 addition & 1 deletion spec/factory_bot/declaration/dynamic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
end
end

context "when one is ignored and the other isn't" do
context "when one is transient and the other isn't" do
it "the objects are NOT equal" do
block = -> {}
declaration = described_class.new(:name, false, block)
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_bot/declaration/implicit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
end
end

context "when one is ignored and the other isn't" do
context "when one is transient and the other isn't" do
it "the objects are NOT equal" do
declaration = described_class.new(:name, :factory, false)
other_declaration = described_class.new(:name, :factory, true)
Expand Down
6 changes: 3 additions & 3 deletions spec/factory_bot/definition_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
attribute_value = -> { "dynamic attribute" }
proxy.add_attribute(:attribute_name, &attribute_value)
expect(definition).to have_dynamic_declaration(:attribute_name)
.ignored
.transient
.with_value(attribute_value)
end
end

describe FactoryBot::DefinitionProxy, "#transient" do
it "makes all attributes added ignored" do
it "makes all attributes added transient" do
definition = FactoryBot::Definition.new(:name)
proxy = FactoryBot::DefinitionProxy.new(definition)
attribute_value = -> { "dynamic_attribute" }
Expand All @@ -30,7 +30,7 @@
end

expect(definition).to have_dynamic_declaration(:attribute_name)
.ignored
.transient
.with_value(attribute_value)
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/support/matchers/declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def named(name)
self
end

def ignored
@ignored = true
def transient
@transient = true
self
end

Expand Down Expand Up @@ -56,8 +56,8 @@ def failure_message

def expected_declaration
case @declaration_type
when :dynamic then FactoryBot::Declaration::Dynamic.new(@name, ignored?, @value)
when :implicit then FactoryBot::Declaration::Implicit.new(@name, @factory, ignored?)
when :dynamic then FactoryBot::Declaration::Dynamic.new(@name, transient?, @value)
when :implicit then FactoryBot::Declaration::Implicit.new(@name, @factory, transient?)
when :association
if @options
FactoryBot::Declaration::Association.new(@name, options)
Expand All @@ -67,8 +67,8 @@ def expected_declaration
end
end

def ignored?
!!@ignored
def transient?
!!@transient
end

def options
Expand Down