debian-mirror-gitlab/spec/services/emails/create_service_spec.rb

29 lines
792 B
Ruby
Raw Normal View History

2019-05-18 00:54:41 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
describe Emails::CreateService do
let(:user) { create(:user) }
2018-03-17 18:26:18 +05:30
let(:opts) { { email: 'new@email.com', user: user } }
2017-09-10 17:25:29 +05:30
subject(:service) { described_class.new(user, opts) }
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
2018-03-17 18:26:18 +05:30
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-09-10 17:25:29 +05:30
it 'has the right user association' do
service.execute
expect(user.emails).to eq(Email.where(opts))
end
end
end