Skip to content

Commit

Permalink
add mailing clone api
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasritz committed Nov 6, 2020
1 parent c40ba74 commit a68ef15
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/crm/mailing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class Mailing < Core::BasicResource
# @!parse extend Core::Mixins::Modifiable::ClassMethods
# @!parse extend Core::Mixins::Searchable::ClassMethods

# Clones a mailing.
# @example
# mailing.clone
# # => Crm::Mailing
# @return [BasicResource] the cloned mailing.
# @api public
def clone
self.class.new(Core::RestApi.instance.post("#{path}/clone", {}))
end

# Renders a preview of the email for the given contact.
# @example
# mailing.html_body
Expand Down
11 changes: 11 additions & 0 deletions spec/crm/mailing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ module Crm
end
end

describe '#create' do
let(:mailing) { Mailing.new("id" => "abc") }

it 'clones a mailing' do
expect(Core::RestApi.instance).to receive(:post).with('mailings/abc/clone', {})
.and_return({"id" => "def"})
clone = mailing.clone
expect(clone.id).to eq('def')
end
end

describe '#render_preview' do
let(:mailing) { Mailing.new("id" => "abc") }
let(:preview_output) {
Expand Down
15 changes: 15 additions & 0 deletions spec/features/mailing_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@
end
end

describe 'clone' do
let(:mailing) do
Crm::Mailing.create({
title: 'My Mailing',
type_id: 'newsletter',
})
end

it 'clones the mailing' do
clone = mailing.clone
expect(clone.id).not_to eq(mailing.id)
expect(clone.title).to eq('My Mailing (Copy)')
end
end

describe 'changes' do
let(:mailing) do
Crm::Mailing.create({
Expand Down

0 comments on commit a68ef15

Please sign in to comment.