mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 01:35:34 +08:00
Add new context helper to controllers tests [SCI-6072] (#3546)
This commit is contained in:
parent
066239db51
commit
2240dc5984
13 changed files with 62 additions and 212 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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 }
|
||||
include_context 'reference_project_structure', {
|
||||
result_text: true
|
||||
}
|
||||
|
||||
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
|
||||
describe 'DELETE destroy' do
|
||||
|
||||
let(:action) { delete :destroy, params: params }
|
||||
let(:params) do
|
||||
{ id: result_text.result.id }
|
||||
end
|
||||
|
||||
before do
|
||||
create_user_assignment(task, owner_role, user)
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
let(:action) { delete :destroy, params: params }
|
||||
let(:params) do
|
||||
{ id: result.id }
|
||||
result_text.result.archive!(user)
|
||||
end
|
||||
|
||||
it 'calls create activity service' do
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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 } }
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue