From cbe242c9427161c16d45bde560421a0445ecb579 Mon Sep 17 00:00:00 2001 From: Daniel Colson Date: Fri, 28 Sep 2018 16:57:46 -0400 Subject: [PATCH] Remove references to static attributes We removed static attributes in https://github.com/thoughtbot/factory_bot/pull/1163 This PR cleans up a few remaining references we had to static attributes in the tests. --- spec/acceptance/attributes_ordered_spec.rb | 4 +-- spec/acceptance/modify_factories_spec.rb | 8 ++--- spec/acceptance/parent_spec.rb | 35 +++------------------- spec/factory_bot/declaration_list_spec.rb | 26 ++++++++-------- 4 files changed, 23 insertions(+), 50 deletions(-) diff --git a/spec/acceptance/attributes_ordered_spec.rb b/spec/acceptance/attributes_ordered_spec.rb index 14d0fd5..2c91d73 100644 --- a/spec/acceptance/attributes_ordered_spec.rb +++ b/spec/acceptance/attributes_ordered_spec.rb @@ -30,7 +30,7 @@ describe "a generated attributes hash where order matters" do context "factory with a parent" do subject { FactoryBot.build(:child_model) } - it "assigns attributes in the order they're defined with preference to static attributes" do + it "assigns attributes in the order they're defined" do expect(subject[:evaluates_first]).to eq 1 expect(subject[:evaluates_second]).to eq 1 expect(subject[:evaluates_third]).to eq 1 @@ -40,7 +40,7 @@ describe "a generated attributes hash where order matters" do context "factory without a parent" do subject { FactoryBot.build(:without_parent) } - it "assigns attributes in the order they're defined with preference to static attributes without a parent class" do + it "assigns attributes in the order they're defined without a parent class" do expect(subject[:evaluates_first]).to eq 1 expect(subject[:evaluates_second]).to eq 1 expect(subject[:evaluates_third]).to eq 1 diff --git a/spec/acceptance/modify_factories_spec.rb b/spec/acceptance/modify_factories_spec.rb index befb381..f8ac774 100644 --- a/spec/acceptance/modify_factories_spec.rb +++ b/spec/acceptance/modify_factories_spec.rb @@ -111,14 +111,14 @@ describe "modifying factories" do its(:email) { should eq "Great User-modified@example.com" } end - context "overriding dynamic attributes" do + context "overriding the email" do subject { create(:user, email: "perfect@example.com") } its(:name) { should eq "Great User" } its(:email) { should eq "perfect@example.com" } end - context "overriding static attributes" do + context "overriding the name" do subject { create(:user, name: "wonderful") } its(:name) { should eq "wonderful" } @@ -135,7 +135,7 @@ describe "modifying factories" do its(:admin) { should be true } end - context "overriding dynamic attributes" do + context "overriding the email" do subject { create(:admin, email: "perfect@example.com") } its(:name) { should eq "Great User" } @@ -143,7 +143,7 @@ describe "modifying factories" do its(:admin) { should be true } end - context "overriding static attributes" do + context "overriding the name" do subject { create(:admin, name: "wonderful") } its(:name) { should eq "wonderful" } diff --git a/spec/acceptance/parent_spec.rb b/spec/acceptance/parent_spec.rb index 1512cc0..4e644a7 100644 --- a/spec/acceptance/parent_spec.rb +++ b/spec/acceptance/parent_spec.rb @@ -13,18 +13,6 @@ describe "an instance generated by a factory that inherits from another factory" admin { true } upper_email { email.upcase } end - - factory :guest do - email { "#{name}-guest@example.com" } - end - - factory :no_email do - email { "" } - end - - factory :bill do - name { "Bill" } # block to make attribute dynamic - end end end end @@ -32,35 +20,20 @@ describe "an instance generated by a factory that inherits from another factory" describe "the parent class" do subject { FactoryBot.create(:user) } it { should_not be_admin } + its(:name) { should eq "John" } its(:email) { should eq "john@example.com" } + its(:login) { should eq "john@example.com" } end - describe "the child class redefining parent's static method used by a dynamic method" do + describe "the child class redefining parent's attributes" do subject { FactoryBot.create(:admin) } it { should be_kind_of(User) } it { should be_admin } its(:name) { should eq "admin" } its(:email) { should eq "admin@example.com" } + its(:login) { should eq "admin@example.com" } its(:upper_email) { should eq "ADMIN@EXAMPLE.COM" } end - - describe "the child class redefining parent's dynamic method" do - subject { FactoryBot.create(:guest) } - it { should_not be_admin } - its(:name) { should eq "John" } - its(:email) { should eql "John-guest@example.com" } - its(:login) { should eq "John-guest@example.com" } - end - - describe "the child class redefining parent's dynamic attribute with static attribute" do - subject { FactoryBot.create(:no_email) } - its(:email) { should eq "" } - end - - describe "the child class redefining parent's static attribute with dynamic attribute" do - subject { FactoryBot.create(:bill) } - its(:name) { should eq "Bill" } - end end describe "nested factories with different parents" do diff --git a/spec/factory_bot/declaration_list_spec.rb b/spec/factory_bot/declaration_list_spec.rb index e67a087..a5799b4 100644 --- a/spec/factory_bot/declaration_list_spec.rb +++ b/spec/factory_bot/declaration_list_spec.rb @@ -1,15 +1,15 @@ describe FactoryBot::DeclarationList, "#attributes" do - let(:static_attribute_1) { double("static attribute 1") } - let(:static_attribute_2) { double("static attribute 2") } - let(:dynamic_attribute_1) { double("dynamic attribute 1") } - let(:static_declaration) do + let(:attribute_1) { double("attribute 1") } + let(:attribute_2) { double("attribute 2") } + let(:attribute_3) { double("attribute 3") } + let(:declaration_1) do double( - "static declaration", - to_attributes: [static_attribute_1, static_attribute_2], + "declaration 1", + to_attributes: [attribute_1, attribute_2], ) end - let(:dynamic_declaration) do - double("static declaration", to_attributes: [dynamic_attribute_1]) + let(:declaration_2) do + double("declaration_2", to_attributes: [attribute_3]) end it "returns an AttributeList" do @@ -21,14 +21,14 @@ describe FactoryBot::DeclarationList, "#attributes" do it "defines each attribute on the attribute list" do allow(FactoryBot::AttributeList).to receive(:new).and_return attribute_list - subject.declare_attribute(static_declaration) - subject.declare_attribute(dynamic_declaration) + subject.declare_attribute(declaration_1) + subject.declare_attribute(declaration_2) subject.attributes - expect(attribute_list).to have_received(:define_attribute).with(static_attribute_1) - expect(attribute_list).to have_received(:define_attribute).with(static_attribute_2) - expect(attribute_list).to have_received(:define_attribute).with(dynamic_attribute_1) + expect(attribute_list).to have_received(:define_attribute).with(attribute_1) + expect(attribute_list).to have_received(:define_attribute).with(attribute_2) + expect(attribute_list).to have_received(:define_attribute).with(attribute_3) end end