diff options
author | James Lopez <james@jameslopez.es> | 2017-06-16 15:30:29 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-06-23 12:41:42 +0300 |
commit | cabbfe94fcc929a48b8bf7402cd8cb1cc00612d6 (patch) | |
tree | 169fcebad1733bc1c3ea256b6c46eab1fb9bb475 /spec | |
parent | 3798e894594c6056df5bea2daa65f10bc19843d0 (diff) |
add more spec examples
Diffstat (limited to 'spec')
-rw-r--r-- | spec/services/emails/create_service_spec.rb | 12 | ||||
-rw-r--r-- | 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 |