Commit defa48ea authored by James Lopez's avatar James Lopez

update services and specs

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