2017-06-16 08:07:56 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Emails::CreateService do
|
2017-06-16 08:07:56 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-09-27 10:39:10 -04:00
|
|
|
let(:opts) { { email: 'new@email.com', user: user } }
|
2017-06-16 08:07:56 -04:00
|
|
|
|
2017-06-23 13:00:22 -04:00
|
|
|
subject(:service) { described_class.new(user, opts) }
|
2017-06-16 08:07:56 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'creates an email with valid attributes' do
|
|
|
|
expect { service.execute }.to change { Email.count }.by(1)
|
|
|
|
expect(Email.where(opts)).not_to be_empty
|
|
|
|
end
|
|
|
|
|
2017-09-13 09:02:27 -04:00
|
|
|
it 'creates an email with additional attributes' do
|
|
|
|
expect { service.execute(confirmation_token: 'abc') }.to change { Email.count }.by(1)
|
|
|
|
expect(Email.where(opts).first.confirmation_token).to eq 'abc'
|
|
|
|
end
|
|
|
|
|
2017-06-16 08:07:56 -04:00
|
|
|
it 'has the right user association' do
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(user.emails).to eq(Email.where(opts))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|