mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
experiment activities refactoring
This commit is contained in:
parent
2e987ceed3
commit
70eebca5ee
6 changed files with 81 additions and 66 deletions
|
@ -45,19 +45,8 @@ class ExperimentsController < ApplicationController
|
|||
@experiment.last_modified_by = current_user
|
||||
@experiment.project = @project
|
||||
if @experiment.save
|
||||
|
||||
experiment_annotation_notification
|
||||
Activity.create(
|
||||
type_of: :create_experiment,
|
||||
project: @experiment.project,
|
||||
experiment: @experiment,
|
||||
user: current_user,
|
||||
message: I18n.t(
|
||||
'activities.create_experiment',
|
||||
user: current_user.full_name,
|
||||
experiment: @experiment.name
|
||||
)
|
||||
)
|
||||
log_activity(:create_experiment)
|
||||
flash[:success] = t('experiments.create.success_flash',
|
||||
experiment: @experiment.name)
|
||||
respond_to do |format|
|
||||
|
@ -105,7 +94,6 @@ class ExperimentsController < ApplicationController
|
|||
@experiment.last_modified_by = current_user
|
||||
|
||||
if @experiment.save
|
||||
|
||||
experiment_annotation_notification(old_text)
|
||||
|
||||
activity_type = if experiment_params[:archived] == 'false'
|
||||
|
@ -113,15 +101,7 @@ class ExperimentsController < ApplicationController
|
|||
else
|
||||
:edit_experiment
|
||||
end
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: activity_type,
|
||||
owner: current_user,
|
||||
subject: @experiment,
|
||||
project: @experiment.project,
|
||||
team: @experiment.project.team,
|
||||
message_items: {
|
||||
experiment: @experiment.id
|
||||
})
|
||||
log_activity(activity_type)
|
||||
|
||||
@experiment.touch(:workflowimg_updated_at)
|
||||
flash[:success] = t('experiments.update.success_flash',
|
||||
|
@ -153,17 +133,7 @@ class ExperimentsController < ApplicationController
|
|||
@experiment.archived_by = current_user
|
||||
@experiment.archived_on = DateTime.now
|
||||
if @experiment.save
|
||||
Activity.create(
|
||||
type_of: :archive_experiment,
|
||||
project: @experiment.project,
|
||||
experiment: @experiment,
|
||||
user: current_user,
|
||||
message: I18n.t(
|
||||
'activities.archive_experiment',
|
||||
user: current_user.full_name,
|
||||
experiment: @experiment.name
|
||||
)
|
||||
)
|
||||
log_activity(:archive_experiment)
|
||||
flash[:success] = t('experiments.archive.success_flash',
|
||||
experiment: @experiment.name)
|
||||
|
||||
|
@ -351,4 +321,14 @@ class ExperimentsController < ApplicationController
|
|||
canvas_experiment_url(@experiment)))
|
||||
)
|
||||
end
|
||||
|
||||
def log_activity(type_of)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
team: @experiment.project.team,
|
||||
project: @experiment.project,
|
||||
subject: @experiment,
|
||||
message_items: { experiment: @experiment.id })
|
||||
end
|
||||
end
|
||||
|
|
|
@ -86,18 +86,14 @@ module Experiments
|
|||
end
|
||||
|
||||
def track_activity
|
||||
Activity.create(
|
||||
type_of: :clone_experiment,
|
||||
project: @project,
|
||||
experiment: @exp,
|
||||
user: @user,
|
||||
message: I18n.t(
|
||||
'activities.clone_experiment',
|
||||
user: @user,
|
||||
experiment_new: @c_exp.name,
|
||||
experiment_original: @exp.name
|
||||
)
|
||||
)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: :clone_experiment,
|
||||
owner: @user,
|
||||
team: @project.team,
|
||||
project: @project,
|
||||
subject: @exp,
|
||||
message_items: { experiment_new: @c_exp.id,
|
||||
experiment_original: @exp.id })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -73,20 +73,15 @@ module Experiments
|
|||
end
|
||||
|
||||
def track_activity
|
||||
Activity.create(
|
||||
type_of: :move_experiment,
|
||||
project: @project,
|
||||
team: @project.team,
|
||||
subject: @exp,
|
||||
owner: @user,
|
||||
message: I18n.t(
|
||||
'activities.move_experiment',
|
||||
user: @user,
|
||||
experiment: @exp.name,
|
||||
project_new: @project.name,
|
||||
project_original: @original_project.name
|
||||
)
|
||||
)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: :move_experiment,
|
||||
owner: @user,
|
||||
team: @project.team,
|
||||
project: @project,
|
||||
subject: @exp,
|
||||
message_items: { experiment: @exp.id,
|
||||
project_new: @project.id,
|
||||
project_original: @original_project.id })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,14 +5,30 @@ require 'rails_helper'
|
|||
describe ExperimentsController, type: :controller do
|
||||
login_user
|
||||
|
||||
describe 'PUT 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
|
||||
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 }
|
||||
|
||||
describe '#create' do
|
||||
let(:params) do
|
||||
{ project_id: project.id,
|
||||
experiment: { name: 'test experiment A1',
|
||||
description: 'test description one' } }
|
||||
end
|
||||
let(:experiment) { create :experiment, project: project }
|
||||
|
||||
it 'calls create activity service' do
|
||||
expect(Activities::CreateActivityService).to receive(:call)
|
||||
.with(hash_including(activity_type: :create_experiment))
|
||||
|
||||
post :create, params: params, format: :json
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
let(:action) { put :update, params: params }
|
||||
|
||||
context 'when editing experiment' do
|
||||
|
@ -67,4 +83,18 @@ describe ExperimentsController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#archive' do
|
||||
let(:params) do
|
||||
{ id: experiment.id,
|
||||
experiment: { name: 'test experiment A1',
|
||||
description: 'test description one' } }
|
||||
end
|
||||
it 'calls create activity service' do
|
||||
expect(Activities::CreateActivityService).to receive(:call)
|
||||
.with(hash_including(activity_type: :archive_experiment))
|
||||
|
||||
get :archive, params: params, format: :json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,6 +32,13 @@ describe Experiments::CopyExperimentAsTemplateService do
|
|||
expect { service_call }.to(change { Activity.all.count })
|
||||
end
|
||||
|
||||
it 'calls create activity service' do
|
||||
expect(Activities::CreateActivityService).to receive(:call)
|
||||
.with(hash_including(activity_type: :clone_experiment))
|
||||
|
||||
service_call
|
||||
end
|
||||
|
||||
it 'copies all tasks to new experiment' do
|
||||
expect(service_call.cloned_experiment.my_modules.count)
|
||||
.to be == experiment.my_modules.count
|
||||
|
|
|
@ -54,6 +54,13 @@ describe Experiments::MoveToProjectService do
|
|||
it 'adds Activity record' do
|
||||
expect { service_call }.to(change { Activity.all.count })
|
||||
end
|
||||
|
||||
it 'calls create activity service' do
|
||||
expect(Activities::CreateActivityService).to receive(:call)
|
||||
.with(hash_including(activity_type: :move_experiment))
|
||||
|
||||
service_call
|
||||
end
|
||||
end
|
||||
|
||||
context 'when call with invalid params' do
|
||||
|
|
Loading…
Reference in a new issue