Commit defa48ea authored by James Lopez's avatar James Lopez

update services and specs

parent 3a1ff1e3
module Emails
class BaseService
def initialize(user, opts)
def initialize(current_user, user, opts)
@current_user = current_user
@user = user
@email = opts[:email]
end
......
......@@ -7,7 +7,7 @@ module Emails
private
def update_secondary_emails!
result = ::Users::UpdateService.new(@user).execute do |user|
result = ::Users::UpdateService.new(@current_user, @user).execute do |user|
user.update_secondary_emails!
end
......
......@@ -2,7 +2,8 @@ module Users
class UpdateService < BaseService
include NewUserNotifier
def initialize(user, params = {})
def initialize(current_user, user, params = {})
@current_user = current_user
@user = user
@params = params.dup
end
......@@ -40,5 +41,9 @@ module Users
@user.assign_attributes(params) if params.any?
end
def model
@user
end
end
end
......@@ -4,7 +4,7 @@ describe Emails::CreateService 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
......
......@@ -4,7 +4,7 @@ describe Emails::DestroyService do
let!(:user) { create(:user) }
let!(:email) { create(:email, user: user) }
subject(:service) { described_class.new(user, email: email.email) }
subject(:service) { described_class.new(user, user, email: email.email) }
describe '#execute' do
it 'removes an email' do
......
......@@ -31,7 +31,7 @@ describe Users::UpdateService do
end
def update_user(user, opts)
described_class.new(user, opts).execute
described_class.new(user, user, opts).execute
end
end
......@@ -65,7 +65,7 @@ describe Users::UpdateService do
end
def update_user(user, opts)
described_class.new(user, opts).execute!
described_class.new(user, user, opts).execute!
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