Add new Protocol steps activities

This commit is contained in:
Urban Rotnik 2019-03-08 17:01:59 +01:00
parent b33e95e18a
commit 7a05e817ef
2 changed files with 111 additions and 4 deletions

View file

@ -81,8 +81,7 @@ class StepsController < ApplicationController
)
)
else
# TODO: Activity for team if step
# created in protocol management??
log_activity(:add_step_to_protocol_repository)
end
# Update protocol timestamp
@ -201,8 +200,7 @@ class StepsController < ApplicationController
)
)
else
# TODO: Activity for team if step
# updated in protocol management??
log_activity(:edit_step_in_protocol_repository)
end
# Update protocol timestamp
@ -236,6 +234,8 @@ class StepsController < ApplicationController
team = @protocol.team
previous_size = @step.space_taken
log_activity(:delete_step_in_protocol_repository)
# Destroy the step
@step.destroy(current_user)
@ -651,4 +651,16 @@ class StepsController < ApplicationController
]
)
end
def log_activity(type_of)
Activities::CreateActivityService
.call(activity_type: type_of,
owner: current_user,
subject: @protocol,
team: current_team,
message_items: {
protocol: @protocol.id,
step: @step.id
})
end
end

View file

@ -0,0 +1,95 @@
# frozen_string_literal: true
require 'rails_helper'
describe StepsController, type: :controller do
login_user
let(:user) { subject.current_user }
let(:team) { create :team, created_by: user }
let!(:user_team) { create :user_team, :admin, user: user, team: team }
let(:protocol) do
create :protocol, :in_public_repository, team: team, added_by: user
end
let(:step) { create :step, protocol: protocol }
describe 'POST create' do
context 'when in protocol repository' do
let(:params) do
{
protocol_id: protocol.id,
step: {
name: 'test',
description: 'description'
}
}
end
let(:action) { post :create, params: params, format: :json }
it 'calls create activity for creating step in protocol repository' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type:
:add_step_to_protocol_repository)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end
describe 'PUT update' do
context 'when in protocol repository' do
let(:params) do
{
id: step.id,
protocol_id: protocol.id,
step: {
name: 'updated name',
description: 'updated description'
}
}
end
let(:action) { put :update, params: params, format: :json }
it 'calls create activity for editing step in protocol repository' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type:
:edit_step_in_protocol_repository)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end
describe 'DELETE destroy' do
context 'when in protocol repository' do
let(:params) { { id: step.id } }
let(:action) { delete :destroy, params: params, format: :json }
it 'calls create activity for deleting step in protocol repository' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type:
:delete_step_in_protocol_repository)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end
end