From cabbfe94fcc929a48b8bf7402cd8cb1cc00612d6 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 16 Jun 2017 14:30:29 +0200 Subject: [PATCH] add more spec examples --- spec/services/emails/create_service_spec.rb | 12 +++++++++++- spec/services/emails/destroy_service_spec.rb | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/spec/services/emails/create_service_spec.rb b/spec/services/emails/create_service_spec.rb index c1f477f551e..7874da88665 100644 --- a/spec/services/emails/create_service_spec.rb +++ b/spec/services/emails/create_service_spec.rb @@ -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 diff --git a/spec/services/emails/destroy_service_spec.rb b/spec/services/emails/destroy_service_spec.rb index 0778b3f50da..186726951f9 100644 --- a/spec/services/emails/destroy_service_spec.rb +++ b/spec/services/emails/destroy_service_spec.rb @@ -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 -- GitLab