1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
describe "a generated attributes hash where order matters" do
include FactoryBot::Syntax::Methods
before do
define_model("ParentModel", static: :integer,
evaluates_first: :integer,
evaluates_second: :integer,
evaluates_third: :integer)
FactoryBot.define do
factory :parent_model do
evaluates_first { static }
evaluates_second { evaluates_first }
evaluates_third { evaluates_second }
factory :child_model do
static { 1 }
end
end
factory :without_parent, class: ParentModel do
evaluates_first { static }
evaluates_second { evaluates_first }
evaluates_third { evaluates_second }
static { 1 }
end
end
end
context "factory with a parent" do
subject { FactoryBot.build(:child_model) }
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
end
end
context "factory without a parent" do
subject { FactoryBot.build(:without_parent) }
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
end
end
end
|