Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/controllers/api/v2/webhook_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ def destroy
param :id, :identifier, required: true
param_group :webhook_template_clone, as: :create
def clone
@webhook_template = @webhook_template.dup
original = @webhook_template
@webhook_template = original.dup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to discard taxonomy associations, but that wasn't introduced here so I'd be willing to leave it for a later issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree

@webhook_template.cloned_from = original
@webhook_template.name = params[:webhook_template][:name]
@webhook_template.locked = false
process_response @webhook_template.save
end

Expand Down
5 changes: 4 additions & 1 deletion test/controllers/api/v2/webhook_templates_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,16 @@ def setup
end

test 'should clone template' do
original_webhook_template = FactoryBot.create(:webhook_template)
original_webhook_template = FactoryBot.create(:webhook_template, locked: true)
post :clone, params: { id: original_webhook_template.to_param,
webhook_template: { name: 'MyClone' } }
assert_response :success
template = ActiveSupport::JSON.decode(@response.body)
assert_equal(template['name'], 'MyClone')
assert_equal(template['template'], original_webhook_template.template)
refute_equal(template['id'], original_webhook_template.id, 'Clone ID different from original')
assert_equal(template['cloned_from_id'], original_webhook_template.id)
assert_equal(template['locked'], false)
refute_equal(template['id'], original_webhook_template.id)
end

Expand Down
Loading