gitlab-org--gitlab-foss/spec/services/emails/create_service_spec.rb

29 lines
794 B
Ruby
Raw Normal View History

2019-03-22 14:56:06 +00:00
# frozen_string_literal: true
2017-06-16 12:07:56 +00:00
require 'spec_helper'
RSpec.describe Emails::CreateService do
2017-06-16 12:07:56 +00:00
let(:user) { create(:user) }
2017-09-27 14:39:10 +00:00
let(:opts) { { email: 'new@email.com', user: user } }
2017-06-16 12:07:56 +00:00
2017-06-23 17:00:22 +00:00
subject(:service) { described_class.new(user, opts) }
2017-06-16 12:07:56 +00: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
it 'creates an email with additional attributes' do
expect { service.execute(confirmation_token: 'abc') }.to change { Email.count }.by(1)
expect(Email.find_by(opts).confirmation_token).to eq 'abc'
end
2017-06-16 12:07:56 +00:00
it 'has the right user association' do
service.execute
expect(user.emails).to eq(Email.where(opts))
end
end
end