user update service for update identifier action

pull/7647/head
ulferts 5 years ago
parent e0dda422e5
commit fc0e5bdfd2
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 8
      app/controllers/projects_controller.rb
  2. 11
      app/services/projects/update_service.rb
  3. 22
      spec/services/projects/update_service_spec.rb

@ -117,12 +117,14 @@ class ProjectsController < ApplicationController
end
def update_identifier
@project.attributes = permitted_params.project
service_call = Projects::UpdateService
.new(user: current_user,
model: @project)
.call(permitted_params.project)
if @project.save
if service_call.success?
flash[:notice] = I18n.t(:notice_successful_update)
redirect_to settings_project_path(@project)
OpenProject::Notifications.send('project_renamed', project: @project)
else
render action: 'identifier'
end

@ -33,9 +33,20 @@ module Projects
private
def after_save
touch_on_custom_values_update
notify_on_identifier_renamed
end
def touch_on_custom_values_update
model.touch if only_custom_values_updated?
end
def notify_on_identifier_renamed
return unless model.saved_change_to_identifier?
OpenProject::Notifications.send('project_renamed', project: model)
end
def only_custom_values_updated?
!model.saved_changes? && model.custom_values.any?(&:saved_changes?)
end

@ -100,7 +100,25 @@ describe Projects::UpdateService, type: :model do
.to eql project
end
context 'when the SetAttributeService is unsuccessful' do
context 'if the identifier is altered' do
let(:call_attributes) { { identifier: 'Some identifier' } }
before do
allow(project)
.to receive(:saved_change_to_identifier?)
.and_return(true)
end
it 'sends the notification' do
expect(OpenProject::Notifications)
.to receive(:send)
.with('project_renamed', project: project)
subject
end
end
context 'if the SetAttributeService is unsuccessful' do
let(:set_attributes_success) { false }
it 'is unsuccessful' do
@ -126,7 +144,7 @@ describe Projects::UpdateService, type: :model do
end
end
context 'when the project is invalid' do
context 'if the project is invalid' do
let(:project_valid) { false }
it 'is unsuccessful' do

Loading…
Cancel
Save