diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 2940c8481..69be6c2c8 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -131,9 +131,6 @@ class Users::RegistrationsController < Devise::RegistrationsController @team.created_by = resource # set created_by for oraganization @team.save - # Add this user to the team as owner - UserTeam.create(user: resource, team: @team, role: :admin) - # set current team to new user resource.current_team_id = @team.id resource.save @@ -171,9 +168,6 @@ class Users::RegistrationsController < Devise::RegistrationsController @team.created_by = @user # set created_by for team @team.save! - # Add this user to the team as owner - UserTeam.create(user: @user, team: @team, role: :admin) - # set current team to new user @user.current_team_id = @team.id @user.save! diff --git a/features/step_definitions/shared_steps.rb b/features/step_definitions/shared_steps.rb index cfff97f38..cc0d6d3ac 100644 --- a/features/step_definitions/shared_steps.rb +++ b/features/step_definitions/shared_steps.rb @@ -6,7 +6,6 @@ Given(/^the following users are registered:$/) do |table| team_role = hash.delete 'role' user = FactoryBot.create(:user, hash) team = FactoryBot.create(:team, name: team_name, users: [user]) - UserTeam.where(user: user, team: team).first.update role: team_role User.find_by(email: hash.fetch('email')).confirm end end @@ -87,7 +86,6 @@ end Given(/^Templates project exists for the "([^"]*)" team$/) do |team_name| team = Team.find_by(name: team_name) - user = team.user_teams.where(role: :admin).take.user TemplatesService.new.schedule_creation_for_user(user) end Given(/^I'm on the projects page of "([^"]*)" team$/) do |team_name| @@ -99,9 +97,6 @@ end Given(/^"([^"]*)" is in "([^"]*)" team as a "([^"]*)"$/) do |user_email, team_name, role| team = Team.find_by(name: team_name) user = User.find_by(email: user_email) - FactoryBot.create(:user_team, user: user, - team: team, role: - UserTeam.roles.fetch(role)) end Then(/^I attach a "([^"]*)" file to "([^"]*)" field$/) do |file, field_id| diff --git a/features/step_definitions/team_steps.rb b/features/step_definitions/team_steps.rb index d0e9264f8..4ce1cbf79 100644 --- a/features/step_definitions/team_steps.rb +++ b/features/step_definitions/team_steps.rb @@ -40,7 +40,6 @@ Given('the following users are registered with teams:') do |table| team = Team.find_by(name: row[:team]) team ||= FactoryBot.create(:team, name: row[:team]) user = FactoryBot.create(:user, row.slice('name', 'email')) - FactoryBot.create(:user_team, user: user, team: team, role: row[:role]) end end diff --git a/spec/controllers/user_teams_controller_spec.rb b/spec/controllers/user_teams_controller_spec.rb deleted file mode 100644 index e92587719..000000000 --- a/spec/controllers/user_teams_controller_spec.rb +++ /dev/null @@ -1,88 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Users::Settings::UserTeamsController, type: :controller do - login_user - - let(:user) { subject.current_user } - let(:team) { create :team, created_by: user } - let!(:user_team) { create :user_team, :admin, user: user, team: team } - let(:another_user) { create :user } - let!(:another_user_team) do - create :user_team, :normal_user, user: another_user, team: team - end - describe 'DELETE destroy' do - let(:params) do - { - id: another_user_team.id - } - end - let(:action) { delete :destroy, params: params, format: :json } - - context 'when inviting existing user not in the team' do - it 'calls create activity for inviting user' do - expect(Activities::CreateActivityService) - .to(receive(:call) - .with(hash_including(activity_type: :remove_user_from_team))) - - action - end - - it 'adds activity in DB' do - expect { action } - .to(change { Activity.count }) - end - - it 'remove user_team record from DB' do - expect { action } - .to(change { UserTeam.count }) - end - end - - context 'when user leaving team by himself' do - it 'calls create activity for user leaving' do - params_leave = { id: another_user_team.id, leave: true } - expect(Activities::CreateActivityService) - .to(receive(:call) - .with(hash_including(activity_type: :user_leave_team))) - - delete :destroy, params: params_leave, format: :json - end - - it 'adds activity in DB' do - params_leave = { id: another_user_team.id, leave: true } - expect { delete :destroy, params: params_leave, format: :json } - .to(change { Activity.count }) - end - end - end - - describe 'PUT update' do - let(:params) do - { - id: another_user_team.id, - user_team: { - role: 'admin' - } - } - end - let(:action) { put :update, params: params, format: :json } - - context 'when updating user role in the team' do - it 'calls create activity for updating role' do - expect(Activities::CreateActivityService) - .to(receive(:call) - .with(hash_including(activity_type: - :change_users_role_on_team))) - - action - end - - it 'adds activity in DB' do - expect { action } - .to(change { Activity.count }) - end - end - end -end diff --git a/spec/factories/user_teams.rb b/spec/factories/user_teams.rb deleted file mode 100644 index bb5b9c3b6..000000000 --- a/spec/factories/user_teams.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :user_team do - user - team - trait :admin do - role { 'admin' } - end - trait :guest do - role { 'guest' } - end - trait :normal_user do # default enum by DB - role { 'normal_user' } - end - end -end diff --git a/spec/jobs/user_assignments/generate_user_assignments_job.rb b/spec/jobs/user_assignments/generate_user_assignments_job.rb index c70c233c7..8a07f1b91 100644 --- a/spec/jobs/user_assignments/generate_user_assignments_job.rb +++ b/spec/jobs/user_assignments/generate_user_assignments_job.rb @@ -14,10 +14,8 @@ module UserAssignments before(:each) do available_roles = [owner_role, viewer_role, technician_role] - create :user_team, :admin, user: user_two, team: team create :user_assignment, user: user_two, assignable: project, user_role: viewer_role, assigned_by: user_one - create :user_team, :admin, user: user_three, team: team create :user_assignment, user: user_three, assignable: project, user_role: technician_role, assigned_by: user_one end diff --git a/spec/jobs/user_assignments/propagate_assignment_job_spec.rb b/spec/jobs/user_assignments/propagate_assignment_job_spec.rb index 5d260313d..5b654f2ed 100644 --- a/spec/jobs/user_assignments/propagate_assignment_job_spec.rb +++ b/spec/jobs/user_assignments/propagate_assignment_job_spec.rb @@ -16,13 +16,6 @@ module UserAssignments let!(:my_module_one) { create :my_module, experiment: experiment_one, created_by: experiment_one.created_by } let!(:my_module_two) { create :my_module, experiment: experiment_two, created_by: experiment_two.created_by } - - before do - [user_one, user_two].each do |user| - create :user_team, :admin, user: user, team: team - end - end - describe 'perform' do it 'propagates the user assignments to project child object' do expect { diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index 829edd752..3184b9f81 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -26,7 +26,6 @@ describe Team, type: :model do describe 'Relations' do it { should belong_to(:created_by).class_name('User').optional } it { should belong_to(:last_modified_by).class_name('User').optional } - it { should have_many :user_teams } it { should have_many :users } it { should have_many :projects } it { should have_many :protocols } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 18fc48490..461e24c60 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -46,7 +46,6 @@ describe User, type: :model do end describe 'Relations' do - it { should have_many :user_teams } it { should have_many :teams } it { should have_many :user_projects } it { should have_many :projects } @@ -85,7 +84,6 @@ describe User, type: :model do it { should have_many :tokens } it { should have_many :modified_tags } it { should have_many :assigned_user_my_modules } - it { should have_many :assigned_user_teams } it { should have_many :assigned_user_projects } it { should have_many :added_protocols } it { should have_many :archived_protocols } @@ -149,21 +147,6 @@ describe User, type: :model do end end - describe 'teams_data should return a list of teams' do - # needs persistence because is testing a sql query - let(:team) { create :team } - let(:user_one) do - create :user, email: 'user1@asdf.com', current_team_id: team.id - end - let(:user_two) { create :user, email: 'user2@asdf.com' } - - it 'should return correct number of team members' do - create :user_team, team: team, user: user_one - create :user_team, team: team, user: user_two - expect(user_one.datatables_teams.first.members).to eq 2 - end - end - describe 'user settings' do it { is_expected.to respond_to(:time_zone) } it { is_expected.to respond_to(:assignments_notification) } diff --git a/spec/models/user_team_spec.rb b/spec/models/user_team_spec.rb deleted file mode 100644 index 18fa61ead..000000000 --- a/spec/models/user_team_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe UserTeam, type: :model do - let(:user_team) { build :user_team } - - it 'is valid' do - expect(user_team).to be_valid - end - - it 'should be of class UserTeam' do - expect(subject.class).to eq UserTeam - end - - describe 'Database table' do - it { should have_db_column :role } - it { should have_db_column :user_id } - it { should have_db_column :team_id } - it { should have_db_column :created_at } - it { should have_db_column :updated_at } - it { should have_db_column :assigned_by_id } - end - - describe 'Relations' do - it { should belong_to :user } - it { should belong_to :team } - it { should belong_to(:assigned_by).class_name('User').optional } - end - - describe 'Validations' do - it { should validate_presence_of :role } - it { should validate_presence_of :user } - it { should validate_presence_of :team } - end -end diff --git a/spec/models/views/datatables/teams_spec.rb b/spec/models/views/datatables/teams_spec.rb index 0e6fabdde..e51fc2610 100644 --- a/spec/models/views/datatables/teams_spec.rb +++ b/spec/models/views/datatables/teams_spec.rb @@ -8,7 +8,6 @@ RSpec.describe Views::Datatables::DatatablesTeam, type: :model do it { should have_db_column :name } it { should have_db_column :members } it { should have_db_column :role } - it { should have_db_column :user_team_id } it { should have_db_column :user_id } it { should have_db_column :can_be_left } end diff --git a/spec/requests/api/service/projects_json_export_controller_spec.rb b/spec/requests/api/service/projects_json_export_controller_spec.rb index 61a69e042..24ee86ca0 100644 --- a/spec/requests/api/service/projects_json_export_controller_spec.rb +++ b/spec/requests/api/service/projects_json_export_controller_spec.rb @@ -6,7 +6,6 @@ RSpec.describe "Api::Service::ProjectsJsonExportController", type: :request do before :all do @user = create(:user) @team = create(:team, created_by: @user) - create(:user_team, user: @user, team: @team, role: 1) @accessible_project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team) @accessible_experiment = create(:experiment, created_by: @user, diff --git a/spec/requests/api/service/protocols_controller_spec.rb b/spec/requests/api/service/protocols_controller_spec.rb index a9bd8cd37..27d93dbcf 100644 --- a/spec/requests/api/service/protocols_controller_spec.rb +++ b/spec/requests/api/service/protocols_controller_spec.rb @@ -6,7 +6,6 @@ RSpec.describe "Api::Service::ProtocolsController", type: :request do before :all do @user = create(:user) @team = create(:team, created_by: @user) - create(:user_team, user: @user, team: @team, role: 2) @project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team) @experiment = create(:experiment, created_by: @user, last_modified_by: @user, project: @project, created_by: @user) diff --git a/spec/requests/api/service/steps_controller_spec.rb b/spec/requests/api/service/steps_controller_spec.rb index 112866962..d1cc5332e 100644 --- a/spec/requests/api/service/steps_controller_spec.rb +++ b/spec/requests/api/service/steps_controller_spec.rb @@ -6,7 +6,6 @@ RSpec.describe "Api::Service::StepsController", type: :request do before :all do @user = create(:user) @team = create(:team, created_by: @user) - create(:user_team, user: @user, team: @team, role: 2) @project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team) @experiment = create(:experiment, created_by: @user, last_modified_by: @user, project: @project, created_by: @user) diff --git a/spec/requests/api/v1/step_texts_controller_spec.rb b/spec/requests/api/v1/step_texts_controller_spec.rb index c43989c1c..d37d7480f 100644 --- a/spec/requests/api/v1/step_texts_controller_spec.rb +++ b/spec/requests/api/v1/step_texts_controller_spec.rb @@ -11,7 +11,6 @@ RSpec.describe 'Api::V1::StepTextsController', type: :request do @task = @experiment.my_modules.first @protocol = create(:protocol, my_module: @task) @step = create(:step, protocol: @protocol) - create(:user_team, user: @user, team: @team) @valid_headers = { 'Authorization': 'Bearer ' + generate_token(@user.id), diff --git a/spec/requests/api/v1/task_assignments_controller_spec.rb b/spec/requests/api/v1/task_assignments_controller_spec.rb index 65f46f32b..6c34cbb7e 100644 --- a/spec/requests/api/v1/task_assignments_controller_spec.rb +++ b/spec/requests/api/v1/task_assignments_controller_spec.rb @@ -7,7 +7,6 @@ RSpec.describe 'Api::V1::TaskAssignmentsController', type: :request do @user = create(:user) @user_second = create(:user) @team = create(:team, created_by: @user) - create(:user_team, user: @user, team: @team, role: 1) @owner_role = UserRole.find_by(name: I18n.t('user_roles.predefined.owner')) @project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team) diff --git a/spec/services/project_json_export_service_spec.rb b/spec/services/project_json_export_service_spec.rb index f1cf88998..91f035cf3 100644 --- a/spec/services/project_json_export_service_spec.rb +++ b/spec/services/project_json_export_service_spec.rb @@ -4,7 +4,6 @@ describe ProjectsJsonExportService do before :all do @user = create(:user) @team = create(:team, created_by: @user) - create(:user_team, user: @user, team: @team, role: 1) @accessible_project_1 = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team) @accessible_project_2 = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)