Merge pull request #2590 from luisramos0/spree2_mail_method_create

Spree 2 - MailMethod - CreateMailMethod is now MailConfiguration
This commit is contained in:
Pau Pérez Fabregat
2018-09-10 12:08:23 +02:00
committed by GitHub
5 changed files with 67 additions and 101 deletions

View File

@@ -1,49 +0,0 @@
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
context 'unit' do
before do
allow(mail_method).to receive(:update_attributes).with(attributes)
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
described_class.new(attributes).call
expect(mail_method)
.to have_received(:update_attributes).with(attributes) { mail_method }
end
it 'initializes the mail settings' do
described_class.new(attributes).call
expect(Spree::Core::MailSettings).to have_received(:init)
end
end
context 'integration' do
it 'updates the mail method attributes' do
described_class.new(attributes).call
expect(mail_method.preferred_smtp_username).to eq('smtp_username')
end
end
end
end

View File

@@ -0,0 +1,34 @@
require 'spec_helper'
describe MailConfiguration do
describe 'entries=' do
let(:mail_settings) { instance_double(Spree::Core::MailSettings) }
let(:entries) do
{ smtp_username: "smtp_username", mail_auth_type: "login" }
end
before do
allow(Spree::Core::MailSettings).to receive(:init) { mail_settings }
end
# keeps spree_config unchanged
around do |example|
original_smtp_username = Spree::Config[:smtp_username]
original_mail_auth_type = Spree::Config[:mail_auth_type]
example.run
Spree::Config[:smtp_username] = original_smtp_username
Spree::Config[:mail_auth_type] = original_mail_auth_type
end
it 'sets config entries in the Spree Config' do
described_class.entries= entries
expect(Spree::Config[:smtp_username]).to eq("smtp_username")
expect(Spree::Config[:mail_auth_type]).to eq("login")
end
it 'initializes the mail settings' do
described_class.entries= entries
expect(Spree::Core::MailSettings).to have_received(:init)
end
end
end