mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-04 19:53:19 +08:00
Edit and Archive experiment activity logging
This commit is contained in:
parent
1a3c97b978
commit
976831e7d3
2 changed files with 75 additions and 11 deletions
|
@ -107,17 +107,22 @@ class ExperimentsController < ApplicationController
|
|||
if @experiment.save
|
||||
|
||||
experiment_annotation_notification(old_text)
|
||||
Activity.create(
|
||||
type_of: :edit_experiment,
|
||||
project: @experiment.project,
|
||||
experiment: @experiment,
|
||||
user: current_user,
|
||||
message: I18n.t(
|
||||
'activities.edit_experiment',
|
||||
user: current_user.full_name,
|
||||
experiment: @experiment.name
|
||||
)
|
||||
)
|
||||
|
||||
activity_type_of = if experiment_params[:archived] == 'false'
|
||||
:restore_experiment
|
||||
else
|
||||
:edit_experiment
|
||||
end
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: activity_type_of,
|
||||
owner: current_user,
|
||||
subject: @experiment,
|
||||
project: @experiment.project,
|
||||
team: @experiment.project.team,
|
||||
message_items: {
|
||||
experiment: @experiment.id
|
||||
})
|
||||
|
||||
@experiment.touch(:workflowimg_updated_at)
|
||||
flash[:success] = t('experiments.update.success_flash',
|
||||
experiment: @experiment.name)
|
||||
|
|
59
spec/controllers/experiments_controller_sepc.rb
Normal file
59
spec/controllers/experiments_controller_sepc.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ExperimentsController, type: :controller do
|
||||
login_user
|
||||
|
||||
describe '#update' do
|
||||
let!(:user) { controller.current_user }
|
||||
let!(:team) { create :team, created_by: user, users: [user] }
|
||||
let!(:project) { create :project, team: team }
|
||||
let!(:user_project) do
|
||||
create :user_project, :owner, user: user, project: project
|
||||
end
|
||||
let(:experiment) { create :experiment, project: project }
|
||||
|
||||
context 'when editing experiment' do
|
||||
let(:params) do
|
||||
{
|
||||
id: experiment.id,
|
||||
experiment: { title: 'new_title' }
|
||||
}
|
||||
end
|
||||
|
||||
it 'calls create activity for editing experiment' do
|
||||
expect(Activities::CreateActivityService)
|
||||
.to(receive(:call)
|
||||
.with(hash_including(activity_type: :edit_experiment)))
|
||||
|
||||
put :update, params: params
|
||||
end
|
||||
end
|
||||
|
||||
context 'when archiving experiment' do
|
||||
let(:archived_experiment) do
|
||||
create :experiment,
|
||||
archived: true,
|
||||
archived_by: (create :user),
|
||||
archived_on: Time.now,
|
||||
project: project
|
||||
end
|
||||
|
||||
let(:archived_params) do
|
||||
{
|
||||
id: archived_experiment.id,
|
||||
experiment: { archived: false }
|
||||
}
|
||||
end
|
||||
|
||||
it 'calls create activity for unarchiving experiment' do
|
||||
expect(Activities::CreateActivityService)
|
||||
.to(receive(:call)
|
||||
.with(hash_including(activity_type: :restore_experiment)))
|
||||
|
||||
put :update, params: archived_params
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue