diff --git a/lib/factory_bot/attribute_assigner.rb b/lib/factory_bot/attribute_assigner.rb index 05e3b1869..0eb7e0516 100644 --- a/lib/factory_bot/attribute_assigner.rb +++ b/lib/factory_bot/attribute_assigner.rb @@ -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 @@ -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) diff --git a/lib/factory_bot/attribute_list.rb b/lib/factory_bot/attribute_list.rb index c89a1259d..55538ef79 100644 --- a/lib/factory_bot/attribute_list.rb +++ b/lib/factory_bot/attribute_list.rb @@ -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 diff --git a/spec/acceptance/initialize_with_spec.rb b/spec/acceptance/initialize_with_spec.rb index b288bdc2e..07b1b3e6a 100644 --- a/spec/acceptance/initialize_with_spec.rb +++ b/spec/acceptance/initialize_with_spec.rb @@ -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 @@ -194,7 +194,7 @@ def initialize(attributes = {}) factory :user do transient do - ignored { "of course!" } + transient_text { "of course!" } end email @@ -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 diff --git a/spec/factory_bot/attribute_list_spec.rb b/spec/factory_bot/attribute_list_spec.rb index f8edc6196..e521b741a 100644 --- a/spec/factory_bot/attribute_list_spec.rb +++ b/spec/factory_bot/attribute_list_spec.rb @@ -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 @@ -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) ) diff --git a/spec/factory_bot/declaration/dynamic_spec.rb b/spec/factory_bot/declaration/dynamic_spec.rb index 838fcd7f9..694d545ef 100644 --- a/spec/factory_bot/declaration/dynamic_spec.rb +++ b/spec/factory_bot/declaration/dynamic_spec.rb @@ -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) diff --git a/spec/factory_bot/declaration/implicit_spec.rb b/spec/factory_bot/declaration/implicit_spec.rb index 63378d728..22a0b2267 100644 --- a/spec/factory_bot/declaration/implicit_spec.rb +++ b/spec/factory_bot/declaration/implicit_spec.rb @@ -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) diff --git a/spec/factory_bot/definition_proxy_spec.rb b/spec/factory_bot/definition_proxy_spec.rb index c1e77c066..fad9c32ae 100644 --- a/spec/factory_bot/definition_proxy_spec.rb +++ b/spec/factory_bot/definition_proxy_spec.rb @@ -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" } @@ -30,7 +30,7 @@ end expect(definition).to have_dynamic_declaration(:attribute_name) - .ignored + .transient .with_value(attribute_value) end end diff --git a/spec/support/matchers/declaration.rb b/spec/support/matchers/declaration.rb index 65e4663bd..b1ae73bc8 100644 --- a/spec/support/matchers/declaration.rb +++ b/spec/support/matchers/declaration.rb @@ -25,8 +25,8 @@ def named(name) self end - def ignored - @ignored = true + def transient + @transient = true self end @@ -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) @@ -67,8 +67,8 @@ def expected_declaration end end - def ignored? - !!@ignored + def transient? + !!@transient end def options