2019-03-08 00:26:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ProjectCommentsController, type: :controller do
|
2021-09-14 18:45:44 +08:00
|
|
|
login_user
|
|
|
|
include_context 'reference_project_structure', {
|
2021-09-14 16:10:14 +08:00
|
|
|
project_comment: true
|
|
|
|
}
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'POST create' do
|
2019-03-08 00:26:42 +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-08 00:26:42 +08:00
|
|
|
let(:params) do
|
|
|
|
{ project_id: project.id,
|
|
|
|
comment: { message: 'test message' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :add_comment_to_project))
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-08 00:26:42 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'PUT update' do
|
2019-03-08 00:26:42 +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-08 00:26:42 +08:00
|
|
|
let(:params) do
|
|
|
|
{ project_id: project.id,
|
|
|
|
id: project_comment.id,
|
|
|
|
comment: { message: 'test message updated' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :edit_project_comment))
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-08 00:26:42 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'DELETE destroy' do
|
2019-03-08 00:26:42 +08:00
|
|
|
context 'in JSON format' do
|
2019-03-27 18:24:44 +08:00
|
|
|
let(:action) { delete :destroy, params: params, format: :json }
|
2019-03-08 00:26:42 +08:00
|
|
|
let(:params) do
|
|
|
|
{ project_id: project.id,
|
|
|
|
id: project_comment.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :delete_project_comment))
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-08 00:26:42 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|