add more spec examples
This commit is contained in:
parent
3798e89459
commit
cabbfe94fc
|
@ -4,7 +4,7 @@ describe Emails::CreateService, services: true do
|
|||
let(:user) { create(:user) }
|
||||
let(:opts) { { email: 'new@email.com' } }
|
||||
|
||||
subject(:service) { described_class.new(user, opts) }
|
||||
subject(:service) { described_class.new(user, user, opts) }
|
||||
|
||||
describe '#execute' do
|
||||
it 'creates an email with valid attributes' do
|
||||
|
@ -17,5 +17,15 @@ describe Emails::CreateService, services: true do
|
|||
|
||||
expect(user.emails).to eq(Email.where(opts))
|
||||
end
|
||||
|
||||
it 'does not create an email if the user has no permissions' do
|
||||
expect { described_class.new(create(:user), user, opts).execute }.not_to change { Email.count }
|
||||
end
|
||||
|
||||
it 'creates an email if we skip authorization' do
|
||||
expect do
|
||||
described_class.new(create(:user), user, opts).execute(skip_authorization: true)
|
||||
end.to change { Email.count }.by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,11 +4,21 @@ describe Emails::DestroyService, services: true do
|
|||
let!(:user) { create(:user) }
|
||||
let!(:email) { create(:email, user: user) }
|
||||
|
||||
subject(:service) { described_class.new(user, opts) }
|
||||
subject(:service) { described_class.new(user, user, email: email.email) }
|
||||
|
||||
describe '#execute' do
|
||||
it 'creates an email with valid attributes' do
|
||||
it 'removes an email' do
|
||||
expect { service.execute }.to change { user.emails.count }.by(-1)
|
||||
end
|
||||
|
||||
it 'does not remove an email if the user has no permissions' do
|
||||
expect { described_class.new(create(:user), user, opts).execute }.not_to change { Email.count }
|
||||
end
|
||||
|
||||
it 'removes an email if we skip authorization' do
|
||||
expect do
|
||||
described_class.new(create(:user), user, opts).execute(skip_authorization: true)
|
||||
end.to change { Email.count }.by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue