diff --git a/spec/controllers/project_folders_controller_spec.rb b/spec/controllers/project_folders_controller_spec.rb index fd636ad28..9ae3d43de 100644 --- a/spec/controllers/project_folders_controller_spec.rb +++ b/spec/controllers/project_folders_controller_spec.rb @@ -6,11 +6,10 @@ describe ProjectFoldersController, type: :controller do login_user # render_views - let(:user) { subject.current_user } - let(:team) { create :team, created_by: user } - let!(:user_team) { create :user_team, team: team, user: user, role: :admin } + include_context 'reference_project_structure' + let(:project_folder) { create :project_folder, team: team } - let(:owner_role) { create :owner_role } + describe 'POST #move_to' do let!(:project_folder_1) do @@ -34,7 +33,7 @@ describe ProjectFoldersController, type: :controller do before do 3.times do |i| - create_user_assignment(public_send("project_#{i+1}"), owner_role, user) + create_user_assignment(public_send("project_#{i+1}"), role, user) end end diff --git a/spec/controllers/protocols_controller_spec.rb b/spec/controllers/protocols_controller_spec.rb index eb348a007..f29dfeed2 100644 --- a/spec/controllers/protocols_controller_spec.rb +++ b/spec/controllers/protocols_controller_spec.rb @@ -5,17 +5,7 @@ require 'rails_helper' describe ProtocolsController, 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(:project) { create :project, team: team, created_by: user } - let (:owner_role) { create :owner_role } - let(:experiment) { create :experiment, project: project } - let(:my_module) { create :my_module, experiment: experiment } - - before do - create_user_assignment(my_module, owner_role, user) - end + include_context 'reference_project_structure' describe 'POST create' do let(:action) { post :create, params: params, format: :json } diff --git a/spec/controllers/reports_controller_spec.rb b/spec/controllers/reports_controller_spec.rb index 61c52d118..61addb422 100644 --- a/spec/controllers/reports_controller_spec.rb +++ b/spec/controllers/reports_controller_spec.rb @@ -5,21 +5,8 @@ require 'rails_helper' describe ReportsController, type: :controller do login_user - let(:user) { subject.current_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(:project) { create :project, team: team, user_projects: [user_project] } - let(:owner_user_role) { create :owner_role } - let!(:user_assignment) do - create :user_assignment, - assignable: project, - user: user, - user_role: owner_user_role, - assigned_by: user - end - let(:experiment) { create :experiment, project: project } - let(:my_module1) { create :my_module, experiment: experiment } + include_context 'reference_project_structure' + let(:my_module2) { create :my_module, experiment: experiment } let(:report) do create :report, user: user, project: project, team: team, @@ -34,7 +21,7 @@ describe ReportsController, type: :controller do report: { name: 'test report created', description: 'test description created', settings: Report::DEFAULT_SETTINGS }, - project_content: { experiments: [{ id: experiment.id, my_module_ids: [my_module1.id] }] }, + project_content: { experiments: [{ id: experiment.id, my_module_ids: [my_module.id] }] }, template_values: [] } end diff --git a/spec/controllers/result_assets_controller_spec.rb b/spec/controllers/result_assets_controller_spec.rb index 00a41f286..92351e581 100644 --- a/spec/controllers/result_assets_controller_spec.rb +++ b/spec/controllers/result_assets_controller_spec.rb @@ -5,27 +5,14 @@ require 'rails_helper' describe ResultAssetsController, type: :controller do login_user - let(:user) { subject.current_user } - let!(:team) { create :team, :with_members } - let(:project) do - create :project, team: team - end - let(:owner_role) { create :owner_role } - let(:experiment) { create :experiment, project: project } - let(:task) { create :my_module, name: 'test task', experiment: experiment } - let(:result) do - create :result, name: 'test result', my_module: task, user: user - end - let(:result_asset) { create :result_asset, result: result } - - before do - create_user_assignment(task, owner_role, user) - end + include_context 'reference_project_structure', { + result_asset: true + } describe 'POST create' do let(:action) { post :create, params: params, format: :json } let(:params) do - { my_module_id: task.id, + { my_module_id: my_module.id, results_names: { '0': 'result name created' }, results_files: { '0': file_fixture('files/export.csv', 'text/csv') } } @@ -47,7 +34,7 @@ describe ResultAssetsController, type: :controller do let(:action) { put :update, params: params, format: :json } let(:params) do { id: result_asset.id, - result: { name: result.name } } + result: { name: result_asset.result.name } } end it 'calls create activity service (edit_result)' do params[:result][:name] = 'test result changed' diff --git a/spec/controllers/result_comments_controller_spec.rb b/spec/controllers/result_comments_controller_spec.rb index 3717532a1..c33e288ce 100644 --- a/spec/controllers/result_comments_controller_spec.rb +++ b/spec/controllers/result_comments_controller_spec.rb @@ -5,36 +5,16 @@ require 'rails_helper' describe ResultCommentsController, type: :controller do login_user - let(:user) { subject.current_user } - let!(:team) { create :team, created_by: user, users: [user] } - let(:project) do - create :project, team: team - end - let(:owner_role) { create :owner_role } - - let(:experiment) { create :experiment, project: project } - let(:task) { create :my_module, name: 'test task', experiment: experiment } - let(:result) do - create :result, name: 'test result', my_module: task, user: user - end - let!(:result_text) do - create :result_text, text: 'test text result', result: result - end - let(:result_comment) do - create :result_comment, message: 'test comment result', - result: result, - user: user - end - - before do - create_user_assignment(task, owner_role, user) - end + include_context 'reference_project_structure', { + result_text: true, + result_comment: true + } describe 'POST create' do context 'in JSON format' do let(:action) { post :create, params: params, format: :json } let(:params) do - { result_id: result.id, + { result_id: result_text.result.id, comment: { message: 'test comment' } } end @@ -55,8 +35,8 @@ describe ResultCommentsController, type: :controller do context 'in JSON format' do let(:action) { put :update, params: params, format: :json } let(:params) do - { result_id: result.id, - id: result_comment.id, + { result_id: result_text.result.id, + id: result_text_comment.id, comment: { message: 'test comment updated' } } end @@ -76,8 +56,8 @@ describe ResultCommentsController, type: :controller do describe 'DELETE destroy' do let(:action) { delete :destroy, params: params, format: :json } let(:params) do - { result_id: result.id, - id: result_comment.id } + { result_id: result_text.result.id, + id: result_text_comment.id } end it 'calls create activity service' do diff --git a/spec/controllers/result_tables_controller_spec.rb b/spec/controllers/result_tables_controller_spec.rb index b1985e220..abfe161d5 100644 --- a/spec/controllers/result_tables_controller_spec.rb +++ b/spec/controllers/result_tables_controller_spec.rb @@ -5,28 +5,14 @@ require 'rails_helper' describe ResultTablesController, type: :controller do login_user - let(:user) { subject.current_user } - let!(:team) { create :team, created_by: user, users: [user] } - let(:project) do - create :project, team: team - end - let(:owner_role) { create :owner_role } - - let(:experiment) { create :experiment, project: project } - let(:task) { create :my_module, name: 'test task', experiment: experiment } - let(:result) do - create :result, name: 'test result', my_module: task, user: user - end - let(:result_table) { create :result_table, result: result } - - before do - create_user_assignment(task, owner_role, user) - end + include_context 'reference_project_structure', { + result_table: true + } describe 'POST create' do let(:action) { post :create, params: params, format: :json } let(:params) do - { my_module_id: task.id, + { my_module_id: my_module.id, result: { name: 'result name created', table_attributes: @@ -49,7 +35,7 @@ describe ResultTablesController, type: :controller do let(:action) { put :update, params: params, format: :json } let(:params) do { id: result_table.id, - result: { name: result.name } } + result: { name: result_table.result.name } } end it 'calls create activity service (edit_result)' do params[:result][:name] = 'test result changed' diff --git a/spec/controllers/result_texts_controller_spec.rb b/spec/controllers/result_texts_controller_spec.rb index 286486300..eb50f5166 100644 --- a/spec/controllers/result_texts_controller_spec.rb +++ b/spec/controllers/result_texts_controller_spec.rb @@ -5,29 +5,14 @@ require 'rails_helper' describe ResultTextsController, type: :controller do login_user - let(:user) { subject.current_user } - let!(:team) { create :team, :with_members } - let(:project) do - create :project, team: team - end - let(:owner_role) { create :owner_role } - let(:experiment) { create :experiment, project: project } - let(:task) { create :my_module, name: 'test task', experiment: experiment } - let(:result) do - create :result, name: 'test result', my_module: task, user: user - end - let(:result_text) do - create :result_text, text: 'test text result', result: result - end - - before do - create_user_assignment(task, owner_role, user) - end + include_context 'reference_project_structure', { + result_text: true + } describe 'POST create' do let(:action) { post :create, params: params, format: :json } let(:params) do - { my_module_id: task.id, + { my_module_id: my_module.id, result: { name: 'result name created', result_text_attributes: { text: 'result text created' } } } end @@ -48,7 +33,7 @@ describe ResultTextsController, type: :controller do let(:action) { put :update, params: params, format: :json } let(:params) do { id: result_text.id, - result: { name: result.name } } + result: { name: result_text.result.name } } end it 'calls create activity service (edit_result)' do params[:result][:name] = 'test result changed' diff --git a/spec/controllers/results_controller_spec.rb b/spec/controllers/results_controller_spec.rb index 8569f8f9e..6b7e4d03b 100644 --- a/spec/controllers/results_controller_spec.rb +++ b/spec/controllers/results_controller_spec.rb @@ -5,30 +5,19 @@ require 'rails_helper' describe ResultsController, type: :controller do login_user - let(:user) { subject.current_user } - let!(:team) { create :team, :with_members } - let(:project) do - create :project, team: team - end - let(:owner_role) { create :owner_role } - - let(:experiment) { create :experiment, project: project } - let(:task) { create :my_module, name: 'test task', experiment: experiment } - let(:result) do - create :result, :archived, name: 'test result', my_module: task, user: user - end - let!(:result_text) do - create :result_text, text: 'test text result', result: result - end - - before do - create_user_assignment(task, owner_role, user) - end + include_context 'reference_project_structure', { + result_text: true + } describe 'DELETE destroy' do + let(:action) { delete :destroy, params: params } let(:params) do - { id: result.id } + { id: result_text.result.id } + end + + before do + result_text.result.archive!(user) end it 'calls create activity service' do diff --git a/spec/controllers/step_comments_controller_spec.rb b/spec/controllers/step_comments_controller_spec.rb index 1b68ad372..d84af5962 100644 --- a/spec/controllers/step_comments_controller_spec.rb +++ b/spec/controllers/step_comments_controller_spec.rb @@ -5,23 +5,10 @@ require 'rails_helper' describe StepCommentsController, 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(:project) { create :project, team: team, created_by: user } - let(:normal_user_role) { create :normal_user_role } - - let(:experiment) { create :experiment, project: project } - let(:my_module) { create :my_module, experiment: experiment } - let(:protocol) do - create :protocol, my_module: my_module, team: team, added_by: user - end - let(:step) { create :step, protocol: protocol, user: user } - let(:step_comment) { create :step_comment, user: user, step: step } - - before do - create_user_assignment(my_module, normal_user_role, user) - end + include_context 'reference_project_structure', { + step: true, + step_comment: true + } describe 'POST create' do let(:action) { post :create, params: params, format: :json } diff --git a/spec/controllers/steps_controller_spec.rb b/spec/controllers/steps_controller_spec.rb index 60bd84f4f..be5166ffe 100644 --- a/spec/controllers/steps_controller_spec.rb +++ b/spec/controllers/steps_controller_spec.rb @@ -5,26 +5,15 @@ require 'rails_helper' describe StepsController, 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(:project) { create :project, team: team, created_by: user } - let(:owner_role) { create :owner_role } - let(:experiment) { create :experiment, project: project } - let(:my_module) { create :my_module, experiment: experiment } - let(:protocol) do - create :protocol, my_module: my_module, team: team, added_by: user - end - let(:step) { create :step, protocol: protocol, user: user } + include_context 'reference_project_structure', { + step: true + } + let(:protocol_repo) do create :protocol, :in_public_repository, team: team, added_by: user end let(:step_repo) { create :step, protocol: protocol_repo } - before do - create_user_assignment(my_module, owner_role, user) - end - describe 'POST create' do let(:action) { post :create, params: params, format: :json } @@ -50,7 +39,7 @@ describe StepsController, type: :controller do context 'when in protocol on task' do let(:params) do - { protocol_id: protocol.id, + { protocol_id: my_module.protocol.id, step: { name: 'test', description: 'description' } } end @@ -208,7 +197,7 @@ describe StepsController, type: :controller do context 'when completing step' do let(:step) do - create :step, protocol: protocol, user: user, completed: false + create :step, protocol: my_module.protocol, user: user, completed: false end let(:params) { { id: step.id, completed: true } } diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 994939691..f9995f121 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -5,18 +5,9 @@ require 'rails_helper' describe TagsController, 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(:project) { create :project, team: team, created_by: user } - let(:owner_role) { create :owner_role } - let(:experiment) { create :experiment, project: project } - let(:my_module) { create :my_module, experiment: experiment } - let(:tag) { create :tag, project: project } - - before do - create_user_assignment(my_module, owner_role, user) - end + include_context 'reference_project_structure', { + tag: true + } describe 'POST create' do let(:action) { post :create, params: params, format: :json } diff --git a/spec/controllers/user_my_modules_controller_spec.rb b/spec/controllers/user_my_modules_controller_spec.rb index e676be474..e9de553dc 100644 --- a/spec/controllers/user_my_modules_controller_spec.rb +++ b/spec/controllers/user_my_modules_controller_spec.rb @@ -5,17 +5,7 @@ require 'rails_helper' describe UserMyModulesController, 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(:project) { create :project, team: team, created_by: user } - let(:owner_role) { create :owner_role } - let(:experiment) { create :experiment, project: project } - let(:my_module) { create :my_module, experiment: experiment } - - before do - create_user_assignment(my_module, owner_role, user) - end + include_context 'reference_project_structure' describe 'POST create' do let(:action) { post :create, params: params, format: :json } diff --git a/spec/controllers/wopi_controller_spec.rb b/spec/controllers/wopi_controller_spec.rb index 70f9948d9..99945116d 100644 --- a/spec/controllers/wopi_controller_spec.rb +++ b/spec/controllers/wopi_controller_spec.rb @@ -6,22 +6,16 @@ describe WopiController, type: :controller do ENV['WOPI_USER_HOST'] = 'localhost' 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(:project) do - create :project, team: team - end - let(:owner_role) { create :owner_role } - let(:experiment) { create :experiment, project: project } - let(:my_module) { create :my_module, name: 'test task', experiment: experiment } + + include_context 'reference_project_structure', { + step: true + } + + let(:result) do create :result, name: 'test result', my_module: my_module, user: user end - let(:protocol) do - create :protocol, my_module: my_module, team: team, added_by: user - end - let(:step) { create :step, protocol: protocol, user: user } + let(:protocol_in_repository) { create :protocol, :in_public_repository, team: team } let(:step_in_repository) { create :step, protocol: protocol_in_repository, user: user } @@ -32,10 +26,6 @@ describe WopiController, type: :controller do let(:result_asset) { create :result_asset, result: result, asset: asset } let(:token) { Token.create(token: 'token', ttl: 0, user_id: user.id) } - before do - create_user_assignment(my_module, owner_role, user) - end - describe 'POST unlock' do before do token