2011-08-09 15:07:40 -04:00
|
|
|
describe "a generated attributes hash where order matters" do
|
2017-10-20 15:20:28 -04:00
|
|
|
include FactoryBot::Syntax::Methods
|
2011-08-09 15:07:40 -04:00
|
|
|
|
|
|
|
before do
|
2019-05-12 22:39:55 -04:00
|
|
|
define_model("ParentModel", static: :integer,
|
2022-03-07 20:22:23 -05:00
|
|
|
evaluates_first: :integer,
|
|
|
|
evaluates_second: :integer,
|
|
|
|
evaluates_third: :integer)
|
2011-08-09 15:07:40 -04:00
|
|
|
|
2017-10-20 15:20:28 -04:00
|
|
|
FactoryBot.define do
|
2011-08-09 15:07:40 -04:00
|
|
|
factory :parent_model do
|
2020-06-05 15:15:18 -04:00
|
|
|
evaluates_first { static }
|
2011-08-09 15:07:40 -04:00
|
|
|
evaluates_second { evaluates_first }
|
2020-06-05 15:15:18 -04:00
|
|
|
evaluates_third { evaluates_second }
|
2011-08-09 15:07:40 -04:00
|
|
|
|
|
|
|
factory :child_model do
|
2018-07-29 11:30:02 -04:00
|
|
|
static { 1 }
|
2011-08-09 15:07:40 -04:00
|
|
|
end
|
|
|
|
end
|
2011-08-12 18:07:40 -04:00
|
|
|
|
2012-03-09 17:20:38 -05:00
|
|
|
factory :without_parent, class: ParentModel do
|
2020-06-05 15:15:18 -04:00
|
|
|
evaluates_first { static }
|
|
|
|
evaluates_second { evaluates_first }
|
|
|
|
evaluates_third { evaluates_second }
|
2018-07-29 11:30:02 -04:00
|
|
|
static { 1 }
|
2011-08-12 18:07:40 -04:00
|
|
|
end
|
2011-08-09 15:07:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-12 18:07:40 -04:00
|
|
|
context "factory with a parent" do
|
2017-10-20 15:20:28 -04:00
|
|
|
subject { FactoryBot.build(:child_model) }
|
2011-08-09 15:07:40 -04:00
|
|
|
|
2018-09-28 16:57:46 -04:00
|
|
|
it "assigns attributes in the order they're defined" do
|
2013-01-18 13:27:57 -05:00
|
|
|
expect(subject[:evaluates_first]).to eq 1
|
|
|
|
expect(subject[:evaluates_second]).to eq 1
|
|
|
|
expect(subject[:evaluates_third]).to eq 1
|
2011-08-12 18:07:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "factory without a parent" do
|
2017-10-20 15:20:28 -04:00
|
|
|
subject { FactoryBot.build(:without_parent) }
|
2011-08-12 18:07:40 -04:00
|
|
|
|
2018-09-28 16:57:46 -04:00
|
|
|
it "assigns attributes in the order they're defined without a parent class" do
|
2013-01-18 13:27:57 -05:00
|
|
|
expect(subject[:evaluates_first]).to eq 1
|
|
|
|
expect(subject[:evaluates_second]).to eq 1
|
|
|
|
expect(subject[:evaluates_third]).to eq 1
|
2011-08-12 18:07:40 -04:00
|
|
|
end
|
2011-08-09 15:07:40 -04:00
|
|
|
end
|
|
|
|
end
|