Files
openfoodnetwork/spec/services/create_mail_method_spec.rb
Pau Perez a7f1ed660b Add service to create a mail method
This will make loading sample data into staging environments easier.
2018-03-16 13:33:20 +01:00

42 lines
1.2 KiB
Ruby

require 'spec_helper'
describe CreateMailMethod do
describe '#call' do
let(:mail_method) { Spree::MailMethod.create(environment: 'test') }
let(:mail_settings) { instance_double(Spree::Core::MailSettings) }
let(:attributes) do
{ preferred_smtp_username: "smtp_username", environment: "test" }
end
before do
allow(Spree::MailMethod)
.to receive(:create).with(environment: 'test').and_return(mail_method)
allow(Spree::Core::MailSettings).to receive(:init) { mail_settings }
end
it 'creates a new MailMethod' do
described_class.new(attributes).call
expect(Spree::MailMethod)
.to have_received(:create).with(environment: 'test') { mail_method }
end
it 'updates the MailMethod' do
expect(mail_method)
.to(receive(:update_attributes)).with(attributes) { mail_method }
described_class.new(attributes).call
end
it 'updates the mail method attributes' do
described_class.new(attributes).call
expect(mail_method.preferred_smtp_username).to eq('smtp_username')
end
it 'initializes the mail settings' do
described_class.new(attributes).call
expect(Spree::Core::MailSettings).to have_received(:init)
end
end
end