-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding factory to ExtManagementSystem with invalid credentials #16781
Adding factory to ExtManagementSystem with invalid credentials #16781
Conversation
@chrisarcand Please review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a specific separate factory for ems_physical_infra
, this should utilize FactoryGirl traits; you can see a couple in use within this factory file.
Just make a trait called :with_invalid_authentication
which only has your after block with the authentication(s); then in your spec, use FactoryGirl.create(:ems_physical_infra, :with_invalid_authentication)
. This has the added benefit of now being able to have invalid authentication for any of the other ems types.
de9a376
to
0604e93
Compare
Awesome! It's done @chrisarcand |
after(:create) do |x| | ||
x.authentications = [FactoryGirl.build(:authentication, :resource => x, :status => "invalid")] | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right idea, but why inside the :ems_physical_infra
factory? These authentications are the same for all providers, no? If you place it next to the other traits in :ext_management_system
, this trait can then be used with all the other child factories in this file (including :ems_physical_infra
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, nice!
:parent => :ext_management_system do | ||
trait :with_invalid_authentication do | ||
after(:create) do |x| | ||
x.authentications = [FactoryGirl.build(:authentication, :resource => x, :status => "invalid")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer:
x.authentications << FactoryGirl.build(:authentication, :status => "invalid")
0604e93
to
6d5c25c
Compare
:parent => :ext_management_system do | ||
end | ||
|
||
factory :ems_physical_infra_with_invalid_authentication, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like something went wrong during a rebase and brought this factory back as well as all of the do / end
blocks I deleted :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do
think this should be the end
of those blocks, indeed.
82e7f66
to
988204b
Compare
|
||
trait :with_invalid_authentication do | ||
after(:create) do |x| | ||
x.authentications << FactoryGirl.build(:authentication, :resource => x, :status => "invalid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Last thing: It's good to reach for build
first when you can, but one to many relationships may or may not work with initialized-but-not-persisted objects on them (as often, you're testing something where something else does a lookup on this authentications, for example), depending on what you're doing. As this is an optional trait that won't be used unless people explicitly want it, you likely want to use FactoryGirl.create
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it! create
is really better in this case, thanks for pointing
988204b
to
2b23145
Compare
Checked commit douglasgabriel@2b23145 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
|
||
trait :with_invalid_authentication do | ||
after(:create) do |x| | ||
x.authentications << FactoryGirl.create(:authentication, :resource => x, :status => "invalid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you use the <<
operator on an association, you shouldn't need the :resource => x
in create
2b23145
to
49ec4be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM Thanks @douglasgabriel
This PR adds a factory to an ExtManagementSystem with invalid credentials