mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
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.
This commit is contained in:
parent
5b31b56d65
commit
cbe242c942
4 changed files with 23 additions and 50 deletions
|
@ -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
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue