scinote-web/spec/controllers/project_comments_controller_spec.rb

86 lines
2.2 KiB
Ruby
Raw Normal View History

2019-03-08 00:26:42 +08:00
# frozen_string_literal: true
require 'rails_helper'
describe ProjectCommentsController, type: :controller do
login_user
2019-03-21 04:34:47 +08:00
let(:user) { subject.current_user }
2019-03-08 00:26:42 +08:00
let(:team) { create :team, created_by: user }
let(:user_team) { create :user_team, team: team, user: user }
let(:user_project) { create :user_project, :owner, user: user }
let(:project) do
create :project, team: team, user_projects: [user_project]
end
let(:project_comment) do
create :project_comment, project: project, user: user
end
describe 'POST create' do
2019-03-08 00:26:42 +08:00
context 'in JSON format' do
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))
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
describe 'PUT update' do
2019-03-08 00:26:42 +08:00
context 'in JSON format' do
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))
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
describe 'DELETE destroy' do
2019-03-08 00:26:42 +08:00
context 'in JSON format' do
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))
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