2021-05-16 17:04:04 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe MyModuleMember, type: :model do
|
2021-09-30 17:32:11 +08:00
|
|
|
# let(:owner_role) { create :owner_role }
|
2021-05-16 17:04:04 +08:00
|
|
|
let!(:user) { create :user }
|
2021-09-30 17:32:11 +08:00
|
|
|
let!(:owner_role) { UserRole.find_by(name: I18n.t('user_roles.predefined.owner')) }
|
2022-03-09 21:12:16 +08:00
|
|
|
let!(:project) { create :project, created_by: user }
|
|
|
|
let!(:experiment) { create :experiment, project: project, created_by: project.created_by }
|
|
|
|
let!(:my_module) { create :my_module, experiment: experiment, created_by: experiment.created_by }
|
2021-05-16 17:04:04 +08:00
|
|
|
let(:normal_user_role) { create :normal_user_role }
|
|
|
|
|
2021-05-23 00:36:30 +08:00
|
|
|
describe '#update' do
|
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
|
|
|
|
2022-03-09 21:12:16 +08:00
|
|
|
let!(:subject) { described_class.new(user, my_module, experiment, project, user) }
|
2021-05-23 00:36:30 +08:00
|
|
|
|
|
|
|
it 'updates the assigment user role' do
|
|
|
|
subject.update(valid_params)
|
2022-03-09 21:12:16 +08:00
|
|
|
expect(subject.user_assignment.user_role).to eq normal_user_role
|
2021-05-23 00:36:30 +08:00
|
|
|
end
|
|
|
|
|
2021-05-22 19:59:27 +08:00
|
|
|
it 'logs a change_user_role_on_my_module activity' do
|
|
|
|
expect {
|
|
|
|
subject.update(valid_params)
|
|
|
|
}.to change(Activity, :count).by(1)
|
|
|
|
expect(Activity.last.type_of).to eq 'change_user_role_on_my_module'
|
|
|
|
end
|
2021-05-16 17:04:04 +08:00
|
|
|
end
|
|
|
|
end
|