mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-25 08:14:17 +08:00
Add new Protocol steps activities
This commit is contained in:
parent
b33e95e18a
commit
7a05e817ef
2 changed files with 111 additions and 4 deletions
|
@ -81,8 +81,7 @@ class StepsController < ApplicationController
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
# TODO: Activity for team if step
|
log_activity(:add_step_to_protocol_repository)
|
||||||
# created in protocol management??
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update protocol timestamp
|
# Update protocol timestamp
|
||||||
|
@ -201,8 +200,7 @@ class StepsController < ApplicationController
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
# TODO: Activity for team if step
|
log_activity(:edit_step_in_protocol_repository)
|
||||||
# updated in protocol management??
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update protocol timestamp
|
# Update protocol timestamp
|
||||||
|
@ -236,6 +234,8 @@ class StepsController < ApplicationController
|
||||||
team = @protocol.team
|
team = @protocol.team
|
||||||
previous_size = @step.space_taken
|
previous_size = @step.space_taken
|
||||||
|
|
||||||
|
log_activity(:delete_step_in_protocol_repository)
|
||||||
|
|
||||||
# Destroy the step
|
# Destroy the step
|
||||||
@step.destroy(current_user)
|
@step.destroy(current_user)
|
||||||
|
|
||||||
|
@ -651,4 +651,16 @@ class StepsController < ApplicationController
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|
95
spec/controllers/steps_controller_spec.rb
Normal file
95
spec/controllers/steps_controller_spec.rb
Normal 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
|
Loading…
Reference in a new issue