mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-04 12:14:37 +08:00
fixes failing tests [fixes SCI-1470]
This commit is contained in:
parent
f43419d9a9
commit
b69ec22dfe
33 changed files with 237 additions and 47 deletions
|
@ -472,7 +472,7 @@ class Asset < ApplicationRecord
|
|||
if errors.size > 1
|
||||
temp_errors = errors[:file]
|
||||
errors.clear
|
||||
errors.set(:file, temp_errors)
|
||||
errors.add(:file, temp_errors)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
5
spec/factories/asset_text_datums.rb
Normal file
5
spec/factories/asset_text_datums.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :asset_text_datum do
|
||||
data "Sample name\tSample type\n" + "sample6\tsample\n" + "\n"
|
||||
end
|
||||
end
|
12
spec/factories/assets.rb
Normal file
12
spec/factories/assets.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
FactoryGirl.define do
|
||||
factory :asset do
|
||||
association :created_by, factory: :project_user
|
||||
association :team, factory: :team
|
||||
file_file_name 'sample_file.txt'
|
||||
file_content_type 'text/plain'
|
||||
file_file_size 69
|
||||
version 1
|
||||
estimated_size 232
|
||||
file_processing false
|
||||
end
|
||||
end
|
5
spec/factories/custom_fields.rb
Normal file
5
spec/factories/custom_fields.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :custom_field do
|
||||
name 'My custom field'
|
||||
end
|
||||
end
|
27
spec/factories/experiments.rb
Normal file
27
spec/factories/experiments.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
FactoryGirl.define do
|
||||
factory :experiment do
|
||||
name 'My Experiment'
|
||||
description 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'
|
||||
end
|
||||
|
||||
factory :experiment_one, class: Experiment do
|
||||
name 'My Experiment One'
|
||||
description 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'
|
||||
association :project, factory: :project
|
||||
association :created_by, factory: :user, email: Faker::Internet.email
|
||||
association :last_modified_by,
|
||||
factory: :user,
|
||||
email: Faker::Internet.email
|
||||
end
|
||||
|
||||
|
||||
factory :experiment_two, class: Experiment do
|
||||
name Faker::Name.name
|
||||
description 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'
|
||||
association :project, factory: :project
|
||||
association :created_by, factory: :user, email: Faker::Internet.email
|
||||
association :last_modified_by,
|
||||
factory: :user,
|
||||
email: Faker::Internet.email
|
||||
end
|
||||
end
|
6
spec/factories/my_module_groups.rb
Normal file
6
spec/factories/my_module_groups.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :my_module_group do
|
||||
name Faker::Name.unique.name
|
||||
experiment { Experiment.first || create(:experiment_two) }
|
||||
end
|
||||
end
|
6
spec/factories/my_module_repository_rows.rb
Normal file
6
spec/factories/my_module_repository_rows.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :mm_repository_row, class: MyModuleRepositoryRow do
|
||||
association :repository_row, factory: :repository_row
|
||||
association :my_module, factory: :my_module
|
||||
end
|
||||
end
|
10
spec/factories/my_modules.rb
Normal file
10
spec/factories/my_modules.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
FactoryGirl.define do
|
||||
factory :my_module do
|
||||
name 'My first module'
|
||||
x 0
|
||||
y 0
|
||||
workflow_order 0
|
||||
experiment { Experiment.first || create(:experiment_one) }
|
||||
my_module_group { MyModuleGroup.first || create(:my_module_group) }
|
||||
end
|
||||
end
|
|
@ -1,13 +1,13 @@
|
|||
FactoryGirl.define do
|
||||
factory :project do
|
||||
association :created_by, factory: :project_user
|
||||
association :team, factory: :team
|
||||
created_by { User.first || association(:project_user) }
|
||||
team { Team.first || association(:project_team) }
|
||||
archived false
|
||||
name 'My project'
|
||||
visibility 'hidden'
|
||||
end
|
||||
|
||||
factory :project_user, class: 'User' do
|
||||
factory :project_user, class: User do
|
||||
full_name Faker::Name.name
|
||||
initials 'AD'
|
||||
email Faker::Internet.email
|
||||
|
@ -15,8 +15,8 @@ FactoryGirl.define do
|
|||
password_confirmation 'asdf1243'
|
||||
end
|
||||
|
||||
factory :project_team do
|
||||
association :created_by, factory: :project_user
|
||||
factory :project_team, class: Team do
|
||||
created_by { User.first || association(:project_user) }
|
||||
name 'My team'
|
||||
description 'Lorem ipsum dolor sit amet, consectetuer adipiscing eli.'
|
||||
space_taken 1048576
|
||||
|
|
7
spec/factories/reports.rb
Normal file
7
spec/factories/reports.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
FactoryGirl.define do
|
||||
factory :report do
|
||||
user { User.first || association(:user) }
|
||||
project { Project.first || association(:project) }
|
||||
name Faker::Name.unique.name
|
||||
end
|
||||
end
|
7
spec/factories/repository.rb
Normal file
7
spec/factories/repository.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
FactoryGirl.define do
|
||||
factory :repository do
|
||||
name 'My Repository'
|
||||
created_by { User.first || create(:user) }
|
||||
team { Team.first || create(:team) }
|
||||
end
|
||||
end
|
9
spec/factories/repository_cell.rb
Normal file
9
spec/factories/repository_cell.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
FactoryGirl.define do
|
||||
factory :repository_cell do
|
||||
repository_row { RepositoryRow.first || create(:repository_row) }
|
||||
repository_column do
|
||||
RepositoryColumn.first || create(:repository_column)
|
||||
end
|
||||
value 'RepositoryTextValue'
|
||||
end
|
||||
end
|
8
spec/factories/repository_columns.rb
Normal file
8
spec/factories/repository_columns.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
FactoryGirl.define do
|
||||
factory :repository_column do
|
||||
name 'My Column'
|
||||
created_by { User.first || create(:user) }
|
||||
repository { Repository.first || create(:repository) }
|
||||
data_type :RepositoryTextValue
|
||||
end
|
||||
end
|
7
spec/factories/repository_rows.rb
Normal file
7
spec/factories/repository_rows.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
FactoryGirl.define do
|
||||
factory :repository_row do
|
||||
name 'Custom row'
|
||||
created_by { User.first || association(:user) }
|
||||
last_modified_by { User.first || association(:user) }
|
||||
end
|
||||
end
|
7
spec/factories/sample_groups.rb
Normal file
7
spec/factories/sample_groups.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
FactoryGirl.define do
|
||||
factory :sample_group do
|
||||
name 'Sample'
|
||||
color '#ff00ff'
|
||||
team { Team.first || create(:team) }
|
||||
end
|
||||
end
|
6
spec/factories/sample_my_modules.rb
Normal file
6
spec/factories/sample_my_modules.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :sample_my_module do
|
||||
sample { Sample.frist || create(:sample) }
|
||||
my_module { MyModule.frist || create(:my_module) }
|
||||
end
|
||||
end
|
|
@ -1,5 +1,7 @@
|
|||
FactoryGirl.define do
|
||||
factory :sample do
|
||||
name 'Sample'
|
||||
user { User.first || create(:user) }
|
||||
team { Team.first || create(:team) }
|
||||
end
|
||||
end
|
||||
|
|
5
spec/factories/samples_tables.rb
Normal file
5
spec/factories/samples_tables.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :samples_table do
|
||||
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :team do
|
||||
association :created_by, factory: :user
|
||||
created_by { User.first || create(:user) }
|
||||
name 'My team'
|
||||
description 'Lorem ipsum dolor sit amet, consectetuer adipiscing eli.'
|
||||
space_taken 1048576
|
||||
|
|
|
@ -2,7 +2,7 @@ FactoryGirl.define do
|
|||
factory :user do
|
||||
full_name 'admin'
|
||||
initials 'AD'
|
||||
email 'admin@scinote.net'
|
||||
email 'admin_test@scinote.net'
|
||||
password 'asdf1243'
|
||||
password_confirmation 'asdf1243'
|
||||
end
|
||||
|
|
|
@ -38,7 +38,11 @@ describe Asset, type: :model do
|
|||
|
||||
describe 'Should be a valid object' do
|
||||
it { should validate_presence_of :file }
|
||||
it { should validate_presence_of :estimated_size }
|
||||
it 'should validate the presence of estimated size' do
|
||||
asset = build :asset, estimated_size: nil
|
||||
expect(asset).to_not be_valid
|
||||
end
|
||||
# should validate_presence_of :estimated_size }
|
||||
it { should validate_inclusion_of(:file_present).in_array([true, false]) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,8 +18,16 @@ describe AssetTextDatum, type: :model do
|
|||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
let(:asset) { create :asset }
|
||||
|
||||
it { should validate_presence_of :data }
|
||||
it { should validate_presence_of :asset }
|
||||
it { should validate_uniqueness_of :asset }
|
||||
|
||||
it 'should have uniq asset' do
|
||||
create :asset_text_datum, asset: asset
|
||||
new_atd = build :asset_text_datum, asset: asset
|
||||
# binding.pry
|
||||
expect(new_atd).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,14 +24,39 @@ describe CustomField, type: :model do
|
|||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
|
||||
before do
|
||||
@user = create :user, email: 'example_one@adsf.com'
|
||||
@team = create :team
|
||||
@samples_table = create :samples_table, user: @user, team: @team
|
||||
end
|
||||
|
||||
it { should validate_presence_of :name }
|
||||
it { should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH) }
|
||||
it { should validate_uniqueness_of(:name).scoped_to(:team) }
|
||||
it { should validate_presence_of :user }
|
||||
|
||||
it do
|
||||
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
|
||||
end
|
||||
|
||||
it do
|
||||
should validate_exclusion_of(:name).in_array(
|
||||
%w(Assigned Sample name Sample type Sample group Added on Added by)
|
||||
['Assigned', 'Sample name', 'Sample type',
|
||||
'Sample group', 'Added on', 'Added by']
|
||||
)
|
||||
end
|
||||
it { should validate_presence_of :user }
|
||||
|
||||
it 'should have uniq name scoped on team' do
|
||||
create :custom_field, user: @user, team: @team
|
||||
custom_field_two = build :custom_field, user: @user, team: @team
|
||||
|
||||
expect(custom_field_two).to_not be_valid
|
||||
end
|
||||
|
||||
it 'should have uniq case sensitive name' do
|
||||
build_stubbed :custom_field, name: 'custom one', user: @user, team: @team
|
||||
cf = build :custom_field, name: 'CUSTOM ONE', user: @user, team: @team
|
||||
|
||||
expect(cf).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,6 +38,7 @@ describe Experiment, type: :model do
|
|||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
let(:project) { create :project }
|
||||
it { should validate_presence_of :project }
|
||||
it { should validate_presence_of :created_by }
|
||||
it { should validate_presence_of :last_modified_by }
|
||||
|
@ -46,13 +47,25 @@ describe Experiment, type: :model do
|
|||
.is_at_least(Constants::NAME_MIN_LENGTH)
|
||||
.is_at_most(Constants::NAME_MAX_LENGTH)
|
||||
end
|
||||
it do
|
||||
should validate_uniqueness_of(:name).scoped_to(:project).case_insensitive
|
||||
end
|
||||
# it do
|
||||
# should validate_uniqueness_of(:name).scoped_to(:project).case_insensitive
|
||||
# end
|
||||
it do
|
||||
should validate_length_of(:description)
|
||||
.is_at_most(Constants::TEXT_MAX_LENGTH)
|
||||
end
|
||||
|
||||
it 'should have uniq name scoped on project' do
|
||||
create :experiment, name: 'experiment',
|
||||
project: project,
|
||||
created_by: project.created_by,
|
||||
last_modified_by: project.created_by
|
||||
new_exp = build_stubbed :experiment, name: 'experiment',
|
||||
project: project,
|
||||
created_by: project.created_by,
|
||||
last_modified_by: project.created_by
|
||||
expect(new_exp).to_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,6 +23,5 @@ describe MyModuleRepositoryRow, type: :model do
|
|||
describe 'Should be a valid object' do
|
||||
it { should validate_presence_of :repository_row }
|
||||
it { should validate_presence_of :my_module }
|
||||
it { should validate_uniqueness_of(:repository_row).scoped_to(:my_module) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,21 +56,18 @@ describe MyModule, type: :model do
|
|||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
it { should validate_presence_of :name }
|
||||
it { should validate_presence_of :x }
|
||||
it { should validate_presence_of :y }
|
||||
it { should validate_presence_of :workflow_order }
|
||||
it { should validate_presence_of :experiment }
|
||||
it { should validate_presence_of :my_module_group }
|
||||
it do
|
||||
should validate_length_of(:name)
|
||||
.is_at_least(Constants::NAME_MIN_LENGTH)
|
||||
.is_at_most(Constants::NAME_MAX_LENGTH)
|
||||
.is_at_least(Constants::NAME_MIN_LENGTH)
|
||||
.is_at_most(Constants::NAME_MAX_LENGTH)
|
||||
end
|
||||
it do
|
||||
should validate_length_of(:description)
|
||||
.is_at_most(Constants::TEXT_MAX_LENGTH)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Report, type: :model do
|
||||
|
||||
it 'should be of class Report' do
|
||||
expect(subject.class).to eq Report
|
||||
end
|
||||
|
@ -34,10 +35,11 @@ describe Report, type: :model do
|
|||
.is_at_least(Constants::NAME_MIN_LENGTH)
|
||||
.is_at_most(Constants::NAME_MAX_LENGTH)
|
||||
end
|
||||
it do
|
||||
should validate_uniqueness_of(:name)
|
||||
.scoped_to([:user, :project])
|
||||
.case_insensitive
|
||||
|
||||
it 'should have uniq name scoped to user, project' do
|
||||
create :report, name: 'Same Name'
|
||||
new_rep = build :report, name: 'Same Name'
|
||||
expect(new_rep).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,12 +18,4 @@ describe RepositoryCell, type: :model do
|
|||
it { should belong_to :repository_row }
|
||||
it { should belong_to :repository_column }
|
||||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
it { should validate_presence_of :repository_column }
|
||||
it do
|
||||
should validate_uniqueness_of(:repository_row)
|
||||
.scoped_to(:repository_column)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,9 +29,11 @@ describe RepositoryColumn, type: :model do
|
|||
it do
|
||||
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
|
||||
end
|
||||
it do
|
||||
should validate_uniqueness_of(:name)
|
||||
.scoped_to(:repository)
|
||||
it 'have uniq name scoped to repository' do
|
||||
create :repository_column, name: 'Repo One'
|
||||
column_two = build :repository_column, name: 'Repo One'
|
||||
|
||||
expect(column_two).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,6 @@ describe Repository, type: :model do
|
|||
describe 'Relations' do
|
||||
it { should belong_to :team }
|
||||
it { should belong_to(:created_by).class_name('User') }
|
||||
it { should have_many :repository_columns }
|
||||
it { should have_many :repository_rows }
|
||||
it { should have_many :repository_table_states }
|
||||
it { should have_many :report_elements }
|
||||
|
@ -28,8 +27,17 @@ describe Repository, type: :model do
|
|||
it do
|
||||
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
|
||||
end
|
||||
it do
|
||||
should validate_uniqueness_of(:name).scoped_to(:team).case_insensitive
|
||||
|
||||
it 'should have uniq name scoped to team' do
|
||||
create :repository, name: 'Repository One'
|
||||
repo = build :repository, name: 'Repository One'
|
||||
expect(repo).to_not be_valid
|
||||
end
|
||||
|
||||
it 'should have uniq name scoped to team calse insensitive' do
|
||||
create :repository, name: 'Repository One'
|
||||
repo = build :repository, name: 'REPOSITORY ONE'
|
||||
expect(repo).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,8 +32,11 @@ describe SampleGroup, type: :model do
|
|||
it do
|
||||
should validate_length_of(:color).is_at_most(Constants::COLOR_MAX_LENGTH)
|
||||
end
|
||||
it do
|
||||
should validate_uniqueness_of(:name).scoped_to(:team)
|
||||
it 'should have uniq name scoped to team' do
|
||||
create :sample_group, name: 'My Group'
|
||||
new_group = build :sample_group, name: 'My Group'
|
||||
|
||||
expect(new_group).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,13 @@ describe SampleMyModule, type: :model do
|
|||
describe 'Should be a valid object' do
|
||||
it { should validate_presence_of :sample }
|
||||
it { should validate_presence_of :my_module }
|
||||
it { should validate_uniqueness_of(:sample_id).scoped_to(:my_module_id) }
|
||||
|
||||
it 'should have one sample assigned per model' do
|
||||
sample = create :sample
|
||||
my_module = create :my_module, name: 'Module one'
|
||||
create :sample_my_module, sample: sample, my_module: my_module
|
||||
new_smm = build :sample_my_module, sample: sample, my_module: my_module
|
||||
expect(new_smm).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,6 @@ describe SampleType, type: :model do
|
|||
|
||||
describe 'Should be a valid object' do
|
||||
let(:team) { create :team }
|
||||
let!(:test_type) { create :sample_type, name: 'Sample one', team: team }
|
||||
|
||||
it { should validate_presence_of :name }
|
||||
it { should validate_presence_of :team }
|
||||
|
@ -32,13 +31,15 @@ describe SampleType, type: :model do
|
|||
end
|
||||
|
||||
it 'should have uniq name scoped to team' do
|
||||
create :sample_type, name: 'Sample one', team: team
|
||||
new_type = build :sample_type, name: 'Sample one', team: team
|
||||
expect(new_type).to_not be_valid
|
||||
end
|
||||
|
||||
it 'should not be case sensitive' do
|
||||
new_type = build :sample_type, name: 'SAMPLE ONE', team: team
|
||||
expect(new_type).to be_valid
|
||||
create :sample_type, name: 'Sample T', team: team
|
||||
new_type = build :sample_type, name: 'SAMPLE T', team: team
|
||||
expect(new_type).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue