-
Notifications
You must be signed in to change notification settings - Fork 70
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
Add button to duplicate job definition #92
Add button to duplicate job definition #92
Conversation
@cookpad/dev-infra review please |
@@ -81,7 +81,7 @@ def proceed_multi_instance? | |||
end | |||
|
|||
def text_tags | |||
tags.pluck(:name).join(',') | |||
tags.map(&:name).join(',') |
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.
Why this change needed?
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.
Without this change, text_tags
of duplicated definition always returns empty.
definition = Kuroko2::JobDefinition.first
duplicated_definition = definition.dup
duplicated_definition.tags = definition.tags.dup
definition.tags.pluck(:name) #=> ["HelloWorld"]
definition.tags.map(&:name) #=> ["HelloWorld"]
duplicated_definition.tags.pluck(:name) #=> []
duplicated_definition.tags.map(&:name) #=> ["HelloWorld"]
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.
text_tags
method is called at here.
In new page, text_tags
would return empty array without this change because the job_definition having this tags
does not exist in DB (so #pluck
returns empty array).
Is it right? @takonomura
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.
Yes
dup_from = Kuroko2::JobDefinition.find_by(id: params[:dup_from]) | ||
if dup_from.present? | ||
@definition = dup_from.dup | ||
@definition.admins = dup_from.admins.dup |
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.
Is it need dup
?
if dup_from.present? | ||
@definition = dup_from.dup | ||
@definition.admins = dup_from.admins.dup | ||
@definition.tags = dup_from.tags.dup |
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.
ditto.
expect(response).to render_template('new') | ||
|
||
expect(assigns(:definition)).to be_new_record | ||
expect(assigns(:definition).name).to eq definition.name |
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.
Could you write expect expressions about tags
and admins
?
expect(assigns(:definition).admins).to match_array [admin_user, controller.current_user] | ||
end | ||
|
||
context 'with other admins' do |
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.
'with only anther admin user'
?
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.
Fixed
expect(assigns(:definition).name).to eq definition.name | ||
end | ||
|
||
context 'with admins' do |
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.
'with current_user and another admin user'
d4a8bf3
to
047f318
Compare
expect(response).to have_http_status(:ok) | ||
expect(response).to render_template('new') | ||
|
||
expect(assigns(:definition)).to be_new_record |
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 seems better to check what a field is blank.
|
||
expect(assigns(:definition)).to be_new_record | ||
expect(assigns(:definition).name).to eq definition.name | ||
definition.admins << controller.current_user unless definition.admins.include?(controller.current_user) |
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 seems to better for do not change definition
instance in it
block.
How about changing it to the below code?
expect(assigns(:definition).admins).to eq(definition.admins + controller.current_user)
047f318
to
a543c3e
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 with comment
|
||
expect(assigns(:definition)).to be_new_record | ||
expect(assigns(:definition).name).to eq definition.name | ||
expect(assigns(:definition).admins).to eq definition.admins + [controller.current_user] |
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.
[nits]
[definition.admins, controller.current_user] seems to be better.
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.
expect(assigns(:definition).admins).to eq [definition.admins, controller.current_user]
is not working.
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.
oh..sorry, I misunderstood. definition.admins
is array.
expect(assigns(:definition).tags).to eq definition.tags | ||
end | ||
|
||
context 'with current_user and aother admin user' do |
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.
[typo] another?
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.
Thanks, I fixed it in 33ff102.
Add button for duplicate job definition to Job Definition Details page.
This allows us to duplicate the definition for similarly jobs.
On press the button, it open New Job Definition page with pre-filled the definition.
Before:
After: