Merge pull request #2496 from aignatov-bio/ai-sci-4471-assign-user-after-task-create

Assign user after task created [SCI-4471]
This commit is contained in:
Alex Kriuchykhin 2020-04-06 10:25:19 +02:00 committed by GitHub
commit f92d68d192
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 3 deletions

View file

@ -293,6 +293,8 @@ class Experiment < ApplicationRecord
my_module.last_modified_by = current_user
my_module.save!
my_module.assign_user(current_user)
ids_map[m[:id]] = my_module.id.to_s
end
my_modules.reload

View file

@ -539,6 +539,21 @@ class MyModule < ApplicationRecord
end
end
def assign_user(user, assigned_by = nil)
user_my_modules.create(
assigned_by: assigned_by || user,
user: user
)
Activities::CreateActivityService
.call(activity_type: :assign_user_to_module,
owner: assigned_by || user,
team: experiment.project.team,
project: experiment.project,
subject: self,
message_items: { my_module: id,
user_target: user.id })
end
private
def create_blank_protocol

View file

@ -32,6 +32,9 @@ class CreateMyModuleService
@my_module.save!
create_my_module_activity
@my_module.assign_user(@user)
@params[:experiment].generate_workflow_img
new_my_module = @my_module
end

View file

@ -103,7 +103,9 @@ describe Experiment, type: :model do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :create_module)))
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :assign_user_to_module)))
function_call
end
@ -137,12 +139,15 @@ describe Experiment, type: :model do
.to(receive(:call)
.with(hash_including(activity_type:
:clone_module))).exactly(3).times
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type:
:assign_user_to_module))).exactly(3).times
function_call
end
it 'creats 3 new activities in DB' do
expect { function_call }.to change { Activity.all.count }.by(3)
expect { function_call }.to change { Activity.all.count }.by(6)
end
end