mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 06:35:56 +08:00
Fix broken unit tests [SCI-8972] (#6342)
- Models tests - Controllers tests - Jobs tests - Permissions tests - Utilities tests
This commit is contained in:
parent
04a898760a
commit
857bda6f69
|
@ -350,7 +350,7 @@ class ProjectsController < ApplicationController
|
|||
def notifications
|
||||
@modules = @project.assigned_modules(current_user).order(due_date: :desc)
|
||||
render json: {
|
||||
html: render_to_string(partial: 'notifications')
|
||||
html: render_to_string(partial: 'notifications', formats: :html)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -84,6 +84,31 @@ class RepositoryRowsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@repository_row = RepositoryRow.find_by(id: params[:id])
|
||||
@my_module = MyModule.find_by(id: params[:my_module_id])
|
||||
return render_404 unless @repository_row
|
||||
return render_404 unless @repository_row.repository_id == params[:repository_id].to_i
|
||||
return render_403 unless can_read_repository?(@repository_row.repository)
|
||||
return render_403 if @my_module && !can_read_my_module?(@my_module)
|
||||
|
||||
if @my_module
|
||||
@my_module_assign_error = if !can_assign_my_module_repository_rows?(@my_module)
|
||||
I18n.t('repository_row.modal_info.assign_to_task_error.no_access')
|
||||
elsif @repository_row.my_modules.where(id: @my_module.id).any?
|
||||
I18n.t('repository_row.modal_info.assign_to_task_error.already_assigned')
|
||||
end
|
||||
end
|
||||
|
||||
@assigned_modules = @repository_row.my_modules.joins(experiment: :project)
|
||||
@viewable_modules = @assigned_modules.viewable_by_user(current_user, current_user.teams)
|
||||
@private_modules = @assigned_modules - @viewable_modules
|
||||
|
||||
render json: {
|
||||
html: render_to_string(partial: 'repositories/repository_row_info_modal', formats: :html)
|
||||
}
|
||||
end
|
||||
|
||||
def validate_label_template_columns
|
||||
label_template = LabelTemplate.where(team_id: current_team.id).find(params[:label_template_id])
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class TeamRepositoriesController < ApplicationController
|
|||
|
||||
# DELETE :team_id/repositories/:repository_id/team_repositories/:id
|
||||
def destroy
|
||||
team_shared_object = @repository.team_shared_objects.find(destory_params[:id])
|
||||
team_shared_object = @repository.team_shared_objects.find(destroy_params[:id])
|
||||
ActiveRecord::Base.transaction do
|
||||
log_activity(:unshare_inventory, team_shared_object)
|
||||
team_shared_object.destroy!
|
||||
|
@ -50,7 +50,7 @@ class TeamRepositoriesController < ApplicationController
|
|||
params.permit(:team_id, :repository_id, :target_team_id, :permission_level)
|
||||
end
|
||||
|
||||
def destory_params
|
||||
def destroy_params
|
||||
params.permit(:team_id, :id)
|
||||
end
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ describe AccessPermissions::ExperimentsController, type: :controller do
|
|||
{
|
||||
id: experiment.id,
|
||||
project_id: project.id,
|
||||
experiment_member: {
|
||||
user_assignment: {
|
||||
user_role_id: technician_role.id,
|
||||
user_id: viewer_user.id
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ describe AccessPermissions::MyModulesController, type: :controller do
|
|||
id: my_module.id,
|
||||
experiment_id: experiment.id,
|
||||
project_id: project.id,
|
||||
my_module_member: {
|
||||
user_assignment: {
|
||||
user_role_id: technician_role.id,
|
||||
user_id: viewer_user.id
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ describe AccessPermissions::ProjectsController, type: :controller do
|
|||
let(:valid_params) do
|
||||
{
|
||||
id: project.id,
|
||||
project_member: {
|
||||
user_assignment: {
|
||||
user_role_id: technician_role.id,
|
||||
user_id: normal_user.id
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ describe AccessPermissions::ProjectsController, type: :controller do
|
|||
let(:valid_params) do
|
||||
{
|
||||
id: project.id,
|
||||
access_permissions_new_user_project_form: {
|
||||
access_permissions_new_user_form: {
|
||||
resource_members: {
|
||||
0 => {
|
||||
assign: '1',
|
||||
|
@ -193,8 +193,7 @@ describe AccessPermissions::ProjectsController, type: :controller do
|
|||
it 'removes the user project and user assigment record' do
|
||||
expect {
|
||||
delete :destroy, params: valid_params, format: :json
|
||||
}.to change(UserProject, :count).by(-1).and \
|
||||
change(UserAssignment, :count).by(-1)
|
||||
}.to change(UserAssignment, :count).by(-1)
|
||||
end
|
||||
|
||||
it 'renders 403 if user does not have manage permissions on project' do
|
||||
|
|
|
@ -68,8 +68,10 @@ describe ProjectsController, type: :controller do
|
|||
let(:action) { put :update, params: params }
|
||||
let(:params) do
|
||||
{ id: projects.first.id,
|
||||
project: { name: projects.first.name, team_id: projects.first.team.id,
|
||||
visibility: projects.first.visibility } }
|
||||
project: { name: projects.first.name,
|
||||
team_id: projects.first.team.id,
|
||||
visibility: projects.first.visibility,
|
||||
default_public_user_role_id: projects.first.default_public_user_role.id } }
|
||||
end
|
||||
|
||||
it 'returns redirect response' do
|
||||
|
@ -78,10 +80,10 @@ describe ProjectsController, type: :controller do
|
|||
expect(response.media_type).to eq 'text/html'
|
||||
end
|
||||
|
||||
it 'calls create activity service (change_project_visibility)' do
|
||||
it 'calls create activity service (project_grant_access_to_all_team_members)' do
|
||||
params[:project][:visibility] = 'visible'
|
||||
expect(Activities::CreateActivityService).to receive(:call)
|
||||
.with(hash_including(activity_type: :change_project_visibility))
|
||||
.with(hash_including(activity_type: :project_grant_access_to_all_team_members))
|
||||
action
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'rails_helper'
|
|||
describe ProtocolsController, type: :controller do
|
||||
login_user
|
||||
|
||||
include_context 'reference_project_structure'
|
||||
include_context 'reference_project_structure', { team_role: :owner }
|
||||
|
||||
describe 'POST create' do
|
||||
let(:action) { post :create, params: params, format: :json }
|
||||
|
@ -78,10 +78,12 @@ describe ProtocolsController, type: :controller do
|
|||
protocol: {
|
||||
name: 'my_test_protocol',
|
||||
description: 'description',
|
||||
authors: 'authors'
|
||||
authors: 'authors',
|
||||
elnVersion: '1.0',
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
let(:action) { post :import, params: params, format: :json }
|
||||
|
||||
it 'calls create activity for importing protocols' do
|
||||
|
@ -98,9 +100,9 @@ describe ProtocolsController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'PUT description' do
|
||||
describe 'PATCH description' do
|
||||
let(:protocol) do
|
||||
create :protocol, :in_public_repository, team: team, added_by: user
|
||||
create :protocol, :in_repository_draft, team: team, added_by: user
|
||||
end
|
||||
let(:params) do
|
||||
{
|
||||
|
@ -110,8 +112,7 @@ describe ProtocolsController, type: :controller do
|
|||
}
|
||||
}
|
||||
end
|
||||
let(:action) { put :update_description, params: params, format: :json }
|
||||
|
||||
let(:action) { patch :update_description, params: params, format: :json }
|
||||
it 'calls create activity for updating description' do
|
||||
expect(Activities::CreateActivityService)
|
||||
.to(receive(:call)
|
||||
|
@ -126,14 +127,14 @@ describe ProtocolsController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'POST update_keywords' do
|
||||
describe 'PATCH update_keywords' do
|
||||
let(:protocol) do
|
||||
create :protocol, :in_public_repository, team: team, added_by: user
|
||||
create :protocol, :in_repository_draft, team: team, added_by: user
|
||||
end
|
||||
let(:action) { put :update_keywords, params: params, format: :json }
|
||||
let(:params) do
|
||||
{ id: protocol.id, keywords: ['keyword-1', 'keyword-2'] }
|
||||
end
|
||||
let(:action) { patch :update_keywords, params: params, format: :json }
|
||||
|
||||
it 'calls create activity for updating keywords' do
|
||||
expect(Activities::CreateActivityService)
|
||||
|
@ -151,7 +152,7 @@ describe ProtocolsController, type: :controller do
|
|||
|
||||
context 'update protocol' do
|
||||
let(:protocol_repo) do
|
||||
create :protocol, :in_public_repository, name: ' test protocol',
|
||||
create :protocol, :in_repository_published_original, name: ' test protocol',
|
||||
team: team,
|
||||
added_by: user
|
||||
end
|
||||
|
@ -165,7 +166,7 @@ describe ProtocolsController, type: :controller do
|
|||
let(:params) { { id: protocol.id } }
|
||||
|
||||
describe 'POST revert' do
|
||||
let(:action) { put :revert, params: params, format: :json }
|
||||
let(:action) { post :revert, params: params, format: :json }
|
||||
|
||||
it 'calls create activity for updating protocol in task from repository' do
|
||||
expect(Activities::CreateActivityService)
|
||||
|
@ -184,13 +185,13 @@ describe ProtocolsController, type: :controller do
|
|||
|
||||
describe 'POST load_from_repository' do
|
||||
let(:protocol_source) do
|
||||
create :protocol, :in_public_repository, team: team, added_by: user
|
||||
create :protocol, :in_repository_published_original, team: team, added_by: user
|
||||
end
|
||||
let(:protocol) { create :protocol, team: team, added_by: user, my_module: my_module }
|
||||
let(:action) { put :load_from_repository, params: params, format: :json }
|
||||
let(:params) do
|
||||
{ source_id: protocol_source.id, id: protocol.id }
|
||||
end
|
||||
let(:action) { post :load_from_repository, params: params, format: :json }
|
||||
|
||||
it 'calls create activity for loading protocol to task from repository' do
|
||||
expect(Activities::CreateActivityService)
|
||||
|
@ -210,13 +211,14 @@ describe ProtocolsController, type: :controller do
|
|||
let(:protocol) do
|
||||
create :protocol, my_module: my_module, team: team, added_by: user
|
||||
end
|
||||
let(:action) { put :load_from_file, params: params, format: :json }
|
||||
let(:params) do
|
||||
{ id: protocol.id,
|
||||
protocol: { name: 'my_test_protocol',
|
||||
description: 'description',
|
||||
authors: 'authors' } }
|
||||
authors: 'authors',
|
||||
elnVersion: '1.1'} }
|
||||
end
|
||||
let(:action) { post :load_from_file, params: params, format: :json }
|
||||
|
||||
it 'calls create activity for loading protocol to task from file' do
|
||||
expect(Activities::CreateActivityService)
|
||||
|
|
|
@ -16,7 +16,8 @@ describe ResultTablesController, type: :controller do
|
|||
result:
|
||||
{ name: 'result name created',
|
||||
table_attributes:
|
||||
{ contents: '{\"data\":[[\"a\",\"b\",\"1\",null,null]]}' } } }
|
||||
{ contents: '{\"data\":[[\"a\",\"b\",\"1\",null,null]]}',
|
||||
metadata: "{\"cells\":[{\"row\":\"0\",\"col\":\"0\",\"className\":\"\",\"calculated\":\"\"}]}" } } }
|
||||
end
|
||||
|
||||
it 'calls create activity service' do
|
||||
|
|
|
@ -10,7 +10,7 @@ describe StepsController, type: :controller do
|
|||
}
|
||||
|
||||
let(:protocol_repo) do
|
||||
create :protocol, :in_public_repository, team: team, added_by: user
|
||||
create :protocol, :in_repository_draft, team: team, added_by: user
|
||||
end
|
||||
let(:step_repo) { create :step, protocol: protocol_repo }
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@ describe TeamRepositoriesController, type: :controller do
|
|||
|
||||
describe 'DELETE destroy' do
|
||||
let(:second_team) { create :team, created_by: user }
|
||||
let(:team_repository) { create :team_repository, :read, team: second_team, repository: repository }
|
||||
let(:team_repository) { create :team_shared_object, :read, team: second_team, shared_object: repository }
|
||||
|
||||
context 'when resource can be deleted' do
|
||||
let(:action) do
|
||||
delete :destroy, params: { repository_id: repository.id, team_id: team.id, id: team_repository.id }
|
||||
delete :destroy, params: { team_id: team.id, id: team_repository.id }
|
||||
end
|
||||
|
||||
it 'renders 204' do
|
||||
|
|
|
@ -4,5 +4,15 @@ FactoryBot.define do
|
|||
factory :settings do
|
||||
type { Faker::Lorem.sentence.split(' ').sample }
|
||||
values { { key_of_data: Faker::Lorem.sentence.split(' ').sample } }
|
||||
|
||||
trait :with_load_values_from_env_defined do
|
||||
after(:build) do |application_settings|
|
||||
application_settings.define_singleton_method(:load_values_from_env) do
|
||||
{
|
||||
some_key: Faker::Lorem.sentence.split(' ').sample
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :team_shared_object do
|
||||
repository
|
||||
trait :read do
|
||||
permission_level { :shared_read }
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :user_assignment do
|
||||
end
|
||||
|
|
|
@ -2,9 +2,7 @@ FactoryBot.define do
|
|||
factory :user_role do
|
||||
factory :owner_role do
|
||||
name { I18n.t('user_roles.predefined.owner') }
|
||||
permissions { ProjectPermissions.constants.map { |const| ProjectPermissions.const_get(const) } +
|
||||
ExperimentPermissions.constants.map { |const| ExperimentPermissions.const_get(const) } +
|
||||
MyModulePermissions.constants.map { |const| MyModulePermissions.const_get(const) } }
|
||||
permissions { PredefinedRoles::OWNER_PERMISSIONS }
|
||||
predefined { true }
|
||||
end
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
"published_on": 1516132805,
|
||||
"version": 0,
|
||||
"source_id": 9451,
|
||||
"name": "CUT\u0026RUN: Targeted in situ genome-wide profiling with high efficiency for low cell numbers",
|
||||
"name": "CUT&RUN: Targeted in situ genome-wide profiling with high efficiency for low cell numbers",
|
||||
"description": {
|
||||
"body": "\u003cdiv class = \"text-blocks\"\u003e\u003cdiv class = \"text-block\"\u003eCleavage Under Targets and Release Using Nuclease (CUT\u0026RUN) is an epigenomic profiling strategy in which antibody-targeted controlled cleavage by micrococcal nuclease releases specific protein-DNA complexes into the supernatant for paired-end DNA sequencing. As only the targeted fragments enter into solution, and the vast majority of DNA is left behind, CUT\u0026RUN has exceptionally low background levels. CUT\u0026RUN outperforms the most widely used Chromatin Immunoprecipitation (ChIP) protocols in resolution, signal-to-noise, and depth of sequencing required. In contrast to ChIP, CUT\u0026RUN is free of solubility and DNA accessibility artifacts and can be used to profile insoluble chromatin and to detect long-range 3D contacts without cross-linking. Here we present an improved CUT\u0026RUN protocol that does not require isolation of nuclei and provides high-quality data starting with only 100 cells for a histone modification and 1000 cells for a transcription factor. From cells to purified DNA CUT\u0026RUN requires less than a day at the lab bench.\u003c/div\u003e\u003cdiv class = \"text-block\"\u003eIn summary, CUT\u0026RUN has several advantages over ChIP-seq: (1) The method is performed in situ in non-crosslinked cells and does not require chromatin fragmentation or solubilization; (2) The intrinsically low background allows low sequence depth and identification of low signal genomic features invisible to ChIP; (3) The simple procedure can be completed within a day and is suitable for robotic automation; (4) The method can be used with low cell numbers compared to existing methodologies; (5) A simple spike-in strategy can be used for accurate quantitation of protein-DNA interactions. As such, CUT\u0026RUN represents an attractive replacement for ChIPseq, which is one of the most popular methods in biological research.\u003c/div\u003e\u003c/div\u003e",
|
||||
"body": "<div class = \"text-blocks\"><div class = \"text-block\">Cleavage Under Targets and Release Using Nuclease (CUT&RUN) is an epigenomic profiling strategy in which antibody-targeted controlled cleavage by micrococcal nuclease releases specific protein-DNA complexes into the supernatant for paired-end DNA sequencing. As only the targeted fragments enter into solution, and the vast majority of DNA is left behind, CUT&RUN has exceptionally low background levels. CUT&RUN outperforms the most widely used Chromatin Immunoprecipitation (ChIP) protocols in resolution, signal-to-noise, and depth of sequencing required. In contrast to ChIP, CUT&RUN is free of solubility and DNA accessibility artifacts and can be used to profile insoluble chromatin and to detect long-range 3D contacts without cross-linking. Here we present an improved CUT&RUN protocol that does not require isolation of nuclei and provides high-quality data starting with only 100 cells for a histone modification and 1000 cells for a transcription factor. From cells to purified DNA CUT&RUN requires less than a day at the lab bench.</div><div class = \"text-block\">In summary, CUT&RUN has several advantages over ChIP-seq: (1) The method is performed in situ in non-crosslinked cells and does not require chromatin fragmentation or solubilization; (2) The intrinsically low background allows low sequence depth and identification of low signal genomic features invisible to ChIP; (3) The simple procedure can be completed within a day and is suitable for robotic automation; (4) The method can be used with low cell numbers compared to existing methodologies; (5) A simple spike-in strategy can be used for accurate quantitation of protein-DNA interactions. As such, CUT&RUN represents an attractive replacement for ChIPseq, which is one of the most popular methods in biological research.</div></div>",
|
||||
"image": "https://s3.amazonaws.com/pr-journal/rzxfw26.png",
|
||||
"extra_content": []
|
||||
},
|
||||
|
@ -17,8 +17,22 @@
|
|||
{
|
||||
"source_id": 601564,
|
||||
"name": "Binding cells to beads",
|
||||
"attachments": [
|
||||
{
|
||||
"url": "https://pbs.twimg.com/media/Cwu3zrZWQAA7axs.jpg",
|
||||
"name": "First file"
|
||||
},
|
||||
{
|
||||
"url": "http://something.com/wp-content/uploads/2014/11/14506718045_5b3e71dacd_o.jpg",
|
||||
"name": "Second file"
|
||||
},
|
||||
{
|
||||
"url": "http://something.com/wp-content/uploads/2014/11/14506718045_5b3e71dacd_o.jpg",
|
||||
"name": "14506718045_5b3e71dacd_o.jpg"
|
||||
}
|
||||
],
|
||||
"description": {
|
||||
"body": "\u003cdiv class = \"text-blocks\"\u003e\u003cdiv class = \"text-block\"\u003e\u003cspan style = \":justify;\"\u003eHarvest fresh culture(s) at room temperature and count cells. The same protocol can be used for 100 to 250,000 mammalian cells per sample and/or digestion time point.\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e",
|
||||
"body": "<div class = \"text-blocks\"><div class = \"text-block\"><span style = \":justify;\">Harvest fresh culture(s) at room temperature and count cells. The same protocol can be used for 100 to 250,000 mammalian cells per sample and/or digestion time point.</span></div></div>",
|
||||
"components": [
|
||||
{
|
||||
"type": "amount",
|
||||
|
@ -60,11 +74,11 @@
|
|||
},
|
||||
{
|
||||
"type": "result",
|
||||
"body": "\u003cdiv class = \"text-blocks\"\u003e\u003cdiv class = \"text-block\"\u003eCentrifuge 3 min... This is expected result with HTML.\u003c/div\u003e\u003c/div\u003e"
|
||||
"body": "<div class = \"text-blocks\"><div class = \"text-block\">Centrifuge 3 min... This is expected result with HTML.</div></div>"
|
||||
},
|
||||
{
|
||||
"type": "warning",
|
||||
"body": "\u003cdiv class = \"text-blocks\"\u003e\u003cdiv class = \"text-block\"\u003eCentrifuge 3 min... This is WARNING with HTML.\u003c/div\u003e\u003c/div\u003e",
|
||||
"body": "<div class = \"text-blocks\"><div class = \"text-block\">Centrifuge 3 min... This is WARNING with HTML.</div></div>",
|
||||
"details": {
|
||||
"link": "www.warnings.com/be_careful"
|
||||
}
|
||||
|
@ -99,34 +113,20 @@
|
|||
{
|
||||
"type": "note",
|
||||
"author": "Frank Jones",
|
||||
"body": "\u003cdiv class = \"text-blocks\"\u003e\u003cdiv class = \"text-block\"\u003eCentrifuge 3 min... This is expected result with HTML.\u003c/div\u003e\u003c/div\u003e"
|
||||
"body": "<div class = \"text-blocks\"><div class = \"text-block\">Centrifuge 3 min... This is expected result with HTML.</div></div>"
|
||||
}
|
||||
]
|
||||
},
|
||||
"attachments": [
|
||||
{
|
||||
"url": "https://pbs.twimg.com/media/Cwu3zrZWQAA7axs.jpg",
|
||||
"name": "First file"
|
||||
},
|
||||
{
|
||||
"url": "http://something.com/wp-content/uploads/2014/11/14506718045_5b3e71dacd_o.jpg",
|
||||
"name": "Second file"
|
||||
},
|
||||
{
|
||||
"url": "http://something.com/wp-content/uploads/2014/11/14506718045_5b3e71dacd_o.jpg",
|
||||
"name": "14506718045_5b3e71dacd_o.jpg"
|
||||
}
|
||||
],
|
||||
"position": 0
|
||||
},
|
||||
{
|
||||
"source_id": 601565,
|
||||
"name": "Binding cells to beads 2",
|
||||
"attachments": [],
|
||||
"description": {
|
||||
"body": "\u003cdiv class = \"text-blocks\"\u003e\u003cdiv class = \"text-block\"\u003eCentrifuge 3 min 600 x g at room temperature and withdraw liquid.\u003c/div\u003e\u003c/div\u003e",
|
||||
"body": "<div class = \"text-blocks\"><div class = \"text-block\">Centrifuge 3 min 600 x g at room temperature and withdraw liquid.</div></div>",
|
||||
"components": []
|
||||
},
|
||||
"attachments": [],
|
||||
"position": 1
|
||||
}
|
||||
]
|
||||
|
|
|
@ -42,7 +42,7 @@ module UserAssignments
|
|||
create :user_assignment, assignable: my_module_two, user: user_two, user_role: technician_role, assigned_by: user_one
|
||||
|
||||
expect {
|
||||
described_class.perform_now(project, user_two, technician_role, user_one, destroy: true)
|
||||
described_class.perform_now(project, user_two.id, technician_role, user_one, destroy: true)
|
||||
}.to change(UserAssignment, :count).by(-4)
|
||||
end
|
||||
|
||||
|
|
|
@ -13,8 +13,14 @@ describe Connection, type: :model do
|
|||
expect(subject.class).to eq Connection
|
||||
end
|
||||
|
||||
describe 'Database table' do
|
||||
it { should have_db_column :id }
|
||||
it { should have_db_column :input_id }
|
||||
it { should have_db_column :output_id }
|
||||
end
|
||||
|
||||
describe 'Relations' do
|
||||
#it { should belong_to(:to).class_name('MyModule') }
|
||||
#it { should belong_to(:from).class_name('MyModule') }
|
||||
it { should belong_to(:to).class_name('MyModule').with_foreign_key('input_id').inverse_of(:inputs) }
|
||||
it { should belong_to(:from).class_name('MyModule').with_foreign_key('output_id').inverse_of(:outputs) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Connection, type: :model do
|
||||
it 'should be of class Connection' do
|
||||
expect(subject.class).to eq Connection
|
||||
end
|
||||
|
||||
describe 'Database table' do
|
||||
it { should have_db_column :id }
|
||||
it { should have_db_column :input_id }
|
||||
it { should have_db_column :output_id }
|
||||
end
|
||||
|
||||
describe 'Relations' do
|
||||
it { should belong_to(:to).class_name('MyModule') }
|
||||
it { should belong_to(:from).class_name('MyModule') }
|
||||
end
|
||||
end
|
|
@ -1,53 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ExperimentMember, type: :model do
|
||||
# let(:owner_role) { create :owner_role }
|
||||
let!(:user) { create :user }
|
||||
let!(:owner_role) { UserRole.find_by(name: I18n.t('user_roles.predefined.owner')) }
|
||||
let!(:project) { create :project }
|
||||
let!(:user_project) { create :user_project, user: user, project: project }
|
||||
let!(:user_assignment) do
|
||||
create :user_assignment,
|
||||
assignable: project,
|
||||
user: user,
|
||||
user_role: owner_role,
|
||||
assigned_by: user
|
||||
end
|
||||
let!(:experiment) { create :experiment, project: project }
|
||||
let(:normal_user_role) { create :normal_user_role }
|
||||
|
||||
let(:subject) { described_class.new(user, experiment, project) }
|
||||
|
||||
describe '#update' do
|
||||
let!(:experiment_user_assignment) do
|
||||
create :user_assignment,
|
||||
assignable: experiment,
|
||||
user: user,
|
||||
user_role: owner_role,
|
||||
assigned_by: user
|
||||
end
|
||||
|
||||
let!(:valid_params) do
|
||||
{
|
||||
user_id: user.id,
|
||||
user_role_id: normal_user_role.id
|
||||
}
|
||||
end
|
||||
|
||||
let!(:subject) { described_class.new(user, experiment, project, user, experiment_user_assignment) }
|
||||
|
||||
it 'updates the assigment user role' do
|
||||
subject.update(valid_params)
|
||||
expect(experiment_user_assignment.reload.user_role).to eq normal_user_role
|
||||
end
|
||||
|
||||
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_experiment'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe MyModuleMember, type: :model do
|
||||
# let(:owner_role) { create :owner_role }
|
||||
let!(:user) { create :user }
|
||||
let!(:owner_role) { UserRole.find_by(name: I18n.t('user_roles.predefined.owner')) }
|
||||
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 }
|
||||
let(:normal_user_role) { create :normal_user_role }
|
||||
|
||||
describe '#update' do
|
||||
let!(:valid_params) do
|
||||
{
|
||||
user_id: user.id,
|
||||
user_role_id: normal_user_role.id
|
||||
}
|
||||
end
|
||||
|
||||
let!(:subject) { described_class.new(user, my_module, experiment, project, user) }
|
||||
|
||||
it 'updates the assigment user role' do
|
||||
subject.update(valid_params)
|
||||
expect(subject.user_assignment.user_role).to eq normal_user_role
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
|
@ -1,117 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ProjectMember, type: :model do
|
||||
let!(:owner_role) { UserRole.find_by(name: I18n.t('user_roles.predefined.owner')) }
|
||||
let!(:user) { create :user }
|
||||
let!(:project) { create :project, created_by: user }
|
||||
let(:normal_user_role) { create :normal_user_role }
|
||||
|
||||
let(:subject) { described_class.new(user, project, user) }
|
||||
|
||||
describe '#update' do
|
||||
let!(:user_project) { create :user_project, user: user, project: project }
|
||||
|
||||
it 'updates only the user assignment role' do
|
||||
subject.user_role_id = normal_user_role.id
|
||||
subject.update
|
||||
expect(subject.user_assignment.user_role).to eq normal_user_role
|
||||
end
|
||||
|
||||
it 'logs a change_user_role_on_project activity' do
|
||||
subject.user_role_id = normal_user_role.id
|
||||
expect {
|
||||
subject.update
|
||||
}.to change(Activity, :count).by(1)
|
||||
expect(Activity.last.type_of).to eq 'change_user_role_on_project'
|
||||
end
|
||||
|
||||
it 'triggers the UserAssignments::PropagateAssignmentJob job' do
|
||||
subject.user_role_id = normal_user_role.id
|
||||
expect(UserAssignments::PropagateAssignmentJob).to receive(:perform_later).with(
|
||||
project, user.id, normal_user_role, user.id
|
||||
)
|
||||
subject.update
|
||||
end
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
let!(:user_two) { create :user }
|
||||
let!(:user_project_two) { create :user_project, user: user_two, project: project }
|
||||
let!(:user_assignment_two) do
|
||||
create :user_assignment,
|
||||
assignable: project,
|
||||
user: user_two,
|
||||
user_role: owner_role,
|
||||
assigned_by: user
|
||||
end
|
||||
let!(:user_project) { create :user_project, user: user, project: project }
|
||||
let!(:user_assignment) { project.user_assignments.first }
|
||||
|
||||
it 'removes the user_assignment and user_project' do
|
||||
expect {
|
||||
subject.destroy
|
||||
}.to change(UserAssignment, :count).by(-1).and \
|
||||
change(UserProject, :count).by(-1)
|
||||
end
|
||||
|
||||
it 'does not remove the user_assignment and user_project if the user is last owner' do
|
||||
user_assignment_two.update!(user_role: normal_user_role)
|
||||
|
||||
expect {
|
||||
subject.destroy
|
||||
}.to change(UserAssignment, :count).by(0).and \
|
||||
change(UserProject, :count).by(0)
|
||||
end
|
||||
|
||||
it 'logs a unassign_user_from_project activity' do
|
||||
expect {
|
||||
subject.destroy
|
||||
}.to change(Activity, :count).by(1)
|
||||
expect(Activity.last.type_of).to eq 'unassign_user_from_project'
|
||||
end
|
||||
|
||||
it 'triggers the UserAssignments::PropagateAssignmentJob job' do
|
||||
expect(UserAssignments::PropagateAssignmentJob).to receive(:perform_later).with(
|
||||
project, user.id, owner_role, user.id, destroy: true
|
||||
)
|
||||
subject.destroy
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it 'validates presence or user, project, user_role_id when assign is true' do
|
||||
subject = described_class.new(nil, nil)
|
||||
subject.assign = true
|
||||
subject.valid?
|
||||
expect(subject.errors).to have_key(:project)
|
||||
expect(subject.errors).to have_key(:user)
|
||||
expect(subject.errors).to have_key(:user_role_id)
|
||||
end
|
||||
|
||||
it 'validates user project assignment existence' do
|
||||
subject.assign = true
|
||||
subject.user_assignment.user_role_id = owner_role.id
|
||||
subject.valid?
|
||||
expect(subject.errors).to have_key(:user_role_id)
|
||||
end
|
||||
|
||||
describe 'user_role' do
|
||||
it 'adds an error when user role does not exist' do
|
||||
subject.assign = true
|
||||
subject.user_role_id = 1234
|
||||
subject.valid?
|
||||
expect(subject.errors).to have_key(:user_role_id)
|
||||
end
|
||||
|
||||
it 'does not add an error when role exists' do
|
||||
project.user_assignments.destroy_all
|
||||
subject.assign = true
|
||||
subject.user_role_id = owner_role.id
|
||||
subject.valid?
|
||||
expect(subject.errors).not_to have_key(:user_role_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -95,44 +95,6 @@ describe Protocol, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.publish(user)' do
|
||||
let(:user) { create :user }
|
||||
let(:team) { create :team, created_by: user }
|
||||
let(:protocol) { create :protocol, :in_public_repository, team: team, added_by: user }
|
||||
|
||||
it 'calls create activity for restoring protocol' do
|
||||
expect(Activities::CreateActivityService)
|
||||
.to(receive(:call)
|
||||
.with(hash_including(activity_type:
|
||||
:move_protocol_in_repository)))
|
||||
|
||||
protocol.publish user
|
||||
end
|
||||
|
||||
it 'creats one new activity DB' do
|
||||
expect { protocol.publish(user) }.to change { Activity.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.make_private(user)' do
|
||||
let(:user) { create :user }
|
||||
let(:team) { create :team, created_by: user }
|
||||
let(:protocol) { create :protocol, :in_public_repository, team: team, added_by: user }
|
||||
|
||||
it 'calls create activity for restoring protocol' do
|
||||
expect(Activities::CreateActivityService)
|
||||
.to(receive(:call)
|
||||
.with(hash_including(activity_type:
|
||||
:move_protocol_in_repository)))
|
||||
|
||||
protocol.make_private user
|
||||
end
|
||||
|
||||
it 'creats one new activity DB' do
|
||||
expect { protocol.make_private(user) }.to change { Activity.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.deep_clone_repository' do
|
||||
let(:user) { create :user }
|
||||
let(:team) { create :team, created_by: user }
|
||||
|
|
|
@ -3,14 +3,20 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Settings, type: :model do
|
||||
let(:settings) { build :settings }
|
||||
let(:settings) { build(:settings) }
|
||||
let(:application_settings) { build(:settings, :with_load_values_from_env_defined) }
|
||||
|
||||
it 'raises not NotImplementedError' do
|
||||
expect { settings.load_values_from_env }.to raise_error(NotImplementedError)
|
||||
end
|
||||
|
||||
|
||||
it 'is valid' do
|
||||
expect(settings).to be_valid
|
||||
expect(application_settings).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class Settings' do
|
||||
expect(subject.class).to eq Settings
|
||||
expect(application_settings.class).to eq Settings
|
||||
end
|
||||
|
||||
describe 'Database table' do
|
||||
|
|
|
@ -7,16 +7,19 @@ describe TeamSharedObject, type: :model do
|
|||
let(:team) { create :team, created_by: user }
|
||||
let(:another_team) { create :team, created_by: user }
|
||||
let(:repository) { create :repository, team: team, created_by: user }
|
||||
let(:team_shared_object) { build :team_shared_object, :read, team: another_team, shared_repository: repository }
|
||||
let(:team_shared_object) { create :team_shared_object, :read, team: another_team, shared_object: repository }
|
||||
|
||||
it 'is valid' do
|
||||
expect(team_shared_object).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class TeamSharedObject' do
|
||||
expect(subject.class).to eq TeamSharedObject
|
||||
end
|
||||
|
||||
describe 'Associations' do
|
||||
it { is_expected.to belong_to(:team) }
|
||||
it { is_expected.to belong_to(:shared_repository) }
|
||||
it { is_expected.to belong_to(:shared_object) }
|
||||
describe 'Relations' do
|
||||
it { should belong_to(:team) }
|
||||
it { should belong_to(:shared_object) }
|
||||
it { should belong_to(:shared_repository).optional }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,8 +19,20 @@ describe ExperimentsController, type: :controller do
|
|||
move: { id: 1 },
|
||||
module_archive: { id: 1 },
|
||||
fetch_workflow_img: { id: 1 },
|
||||
sidebar: { id: 1 }
|
||||
}, []
|
||||
sidebar: { id: 1 },
|
||||
my_modules: { id: 1 },
|
||||
load_table: { id: 1 },
|
||||
permissions: { id: 1 },
|
||||
assigned_users_to_tasks: { id: 1 },
|
||||
batch_clone_my_modules: { id: 1 },
|
||||
search_tags: { id: 1 },
|
||||
actions_dropdown: { id: 1 },
|
||||
archive_my_modules: { id: 1 },
|
||||
table: { id: 1 },
|
||||
move_modules: { id: 1 },
|
||||
move_modules_modal: { id: 1 },
|
||||
view_type: { id: 1, view_type: 'table' },
|
||||
}, [:set_breadcrumbs_items, :my_modules_view_mode]
|
||||
|
||||
login_user
|
||||
|
||||
|
@ -87,13 +99,13 @@ describe ExperimentsController, type: :controller do
|
|||
|
||||
it_behaves_like "a controller action with permissions checking", :get, :clone_modal do
|
||||
let(:testable) { experiment }
|
||||
let(:permissions) { [ExperimentPermissions::MANAGE] }
|
||||
let(:permissions) { [ExperimentPermissions::READ] }
|
||||
let(:action_params) { { id: experiment.id } }
|
||||
end
|
||||
|
||||
it_behaves_like "a controller action with permissions checking", :post, :clone do
|
||||
let(:testable) { experiment }
|
||||
let(:permissions) { [ExperimentPermissions::MANAGE] }
|
||||
let(:permissions) { [ExperimentPermissions::READ] }
|
||||
let(:action_params) { { id: experiment.id } }
|
||||
end
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ describe MyModuleRepositoriesController, type: :controller do
|
|||
|
||||
it_behaves_like "a controller with authentication", {
|
||||
index_dt: { my_module_id: 1, id: 1 },
|
||||
create: { my_module_id: 1, id: 1, my_module_tag: { tag_id: 1, my_module_id: 1 } },
|
||||
update: { my_module_id: 1, id: 1 },
|
||||
update_repository_records_modal: { my_module_id: 1, id: 1 },
|
||||
assign_repository_records_modal: { my_module_id: 1, id: 1 },
|
||||
|
|
|
@ -16,12 +16,19 @@ describe MyModulesController, type: :controller do
|
|||
update_description: { id: 1 },
|
||||
update_protocol_description: { id: 1 },
|
||||
protocols: { id: 1 },
|
||||
protocol: { id: 1 },
|
||||
update_protocol: { id: 1 },
|
||||
provisioning_status: { id: 1 },
|
||||
actions_dropdown: { id: 1 },
|
||||
new: { id: 1, experiment_id: 1 },
|
||||
create: { id: 1, experiment_id: 1 },
|
||||
permissions: { id: 1 },
|
||||
results: { id: 1 },
|
||||
archive: { id: 1 },
|
||||
restore_group: { id: 1 },
|
||||
update_state: { id: 1 },
|
||||
canvas_dropdown_menu: { id: 1 }
|
||||
}, []
|
||||
}, [:set_breadcrumbs_items]
|
||||
|
||||
login_user
|
||||
|
||||
|
|
|
@ -12,8 +12,10 @@ describe ProjectsController, type: :controller do
|
|||
show: { id: 1 },
|
||||
experiments_cards: { id: 1 },
|
||||
notifications: { id: 1 },
|
||||
permissions: { id: 1 },
|
||||
actions_dropdown: { id: 1 },
|
||||
view_type: { id: 1 }
|
||||
}, [:current_folder]
|
||||
}, [:current_folder, :set_breadcrumbs_items, :create_tag]
|
||||
|
||||
login_user
|
||||
|
||||
|
|
|
@ -34,10 +34,10 @@ RSpec.shared_context 'reference_project_structure' do |config|
|
|||
let!(:team_assignment) { create :user_assignment, user: user, assignable: team, user_role: owner_role }
|
||||
end
|
||||
|
||||
let!(:project) { create(:project, team: team, created_by: user) }
|
||||
let!(:projects) { create_list(:project, config[:projects], team: team, created_by: user) } if config[:projects]
|
||||
let!(:project) { create(:project, team: team, created_by: user, default_public_user_role_id: team_assignment.user_role.id) }
|
||||
let!(:projects) { create_list(:project, config[:projects], team: team, created_by: user, default_public_user_role_id: team_assignment.user_role.id) } if config[:projects]
|
||||
|
||||
let!(:experiment) { create :experiment, project: project, created_by: project.created_by} unless config[:skip_experiment]
|
||||
let!(:experiment) { create :experiment, project: project, created_by: project.created_by } unless config[:skip_experiment]
|
||||
let!(:experiments) { create_list :experiment, config[:experiments], project: project, created_by: project.created_by } if config[:experiments]
|
||||
|
||||
let!(:my_module) { create :my_module, experiment: experiment, created_by: experiment.created_by } unless config[:skip_my_module]
|
||||
|
|
|
@ -10,7 +10,7 @@ describe ProtocolImporters::ProtocolsIo::V3::ApiClient do
|
|||
URL_PUBLICATIONS = "#{CONSTANTS[:base_uri]}publications"
|
||||
|
||||
let(:query_params) do
|
||||
{ latest: '50' }
|
||||
{ latest: '20' }
|
||||
end
|
||||
|
||||
let(:stub_protocols) do
|
||||
|
|
|
@ -39,7 +39,7 @@ describe ProtocolImporters::ProtocolsIo::V3::ProtocolNormalizer do
|
|||
allow(client_data).to receive_message_chain(:parsed_response)
|
||||
.and_return(protocols_io_single_protocol)
|
||||
|
||||
expect(subject.normalize_protocol(client_data).deep_stringify_keys).to be == normalized_protocol
|
||||
expect(subject.normalize_protocol(client_data).deep_stringify_keys).to eq(normalized_protocol)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue