2019-03-14 02:05:29 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ResultCommentsController, type: :controller do
|
|
|
|
login_user
|
|
|
|
|
2019-03-21 04:34:47 +08:00
|
|
|
let(:user) { subject.current_user }
|
|
|
|
let!(:team) { create :team, created_by: user, users: [user] }
|
2019-03-14 02:05:29 +08:00
|
|
|
let(:project) do
|
2021-09-09 21:41:42 +08:00
|
|
|
create :project, team: team
|
2021-05-29 23:25:20 +08:00
|
|
|
end
|
2021-09-09 21:41:42 +08:00
|
|
|
let(:owner_role) { create :owner_role }
|
|
|
|
|
2019-03-14 02:05:29 +08:00
|
|
|
let(:experiment) { create :experiment, project: project }
|
|
|
|
let(:task) { create :my_module, name: 'test task', experiment: experiment }
|
|
|
|
let(:result) do
|
|
|
|
create :result, name: 'test result', my_module: task, user: user
|
|
|
|
end
|
|
|
|
let!(:result_text) do
|
|
|
|
create :result_text, text: 'test text result', result: result
|
|
|
|
end
|
|
|
|
let(:result_comment) do
|
|
|
|
create :result_comment, message: 'test comment result',
|
|
|
|
result: result,
|
|
|
|
user: user
|
|
|
|
end
|
|
|
|
|
2021-09-09 21:41:42 +08:00
|
|
|
before do
|
|
|
|
create_user_assignment(task, owner_role, user)
|
|
|
|
end
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'POST create' do
|
2019-03-14 02:05:29 +08:00
|
|
|
context 'in JSON format' do
|
2019-03-27 18:24:44 +08:00
|
|
|
let(:action) { post :create, params: params, format: :json }
|
2019-03-14 02:05:29 +08:00
|
|
|
let(:params) do
|
|
|
|
{ result_id: result.id,
|
|
|
|
comment: { message: 'test comment' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :add_comment_to_result))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
2019-03-14 02:05:29 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-14 02:05:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'PUT update' do
|
2019-03-14 02:05:29 +08:00
|
|
|
context 'in JSON format' do
|
2019-03-27 18:24:44 +08:00
|
|
|
let(:action) { put :update, params: params, format: :json }
|
2019-03-14 02:05:29 +08:00
|
|
|
let(:params) do
|
|
|
|
{ result_id: result.id,
|
|
|
|
id: result_comment.id,
|
|
|
|
comment: { message: 'test comment updated' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :edit_result_comment))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
2019-03-14 02:05:29 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-14 02:05:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'DELETE destroy' do
|
|
|
|
let(:action) { delete :destroy, params: params, format: :json }
|
2019-03-14 02:05:29 +08:00
|
|
|
let(:params) do
|
|
|
|
{ result_id: result.id,
|
|
|
|
id: result_comment.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :delete_result_comment))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
2019-03-14 02:05:29 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-14 02:05:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|