Commit cabbfe94 authored by James Lopez's avatar James Lopez

add more spec examples

parent 3798e894
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment