2021-05-16 17:04:04 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ExperimentMember, type: :model do
|
|
|
|
let(:owner_role) { create :owner_role }
|
|
|
|
let!(:user) { create :user }
|
|
|
|
let!(:project) { create :project }
|
|
|
|
let!(:user_project) { create :user_project, user: user, project: project }
|
2021-05-30 01:25:46 +08:00
|
|
|
let!(:user_assignment) do
|
2021-05-22 20:41:56 +08:00
|
|
|
create :user_assignment,
|
|
|
|
assignable: project,
|
|
|
|
user: user,
|
|
|
|
user_role: owner_role,
|
|
|
|
assigned_by: user
|
2021-05-30 01:25:46 +08:00
|
|
|
end
|
2021-05-16 17:04:04 +08:00
|
|
|
let!(:experiment) { create :experiment, project: project }
|
|
|
|
let(:normal_user_role) { create :normal_user_role }
|
|
|
|
|
|
|
|
let(:subject) { described_class.new(user, experiment, project) }
|
|
|
|
|
2021-05-23 00:36:30 +08:00
|
|
|
describe '#update' do
|
2021-05-30 01:25:46 +08:00
|
|
|
let!(:experiment_user_assignment) do
|
2021-05-23 00:36:30 +08:00
|
|
|
create :user_assignment,
|
|
|
|
assignable: experiment,
|
|
|
|
user: user,
|
|
|
|
user_role: owner_role,
|
|
|
|
assigned_by: user
|
2021-05-30 01:25:46 +08:00
|
|
|
end
|
2021-05-23 00:36:30 +08:00
|
|
|
|
2021-05-30 01:25:46 +08:00
|
|
|
let!(:valid_params) do
|
2021-05-23 00:36:30 +08:00
|
|
|
{
|
|
|
|
user_id: user.id,
|
|
|
|
user_role_id: normal_user_role.id
|
|
|
|
}
|
2021-05-30 01:25:46 +08:00
|
|
|
end
|
2021-05-23 00:36:30 +08:00
|
|
|
|
|
|
|
let!(:subject) { described_class.new(user, experiment, project, user, experiment_user_assignment) }
|
|
|
|
|
|
|
|
it 'updates the assigment user role' do
|
|
|
|
subject.update(valid_params)
|
|
|
|
expect(experiment_user_assignment.reload.user_role).to eq normal_user_role
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs a change_user_role_on_my_module activity' do
|
2021-05-22 19:59:27 +08:00
|
|
|
expect {
|
|
|
|
subject.update(valid_params)
|
|
|
|
}.to change(Activity, :count).by(1)
|
|
|
|
expect(Activity.last.type_of).to eq 'change_user_role_on_experiment'
|
|
|
|
end
|
2021-05-16 17:04:04 +08:00
|
|
|
end
|
|
|
|
end
|