1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/spec/acceptance/modify_inherited_spec.rb
Daniel Colson bf04aaa068 Autocorrect all static attributes to dynamic
Most of this was fixed by adding the `attribute-defined-statically-cop`
branch of `thoughtbot/rubocop-rspec` to the Gemfile and running:

```sh
  rubocop \
    --require rubocop-rspec \
    --only FactoryBot/AttributeDefinedStatically \
    --auto-correct
```

I had to update the cucumber tests manually, and I realized our changes
don't handle `ignore` blocks or blocks with arity 1 that use the yielded
DefinitionProxy. I will update
https://github.com/rubocop-hq/rubocop-rspec/pull/666to handle these
cases.
2018-09-14 19:27:13 +00:00

50 lines
1.3 KiB
Ruby

describe "modifying inherited factories with traits" do
before do
define_model('User', gender: :string, admin: :boolean, age: :integer)
FactoryBot.define do
factory :user do
trait(:female) { gender { "Female" } }
trait(:male) { gender { "Male" } }
trait(:young_admin) do
admin { true }
age { 17 }
end
female
young_admin
factory :female_user do
gender { "Female" }
age { 25 }
end
factory :male_user do
gender { "Male" }
end
end
end
end
it "returns the correct value for overridden attributes from traits" do
expect(FactoryBot.build(:male_user).gender).to eq "Male"
end
it "returns the correct value for overridden attributes from traits defining multiple attributes" do
expect(FactoryBot.build(:female_user).gender).to eq "Female"
expect(FactoryBot.build(:female_user).age).to eq 25
expect(FactoryBot.build(:female_user).admin).to eq true
end
it "allows modification of attributes created via traits" do
FactoryBot.modify do
factory :male_user do
age { 20 }
end
end
expect(FactoryBot.build(:male_user).gender).to eq "Male"
expect(FactoryBot.build(:male_user).age).to eq 20
expect(FactoryBot.build(:male_user).admin).to eq true
end
end