mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
bf04aaa068
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.
52 lines
1.2 KiB
Ruby
52 lines
1.2 KiB
Ruby
describe "an instance generated by a factory with a custom class name" do
|
|
before do
|
|
define_model("User", admin: :boolean)
|
|
|
|
FactoryBot.define do
|
|
factory :user
|
|
|
|
factory :admin, class: User do
|
|
admin { true }
|
|
end
|
|
end
|
|
end
|
|
|
|
subject { FactoryBot.create(:admin) }
|
|
|
|
it { should be_kind_of(User) }
|
|
it { should be_admin }
|
|
end
|
|
|
|
describe "attributes defined using Symbol#to_proc" do
|
|
before do
|
|
define_model("User", password: :string, password_confirmation: :string)
|
|
|
|
FactoryBot.define do
|
|
factory :user do
|
|
password { "foo" }
|
|
password_confirmation &:password
|
|
end
|
|
end
|
|
end
|
|
|
|
it "assigns values correctly" do
|
|
user = FactoryBot.build(:user)
|
|
|
|
expect(user.password).to eq "foo"
|
|
expect(user.password_confirmation).to eq "foo"
|
|
end
|
|
|
|
it "assigns value with override correctly" do
|
|
user = FactoryBot.build(:user, password: "bar")
|
|
|
|
expect(user.password).to eq "bar"
|
|
expect(user.password_confirmation).to eq "bar"
|
|
end
|
|
|
|
it "assigns overridden value correctly" do
|
|
user = FactoryBot.build(:user, password_confirmation: "bar")
|
|
|
|
expect(user.password).to eq "foo"
|
|
expect(user.password_confirmation).to eq "bar"
|
|
end
|
|
end
|