2010-11-12 15:58:25 -05:00
|
|
|
describe "an instance generated by a factory with a custom class name" do
|
|
|
|
before do
|
2012-03-09 17:20:38 -05:00
|
|
|
define_model("User", admin: :boolean)
|
2010-11-12 15:58:25 -05:00
|
|
|
|
2017-10-20 15:20:28 -04:00
|
|
|
FactoryBot.define do
|
2011-06-29 14:43:15 -04:00
|
|
|
factory :user
|
2010-11-12 15:58:25 -05:00
|
|
|
|
2012-03-09 17:20:38 -05:00
|
|
|
factory :admin, class: User do
|
2010-11-12 15:58:25 -05:00
|
|
|
admin { true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-20 15:20:28 -04:00
|
|
|
subject { FactoryBot.create(:admin) }
|
2010-11-12 15:58:25 -05:00
|
|
|
|
2013-01-18 13:27:57 -05:00
|
|
|
it { should be_kind_of(User) }
|
|
|
|
it { should be_admin }
|
2010-11-12 15:58:25 -05:00
|
|
|
end
|
|
|
|
|
2015-04-15 21:59:13 -04:00
|
|
|
describe "attributes defined using Symbol#to_proc" do
|
|
|
|
before do
|
|
|
|
define_model("User", password: :string, password_confirmation: :string)
|
|
|
|
|
2017-10-20 15:20:28 -04:00
|
|
|
FactoryBot.define do
|
2015-04-15 21:59:13 -04:00
|
|
|
factory :user do
|
|
|
|
password "foo"
|
|
|
|
password_confirmation &:password
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "assigns values correctly" do
|
2017-10-20 15:20:28 -04:00
|
|
|
user = FactoryBot.build(:user)
|
2015-04-15 21:59:13 -04:00
|
|
|
|
|
|
|
expect(user.password).to eq "foo"
|
|
|
|
expect(user.password_confirmation).to eq "foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "assigns value with override correctly" do
|
2017-10-20 15:20:28 -04:00
|
|
|
user = FactoryBot.build(:user, password: "bar")
|
2015-04-15 21:59:13 -04:00
|
|
|
|
|
|
|
expect(user.password).to eq "bar"
|
|
|
|
expect(user.password_confirmation).to eq "bar"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "assigns overridden value correctly" do
|
2017-10-20 15:20:28 -04:00
|
|
|
user = FactoryBot.build(:user, password_confirmation: "bar")
|
2015-04-15 21:59:13 -04:00
|
|
|
|
|
|
|
expect(user.password).to eq "foo"
|
|
|
|
expect(user.password_confirmation).to eq "bar"
|
|
|
|
end
|
|
|
|
end
|