Skip to content

Commit

Permalink
fix sample tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Dec 12, 2024
1 parent 9ffde4c commit 4d1cb80
Showing 1 changed file with 39 additions and 41 deletions.
80 changes: 39 additions & 41 deletions test/unit/sample_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class SampleTest < ActiveSupport::TestCase
test 'handling booleans' do
sample = Sample.new title: 'testing', project_ids: [FactoryBot.create(:project).id]
sample_type = FactoryBot.create(:simple_sample_type)
sample_type.sample_attributes << FactoryBot.create(:sample_attribute, title: 'bool', sample_attribute_type: FactoryBot.create(:boolean_sample_attribute_type), required: false, is_title: false, sample_type: sample_type)
FactoryBot.create(:sample_attribute, title: 'bool', sample_attribute_type: FactoryBot.create(:boolean_sample_attribute_type), required: false, is_title: false, sample_type: sample_type)
sample_type.save!
sample.sample_type = sample_type

Expand Down Expand Up @@ -275,7 +275,7 @@ class SampleTest < ActiveSupport::TestCase
# with required attribute
sample = Sample.new title: 'testing', project_ids: [FactoryBot.create(:project).id]
sample_type = FactoryBot.create(:simple_sample_type)
sample_type.sample_attributes << FactoryBot.create(:sample_attribute, title: 'bool', sample_attribute_type: FactoryBot.create(:boolean_sample_attribute_type), required: true, is_title: false, sample_type: sample_type)
FactoryBot.create(:sample_attribute, title: 'bool', sample_attribute_type: FactoryBot.create(:boolean_sample_attribute_type), required: true, is_title: false, sample_type: sample_type)
sample_type.save!
sample.sample_type = sample_type

Expand Down Expand Up @@ -310,8 +310,8 @@ class SampleTest < ActiveSupport::TestCase
test 'json metadata with awkward attributes' do
person = FactoryBot.create(:person)
sample_type = SampleType.new title: 'with awkward attributes', projects: person.projects, contributor: person
sample_type.sample_attributes << FactoryBot.create(:any_string_sample_attribute, title: 'title', is_title: true, sample_type: sample_type)
sample_type.sample_attributes << FactoryBot.create(:any_string_sample_attribute, title: 'updated_at', is_title: false, sample_type: sample_type)
FactoryBot.create(:any_string_sample_attribute, title: 'title', is_title: true, sample_type: sample_type)
FactoryBot.create(:any_string_sample_attribute, title: 'updated_at', is_title: false, sample_type: sample_type)
assert sample_type.valid?
sample = Sample.new title: 'testing', project_ids: [FactoryBot.create(:project).id]
sample.sample_type = sample_type
Expand Down Expand Up @@ -436,8 +436,8 @@ class SampleTest < ActiveSupport::TestCase
test 'sample with clashing attribute names' do
person = FactoryBot.create(:person)
sample_type = SampleType.new title: 'with awkward attributes', projects: person.projects, contributor: person
sample_type.sample_attributes << FactoryBot.create(:any_string_sample_attribute, title: 'freeze', is_title: true, sample_type: sample_type)
sample_type.sample_attributes << FactoryBot.create(:any_string_sample_attribute, title: 'updated_at', is_title: false, sample_type: sample_type)
FactoryBot.create(:any_string_sample_attribute, title: 'freeze', is_title: true, sample_type: sample_type)
FactoryBot.create(:any_string_sample_attribute, title: 'updated_at', is_title: false, sample_type: sample_type)
assert sample_type.valid?
sample_type.save!
sample = Sample.new title: 'testing', project_ids: [FactoryBot.create(:project).id]
Expand All @@ -458,7 +458,7 @@ class SampleTest < ActiveSupport::TestCase
test 'sample with clashing attribute names with private methods' do
person = FactoryBot.create(:person)
sample_type = SampleType.new title: 'with awkward attributes', projects: person.projects, contributor: person
sample_type.sample_attributes << FactoryBot.build(:any_string_sample_attribute, title: 'format', is_title: true, sample_type: sample_type)
FactoryBot.build(:any_string_sample_attribute, title: 'format', is_title: true, sample_type: sample_type)
assert sample_type.valid?
disable_authorization_checks { sample_type.save! }
sample = Sample.new title: 'testing', project_ids: [FactoryBot.create(:project).id]
Expand All @@ -477,7 +477,7 @@ class SampleTest < ActiveSupport::TestCase
test 'sample with clashing attribute names with dynamic rails methods' do
person = FactoryBot.create(:person)
sample_type = SampleType.new title: 'with awkward attributes', projects: person.projects, contributor: person
sample_type.sample_attributes << FactoryBot.create(:any_string_sample_attribute, title: 'title_before_last_save', is_title: true, sample_type: sample_type)
FactoryBot.create(:any_string_sample_attribute, title: 'title_before_last_save', is_title: true, sample_type: sample_type)
assert sample_type.valid?
disable_authorization_checks { sample_type.save! }
sample = Sample.new title: 'testing', project_ids: [FactoryBot.create(:project).id]
Expand Down Expand Up @@ -584,12 +584,12 @@ class SampleTest < ActiveSupport::TestCase

test 'strain attributes can appear as related items' do
sample_type = FactoryBot.create(:strain_sample_type)
sample_type.sample_attributes << FactoryBot.build(:sample_attribute, title: 'seekstrain2',
sample_attribute_type: FactoryBot.create(:strain_sample_attribute_type),
required: true, sample_type: sample_type)
sample_type.sample_attributes << FactoryBot.build(:sample_attribute, title: 'seekstrain3',
sample_attribute_type: FactoryBot.create(:strain_sample_attribute_type),
required: true, sample_type: sample_type)
FactoryBot.build(:sample_attribute, title: 'seekstrain2',
sample_attribute_type: FactoryBot.create(:strain_sample_attribute_type),
required: true, sample_type: sample_type)
FactoryBot.build(:sample_attribute, title: 'seekstrain3',
sample_attribute_type: FactoryBot.create(:strain_sample_attribute_type),
required: true, sample_type: sample_type)
strain = FactoryBot.create(:strain)
strain2 = FactoryBot.create(:strain)

