Skip to content
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

Merged
merged 2 commits into from
Jan 25, 2018

Conversation

takonomura
Copy link
Contributor

@takonomura takonomura commented Jan 18, 2018

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:
before
After:
after

@ganmacs
Copy link
Contributor

ganmacs commented Jan 18, 2018

@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(',')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change needed?

Copy link
Contributor Author

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"]

Copy link
Contributor

@ganmacs ganmacs Jan 19, 2018

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

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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' ?

Copy link
Contributor Author

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
Copy link
Contributor

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'

@takonomura takonomura force-pushed the feature/duplicate-job-definition branch from d4a8bf3 to 047f318 Compare January 18, 2018 08:01
expect(response).to have_http_status(:ok)
expect(response).to render_template('new')

expect(assigns(:definition)).to be_new_record
Copy link
Member

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)
Copy link
Member

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)

@takonomura takonomura force-pushed the feature/duplicate-job-definition branch from 047f318 to a543c3e Compare January 19, 2018 00:43
Copy link
Contributor

@ganmacs ganmacs left a 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]
Copy link
Contributor

@ganmacs ganmacs Jan 22, 2018

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[typo] another?

Copy link
Contributor Author

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.

@ganmacs ganmacs merged commit 926f983 into cookpad:master Jan 25, 2018
@takonomura takonomura deleted the feature/duplicate-job-definition branch January 29, 2018 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants