2019-03-27 18:24:44 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe UserMyModulesController, type: :controller do
|
|
|
|
login_user
|
|
|
|
|
2021-09-16 17:52:18 +08:00
|
|
|
include_context 'reference_project_structure'
|
2021-09-09 21:41:42 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'POST create' do
|
|
|
|
let(:action) { post :create, params: params, format: :json }
|
|
|
|
let(:params) do
|
|
|
|
{ my_module_id: my_module.id, user_my_module: { user_id: user.id } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity for assigning user to task' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
2021-10-28 22:32:05 +08:00
|
|
|
.with(hash_including(activity_type: :designate_user_to_my_module)))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE destroy' do
|
|
|
|
let(:user_task) { create :user_my_module, user: user, my_module: my_module }
|
|
|
|
let(:action) { delete :destroy, params: params, format: :json }
|
|
|
|
let(:params) do
|
|
|
|
{ my_module_id: my_module.id, id: user_task.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity for unassigning user to task' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
2021-10-28 22:32:05 +08:00
|
|
|
.with(hash_including(activity_type: :undesignate_user_from_my_module)))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|