scinote-web/spec/controllers/user_projects_controller_spec.rb

90 lines
2.6 KiB
Ruby
Raw Normal View History

2019-03-08 00:26:42 +08:00
# frozen_string_literal: true
require 'rails_helper'
describe UserProjectsController, 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(:user_two) { create :user }
let(:target_user) { create :user }
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(:target_user_project) do
create :user_project, :normal_user, user: target_user
end
let(:project) do
create :project, team: team, user_projects: [user_project,
target_user_project]
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,
user_project: { user_id: user_two.id,
project_id: project.id,
role: :owner } }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :assign_user_to_project))
action
end
2019-03-08 00:26:42 +08:00
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: target_user_project.id,
user_project: { user_id: target_user.id,
project_id: project.id,
role: :viewer } }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :change_user_role_on_project))
action
end
2019-03-08 00:26:42 +08:00
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: target_user_project.id }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :unassign_user_from_project))
action
end
2019-03-08 00:26:42 +08:00
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
2019-03-08 00:26:42 +08:00
end
end
end
end