2019-03-11 20:26:54 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ReportsController, type: :controller do
|
|
|
|
login_user
|
|
|
|
|
2019-03-21 04:34:47 +08:00
|
|
|
let(:user) { subject.current_user }
|
2019-03-11 20:26:54 +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(:report) do
|
|
|
|
create :report, user: user, project: project, team: team,
|
|
|
|
name: 'test repot A1', description: 'test description A1'
|
|
|
|
end
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'POST create' do
|
2019-03-11 20:26:54 +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-11 20:26:54 +08:00
|
|
|
let(:params) do
|
|
|
|
{ project_id: project.id,
|
|
|
|
report: { name: 'test report created',
|
|
|
|
description: 'test description created' },
|
|
|
|
report_contents: '[{"type_of":"project_header","id":{"project_id":' +
|
|
|
|
project.id.to_s + '},"sort_order":null,"children":[]}]' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :create_report))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
2019-03-11 20:26:54 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-11 20:26:54 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'PUT update' do
|
2019-03-11 20:26:54 +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-11 20:26:54 +08:00
|
|
|
let(:params) do
|
|
|
|
{ project_id: project.id,
|
|
|
|
id: report.id,
|
|
|
|
report: { name: 'test report update',
|
|
|
|
description: 'test description update' },
|
|
|
|
report_contents: '[{"type_of":"project_header","id":{"project_id":' +
|
|
|
|
project.id.to_s + '},"sort_order":null,"children":[]}]' }
|
|
|
|
end
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :edit_report))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
2019-03-11 20:26:54 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-11 20:26:54 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'DELETE destroy' do
|
|
|
|
let(:action) { delete :destroy, params: params }
|
2019-03-11 20:26:54 +08:00
|
|
|
let(:params) { { report_ids: "[#{report.id}]" } }
|
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :delete_report))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
2019-03-11 20:26:54 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-11 20:26:54 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|