mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 23:21:30 +08:00
74 lines
1.9 KiB
Ruby
74 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe ResultCommentsController, type: :controller do
|
|
login_user
|
|
|
|
include_context 'reference_project_structure', {
|
|
result_text: true,
|
|
result_comment: true
|
|
}
|
|
|
|
describe 'POST create' do
|
|
context 'in JSON format' do
|
|
let(:action) { post :create, params: params, format: :json }
|
|
let(:params) do
|
|
{ result_id: result_text.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))
|
|
action
|
|
end
|
|
|
|
it 'adds activity in DB' do
|
|
expect { action }
|
|
.to(change { Activity.count })
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'PUT update' do
|
|
context 'in JSON format' do
|
|
let(:action) { put :update, params: params, format: :json }
|
|
let(:params) do
|
|
{ result_id: result_text.result.id,
|
|
id: result_text_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))
|
|
action
|
|
end
|
|
|
|
it 'adds activity in DB' do
|
|
expect { action }
|
|
.to(change { Activity.count })
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'DELETE destroy' do
|
|
let(:action) { delete :destroy, params: params, format: :json }
|
|
let(:params) do
|
|
{ result_id: result_text.result.id,
|
|
id: result_text_comment.id }
|
|
end
|
|
|
|
it 'calls create activity service' do
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
.with(hash_including(activity_type: :delete_result_comment))
|
|
action
|
|
end
|
|
|
|
it 'adds activity in DB' do
|
|
expect { action }
|
|
.to(change { Activity.count })
|
|
end
|
|
end
|
|
end
|