From ffaf141abf3adb797234888c41ba806069be4676 Mon Sep 17 00:00:00 2001 From: zmagoD Date: Sat, 29 May 2021 18:40:26 +0200 Subject: [PATCH] fix failing scenarios --- config/routes.rb | 2 +- .../controllers/my_module_tags_controller_spec.rb | 9 +++++++-- spec/controllers/my_modules_controller_spec.rb | 15 ++++++++++----- spec/controllers/protocols_controller_spec.rb | 9 +++++++-- spec/controllers/steps_controller_spec.rb | 3 +-- spec/controllers/tags_controller_spec.rb | 3 +-- spec/factories/user_projects.rb | 12 ------------ spec/permissions/result_permission_spec.rb | 3 +-- spec/requests/api/v1/assets_controller_spec.rb | 4 ++-- .../api/v1/checklist_items_controller_spec.rb | 4 ++-- .../requests/api/v1/checklists_controller_spec.rb | 4 ++-- spec/requests/api/v1/steps_controller_spec.rb | 2 +- spec/requests/api/v1/tables_controller_spec.rb | 4 ++-- spec/requests/api/v1/tasks_controller_spec.rb | 11 ++++++----- .../smart_annotations/tag_to_text_spec.rb | 10 +++++++++- 15 files changed, 52 insertions(+), 43 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index a98733b4c..a78b4b7a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -660,7 +660,7 @@ Rails.application.routes.draw do namespace :api, defaults: { format: 'json' } do get 'health', to: 'api#health' get 'status', to: 'api#status' - if true #Rails.configuration.x.core_api_v1_enabled + if Rails.configuration.x.core_api_v1_enabled namespace :v1 do resources :teams, only: %i(index show) do resources :inventories, only: %i(index create show update destroy) do diff --git a/spec/controllers/my_module_tags_controller_spec.rb b/spec/controllers/my_module_tags_controller_spec.rb index 938c88573..c9a41d5ec 100644 --- a/spec/controllers/my_module_tags_controller_spec.rb +++ b/spec/controllers/my_module_tags_controller_spec.rb @@ -12,8 +12,13 @@ describe MyModuleTagsController, type: :controller do let!(:user_project) do create :user_project, user: user, project: project end - let(:normal_user_role) { create :normal_user_role } - let!(:user_assignment) { create :user_assignment, assignable: project, user: user, user_role: normal_user_role, assigned_by: user } + let!(:user_assignment) do + create :user_assignment, + assignable: project, + user: user, + user_role: create(:owner_role), + assigned_by: user + end let(:experiment) { create :experiment, project: project } let(:my_module) { create :my_module, experiment: experiment } diff --git a/spec/controllers/my_modules_controller_spec.rb b/spec/controllers/my_modules_controller_spec.rb index 60b069eb3..e991f0e7d 100644 --- a/spec/controllers/my_modules_controller_spec.rb +++ b/spec/controllers/my_modules_controller_spec.rb @@ -9,11 +9,15 @@ describe MyModulesController, type: :controller do let(:team) { create :team, created_by: user } let!(:user_team) { create :user_team, :admin, user: user, team: team } let(:project) { create :project, team: team, created_by: user } - let!(:user_project) do - create :user_project, user: user, project: project + let!(:user_project) { create :user_project, user: user, project: project } + let(:owner_role) { create :owner_role } + let!(:user_assignment) do + create :user_assignment, + assignable: project, + user: user, + user_role: owner_role, + assigned_by: user end - let(:normal_user_role) { create :normal_user_role } - let!(:user_assignment) { create :user_assignment, assignable: project, user: user, user_role: normal_user_role, assigned_by: user } let!(:repository) { create :repository, created_by: user, team: team } let!(:repository_row) do create :repository_row, created_by: user, repository: repository @@ -159,6 +163,7 @@ describe MyModulesController, type: :controller do it 'renders 403' do # Remove user from project UserProject.where(user: user, project: project).destroy_all + UserAssignment.where(user: user, assignable: project).destroy_all action expect(response).to have_http_status 403 @@ -194,7 +199,7 @@ describe MyModulesController, type: :controller do create :user_assignment, assignable: experiment.project, user: user, - user_role: create(:owner_role), + user_role: owner_role, assigned_by: user end diff --git a/spec/controllers/protocols_controller_spec.rb b/spec/controllers/protocols_controller_spec.rb index 55ad50108..5e314c6c6 100644 --- a/spec/controllers/protocols_controller_spec.rb +++ b/spec/controllers/protocols_controller_spec.rb @@ -9,8 +9,13 @@ describe ProtocolsController, type: :controller do let(:team) { create :team, created_by: user } let!(:user_team) { create :user_team, :admin, user: user, team: team } let(:project) { create :project, team: team, created_by: user } - let!(:user_project) do - create :user_project, user: user, project: project + let!(:user_project) { create :user_project, user: user, project: project } + let!(:user_assignment) do + create :user_assignment, + assignable: project, + user: user, + user_role: create(:owner_role), + assigned_by: user end let(:experiment) { create :experiment, project: project } let(:my_module) { create :my_module, experiment: experiment } diff --git a/spec/controllers/steps_controller_spec.rb b/spec/controllers/steps_controller_spec.rb index d7fa721d0..52e9448f5 100644 --- a/spec/controllers/steps_controller_spec.rb +++ b/spec/controllers/steps_controller_spec.rb @@ -12,12 +12,11 @@ describe StepsController, type: :controller do let!(:user_project) do create :user_project, user: user, project: project end - let(:normal_user_role) { create :normal_user_role } let!(:user_assignment) do create :user_assignment, assignable: project, user: user, - user_role: normal_user_role, + user_role: create(:owner_role), assigned_by: user end let(:experiment) { create :experiment, project: project } diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 3b4fe4491..b045df194 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -12,12 +12,11 @@ describe TagsController, type: :controller do let!(:user_project) do create :user_project, user: user, project: project end - let(:normal_user_role) { create :normal_user_role } let!(:user_assignment) do create :user_assignment, assignable: project, user: user, - user_role: normal_user_role, + user_role: create(:owner_role), assigned_by: user end let(:experiment) { create :experiment, project: project } diff --git a/spec/factories/user_projects.rb b/spec/factories/user_projects.rb index 6ab1aa8e2..494a85f29 100644 --- a/spec/factories/user_projects.rb +++ b/spec/factories/user_projects.rb @@ -5,17 +5,5 @@ FactoryBot.define do user project assigned_by { user } - trait :owner do - role { UserProject.roles[:owner] } - end - trait :normal_user do - role { UserProject.roles[:normal_user] } - end - trait :technician do - role { UserProject.roles[:technician] } - end - trait :viewer do - role { UserProject.roles[:viewer] } - end end end diff --git a/spec/permissions/result_permission_spec.rb b/spec/permissions/result_permission_spec.rb index f6a6e6ec0..3ffcf69d4 100644 --- a/spec/permissions/result_permission_spec.rb +++ b/spec/permissions/result_permission_spec.rb @@ -10,14 +10,13 @@ describe 'ResultPermissions' do let(:result) { create :result, user: user, my_module: my_module } let(:my_module) { create :my_module, experiment: experiment } let(:experiment) { create :experiment, user: user } - let(:normal_user_role) { create :normal_user_role } before do create :user_project, user: user, project: experiment.project create :user_assignment, assignable: experiment.project, user: user, - user_role: normal_user_role, + user_role: create(:owner_role), assigned_by: user end diff --git a/spec/requests/api/v1/assets_controller_spec.rb b/spec/requests/api/v1/assets_controller_spec.rb index b99115901..f0888a696 100644 --- a/spec/requests/api/v1/assets_controller_spec.rb +++ b/spec/requests/api/v1/assets_controller_spec.rb @@ -13,11 +13,11 @@ RSpec.describe 'Api::V1::AssetsController', type: :request do @step = create(:step, protocol: @protocol) create(:user_team, user: @user, team: @team) - create(:user_project, :normal_user, user: @user, project: @project) + create(:user_project, user: @user, project: @project) create :user_assignment, assignable: @project, user: @user, - user_role: create(:normal_user_role), + user_role: create(:owner_role), assigned_by: @user @valid_headers = diff --git a/spec/requests/api/v1/checklist_items_controller_spec.rb b/spec/requests/api/v1/checklist_items_controller_spec.rb index 5b6478b9e..91c5ca18a 100644 --- a/spec/requests/api/v1/checklist_items_controller_spec.rb +++ b/spec/requests/api/v1/checklist_items_controller_spec.rb @@ -13,11 +13,11 @@ RSpec.describe 'Api::V1::ChecklistsController', type: :request do @step = create(:step, protocol: @protocol) @checklist = create(:checklist, step: @step) create(:user_team, user: @user, team: @team) - create(:user_project, :normal_user, user: @user, project: @project) + create(:user_project, user: @user, project: @project) create :user_assignment, assignable: @project, user: @user, - user_role: create(:normal_user_role), + user_role: create(:owner_role), assigned_by: @user @valid_headers = { diff --git a/spec/requests/api/v1/checklists_controller_spec.rb b/spec/requests/api/v1/checklists_controller_spec.rb index 1892d05cd..6021d4b00 100644 --- a/spec/requests/api/v1/checklists_controller_spec.rb +++ b/spec/requests/api/v1/checklists_controller_spec.rb @@ -12,11 +12,11 @@ RSpec.describe 'Api::V1::ChecklistsController', type: :request do @protocol = create(:protocol, my_module: @task) @step = create(:step, protocol: @protocol) create(:user_team, user: @user, team: @team) - create(:user_project, :normal_user, user: @user, project: @project) + create(:user_project, user: @user, project: @project) create :user_assignment, assignable: @project, user: @user, - user_role: create(:normal_user_role), + user_role: create(:owner_role), assigned_by: @user @valid_headers = { diff --git a/spec/requests/api/v1/steps_controller_spec.rb b/spec/requests/api/v1/steps_controller_spec.rb index 5868c330d..b5caca070 100644 --- a/spec/requests/api/v1/steps_controller_spec.rb +++ b/spec/requests/api/v1/steps_controller_spec.rb @@ -14,7 +14,7 @@ RSpec.describe 'Api::V1::StepsController', type: :request do create :user_assignment, assignable: @project, user: @user, - user_role: create(:normal_user_role), + user_role: create(:owner_role), assigned_by: @user @valid_headers = diff --git a/spec/requests/api/v1/tables_controller_spec.rb b/spec/requests/api/v1/tables_controller_spec.rb index de7c1a887..5eb70dfa9 100644 --- a/spec/requests/api/v1/tables_controller_spec.rb +++ b/spec/requests/api/v1/tables_controller_spec.rb @@ -12,11 +12,11 @@ RSpec.describe 'Api::V1::TablesController', type: :request do @protocol = create(:protocol, my_module: @task) @step = create(:step, protocol: @protocol) create(:user_team, user: @user, team: @team) - create(:user_project, :normal_user, user: @user, project: @project) + create(:user_project, user: @user, project: @project) create :user_assignment, assignable: @project, user: @user, - user_role: create(:normal_user_role), + user_role: create(:owner_role), assigned_by: @user @valid_headers = { diff --git a/spec/requests/api/v1/tasks_controller_spec.rb b/spec/requests/api/v1/tasks_controller_spec.rb index 04a07fb6c..bdb6c0708 100644 --- a/spec/requests/api/v1/tasks_controller_spec.rb +++ b/spec/requests/api/v1/tasks_controller_spec.rb @@ -9,7 +9,7 @@ RSpec.describe 'Api::V1::TasksController', type: :request do @user = create(:user) @teams = create_list(:team, 2, created_by: @user) create(:user_team, user: @user, team: @teams.first, role: 2) - + @owner_role = create(:owner_role) @valid_project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @teams.first) @@ -144,11 +144,11 @@ RSpec.describe 'Api::V1::TasksController', type: :request do describe 'POST tasks, #create' do before :all do - create :user_project, :normal_user, user: @user, project: @valid_project + create :user_project, user: @user, project: @valid_project create :user_assignment, assignable: @valid_project, user: @user, - user_role: create(:normal_user_role), + user_role: @owner_role, assigned_by: @user @valid_headers['Content-Type'] = 'application/json' end @@ -228,8 +228,9 @@ RSpec.describe 'Api::V1::TasksController', type: :request do end it 'renders 403 for use with view permissions' do - up = UserProject.where(user: @user, project: @valid_project).first - up.update_attribute(:role, :viewer) + user_assignment = UserAssignment.where(user: @user, assignable: @valid_project) + .first + user_assignment.update!(user_role: create(:viewer_role)) post(api_v1_team_project_experiment_tasks_path( team_id: @teams.first.id, diff --git a/spec/services/smart_annotations/tag_to_text_spec.rb b/spec/services/smart_annotations/tag_to_text_spec.rb index 58c40e08e..63e5aa6a6 100644 --- a/spec/services/smart_annotations/tag_to_text_spec.rb +++ b/spec/services/smart_annotations/tag_to_text_spec.rb @@ -8,8 +8,16 @@ describe SmartAnnotations::TagToText do let!(:user_team) { create :user_team, user: user, team: team, role: 2 } let!(:project) { create :project, name: 'my project', team: team } let!(:user_project) do - create :user_project, project: project, user: user, role: 0 + create :user_project, project: project, user: user end + let!(:user_assignment) do + create :user_assignment, + assignable: project, + user: user, + user_role: create(:owner_role), + assigned_by: user + end + let(:text) do "My annotation of [#my project~prj~#{project.id.base62_encode}]" end