Expand Down Expand Up @@ -669,12 +669,11 @@ class SampleTest < ActiveSupport::TestCase
test 'sample responds to correct methods' do
person = FactoryBot.create(:person)
sample_type = SampleType.new(title: 'Custom', projects: person.projects, contributor: person)
attribute1 = FactoryBot.create(:any_string_sample_attribute, title: 'banana_type',
is_title: true, sample_type: sample_type)
attribute2 = FactoryBot.create(:any_string_sample_attribute, title: 'license',
sample_type: sample_type)
sample_type.sample_attributes << attribute1
sample_type.sample_attributes << attribute2
FactoryBot.create(:any_string_sample_attribute, title: 'banana_type',
is_title: true, sample_type: sample_type)
FactoryBot.create(:any_string_sample_attribute, title: 'license',
sample_type: sample_type)

assert sample_type.valid?
disable_authorization_checks { sample_type.save! }
sample = Sample.new(title: 'testing', project_ids: [FactoryBot.create(:project).id])
Expand Down Expand Up @@ -985,11 +984,10 @@ class SampleTest < ActiveSupport::TestCase
org5 = FactoryBot.create(:organism, bioportal_concept: nil)

sample_type = FactoryBot.create(:simple_sample_type)
sample_type.sample_attributes << FactoryBot.build(:sample_attribute, title: 'ncbi',
sample_attribute_type: FactoryBot.create(:ncbi_id_sample_attribute_type),
required: false,
sample_type: sample_type)
sample_type.save!
FactoryBot.create(:sample_attribute, title: 'ncbi',
sample_attribute_type: FactoryBot.create(:ncbi_id_sample_attribute_type),
required: false,
sample_type: sample_type)

contributor = FactoryBot.create(:person)
User.with_current_user(contributor.user) do
Expand Down Expand Up @@ -1033,14 +1031,14 @@ class SampleTest < ActiveSupport::TestCase

# shouldn't be duplicates
sample_type = FactoryBot.create(:simple_sample_type)
sample_type.sample_attributes << FactoryBot.build(:sample_attribute, title: 'ncbi',
sample_attribute_type: FactoryBot.create(:ncbi_id_sample_attribute_type),
required: true,
sample_type: sample_type)
sample_type.sample_attributes << FactoryBot.build(:sample_attribute, title: 'ncbi2',
sample_attribute_type: FactoryBot.create(:ncbi_id_sample_attribute_type),
required: true,
sample_type: sample_type)
FactoryBot.create(:sample_attribute, title: 'ncbi',
sample_attribute_type: FactoryBot.create(:ncbi_id_sample_attribute_type),
required: true,
sample_type: sample_type)
FactoryBot.create(:sample_attribute, title: 'ncbi2',
sample_attribute_type: FactoryBot.create(:ncbi_id_sample_attribute_type),
required: true,
sample_type: sample_type)
sample_type.save!
User.with_current_user(contributor.user) do
sample = Sample.new(sample_type: sample_type, project_ids: [contributor.projects.first.id], contributor: contributor)
Expand All @@ -1054,10 +1052,10 @@ class SampleTest < ActiveSupport::TestCase

# handles capitalized attribute name
sample_type = FactoryBot.create(:simple_sample_type)
sample_type.sample_attributes << FactoryBot.build(:sample_attribute, title: 'NcBi',
sample_attribute_type: FactoryBot.create(:ncbi_id_sample_attribute_type),
required: true,
sample_type: sample_type)
FactoryBot.build(:sample_attribute, title: 'NcBi',
sample_attribute_type: FactoryBot.create(:ncbi_id_sample_attribute_type),
required: true,
sample_type: sample_type)
sample_type.save!
User.with_current_user(contributor.user) do
sample = Sample.new(sample_type: sample_type, project_ids: [contributor.projects.first.id], contributor: contributor)
Expand Down Expand Up @@ -1381,8 +1379,8 @@ class SampleTest < ActiveSupport::TestCase
project = FactoryBot.create(:project)
simple_type = FactoryBot.create(:simple_sample_type, project_ids: [project.id])
type_with_df_attr = FactoryBot.create(:data_file_sample_type, project_ids: [project.id])
df_attr = FactoryBot.build(:data_file_sample_attribute, title: 'data file 2', sample_type: type_with_df_attr)
type_with_df_attr.sample_attributes << df_attr
FactoryBot.create(:data_file_sample_attribute, title: 'data file 2', sample_type: type_with_df_attr)

df1 = FactoryBot.create(:data_file)
df2 = FactoryBot.create(:data_file)
df3 = FactoryBot.create(:data_file)
Expand Down Expand Up @@ -1411,8 +1409,8 @@ class SampleTest < ActiveSupport::TestCase
project = FactoryBot.create(:project)

sample_type = FactoryBot.create(:sop_sample_type, project_ids: [project.id])
sop_attr = FactoryBot.build(:sop_sample_attribute, title: 'sop 2', sample_type: sample_type)
sample_type.sample_attributes << sop_attr
FactoryBot.build(:sop_sample_attribute, title: 'sop 2', sample_type: sample_type)

sop1 = FactoryBot.create(:sop)
sop2 = FactoryBot.create(:sop)

Expand Down

0 comments on commit 4d1cb80

Please sign in to comment.