scinote-web/spec/controllers/result_comments_controller_spec.rb

75 lines
1.9 KiB
Ruby
Raw Normal View History

2019-03-14 02:05:29 +08:00
# 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
}
2021-09-09 21:41:42 +08:00
describe 'POST create' do
2019-03-14 02:05:29 +08:00
context 'in JSON format' do
let(:action) { post :create, params: params, format: :json }
2019-03-14 02:05:29 +08:00
let(:params) do
{ result_id: result_text.result.id,
2019-03-14 02:05:29 +08:00
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
2019-03-14 02:05:29 +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
describe 'PUT update' do
2019-03-14 02:05:29 +08:00
context 'in JSON format' do
let(:action) { put :update, params: params, format: :json }
2019-03-14 02:05:29 +08:00
let(:params) do
{ result_id: result_text.result.id,
id: result_text_comment.id,
2019-03-14 02:05:29 +08:00
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
2019-03-14 02:05:29 +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
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_text.result.id,
id: result_text_comment.id }
2019-03-14 02:05:29 +08:00
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :delete_result_comment))
action
end
2019-03-14 02:05:29 +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