Skip to content

Commit

Permalink
rubocop #1981
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Sep 19, 2024
1 parent d7320b5 commit cf2f06e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
9 changes: 5 additions & 4 deletions lib/seek/fair_data_station/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def update_isa(investigation, datastation_inv, contributor, projects, policy)
datastation_inv.studies.each do |datastation_study|
study = update_or_build_study(datastation_study, contributor, projects, policy, investigation)
datastation_study.observation_units.each do |datastation_observation_unit|
observation_unit = update_or_build_observation_unit(datastation_observation_unit, contributor, projects, policy, study)
observation_unit = update_or_build_observation_unit(datastation_observation_unit, contributor, projects,
policy, study)
datastation_observation_unit.samples.each do |datastation_sample|
sample = update_or_build_sample(datastation_sample, contributor, projects, policy, observation_unit)
datastation_sample.assays.each do |datastation_assay|
Expand Down Expand Up @@ -104,14 +105,14 @@ def build_investigation(datastation_inv, contributor, projects, policy)
investigation
end

def update_entity(seek_entity, datastation_entity, contributor, projects, policy)
def update_entity(seek_entity, datastation_entity, _contributor, _projects, _policy)
attributes = datastation_entity.seek_attributes
seek_entity.assign_attributes(attributes)
update_extended_metadata(seek_entity, datastation_entity)
seek_entity
end

def update_sample(seek_sample, datastation_sample, contributor, projects, policy)
def update_sample(seek_sample, datastation_sample, _contributor, _projects, _policy)
sample_attributes = datastation_sample.seek_attributes
seek_sample.assign_attributes(sample_attributes)
populate_sample(seek_sample, datastation_sample)
Expand Down Expand Up @@ -166,7 +167,7 @@ def update_or_build_assay(datastation_assay, contributor, projects, policy, samp
if assay
update_entity(assay, datastation_assay, contributor, projects, policy)
assay.samples = [sample]
assay.assay_assets.where(asset_type:'DataFile').delete_all
assay.assay_assets.where(asset_type: 'DataFile').delete_all
datastation_assay.datasets.each do |datastation_dataset|
df = build_data_file(contributor, datastation_dataset, projects, policy)
assay.assay_assets.build(asset: df)
Expand Down
86 changes: 45 additions & 41 deletions test/unit/fair_data_station/fair_data_station_writer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,28 @@ class FairDataStationWriterTest < ActiveSupport::TestCase

# on save check, 0 investigation created, 1 study created, 1 obs unit, 1 sample, 1 assay, 3 data file, 3 extended metadata

assert_no_difference("Investigation.count") do
assert_difference("Study.count", 1) do
assert_difference("ObservationUnit.count", 1) do
assert_difference("Sample.count", 1) do
assert_difference("Assay.count", 1) do
assert_difference("DataFile.count", 3) do
assert_difference("ObservationUnitAsset.count", 1) do
assert_difference("AssayAsset.count", 2) do # 1 for new df, the other is for the sample
assert_difference("ExtendedMetadata.count", 3) do
#FIXME: ideally should be zero, but 1 is being created by a save when observation_unit pass to the study.observation_units association
assert_difference("DataFile.count", 1) do
investigation = Seek::FairDataStation::Writer.new.update_isa(investigation, inv, contributor, projects, policy)
end
investigation.save!
end
end
end
end
end
end
end
assert_no_difference('Investigation.count') do
assert_difference('Study.count', 1) do
assert_difference('ObservationUnit.count', 1) do
assert_difference('Sample.count', 1) do
assert_difference('Assay.count', 1) do
assert_difference('DataFile.count', 3) do
assert_difference('ObservationUnitAsset.count', 1) do
assert_difference('AssayAsset.count', 2) do # 1 for new df, the other is for the sample
assert_difference('ExtendedMetadata.count', 3) do
# FIXME: ideally should be zero, but 1 is being created by a save when observation_unit pass to the study.observation_units association
assert_difference('DataFile.count', 1) do
investigation = Seek::FairDataStation::Writer.new.update_isa(investigation, inv, contributor,
projects, policy)
end
investigation.save!
end
end
end
end
end
end
end
end
end

Expand All @@ -276,10 +277,11 @@ class FairDataStationWriterTest < ActiveSupport::TestCase
study = investigation.studies.where(external_identifier: 'seek-test-study-1').first
assert_equal 'manchester test site - changed', study.extended_metadata.get_attribute_value('Experimental site name')
study = investigation.studies.where(external_identifier: 'seek-test-study-2').first
assert_equal 'testing testing testing testing testing testing testing testing testing testing study 2 - changed', study.description
assert_equal 'testing testing testing testing testing testing testing testing testing testing study 2 - changed',
study.description
study = investigation.studies.where(external_identifier: 'seek-test-study-3').first
assert_equal 'test study 3', study.title
assert_equal 'birmingham-test-site',study.extended_metadata.get_attribute_value('Experimental site name')
assert_equal 'birmingham-test-site', study.extended_metadata.get_attribute_value('Experimental site name')

# check:
# seek-test-obs-unit-1 host sex modified
Expand All @@ -293,12 +295,12 @@ class FairDataStationWriterTest < ActiveSupport::TestCase
obs_unit = ObservationUnit.where(external_identifier: 'seek-test-obs-unit-3').first
assert_equal 'test obs unit 3 - changed', obs_unit.title
obs_unit = ObservationUnit.where(external_identifier: 'seek-test-obs-unit-4').first
assert_equal 'testing testing testing testing testing testing testing testing testing testing obs unit 4', obs_unit.description
assert_equal 'testing testing testing testing testing testing testing testing testing testing obs unit 4',
obs_unit.description
assert_equal '1005g', obs_unit.extended_metadata.get_attribute_value('Birth weight')
assert_equal 'seek-test-study-3', obs_unit.study.external_identifier
assert_equal ['test-file-7.csv'], obs_unit.data_files.collect(&:external_identifier)


# check:
# seek-test-sample-1 name changed
# seek-test-sample-2 biosafety changed
Expand All @@ -313,32 +315,33 @@ class FairDataStationWriterTest < ActiveSupport::TestCase
sample = Sample.where(external_identifier: 'seek-test-sample-3').first
assert_equal '123460', sample.get_attribute_value('Organism ncbi id')
sample = Sample.where(external_identifier: 'seek-test-sample-5').first
assert_equal 'testing testing testing testing testing testing testing testing testing testing sample 5 - changed', sample.get_attribute_value('Description')
assert_equal 'testing testing testing testing testing testing testing testing testing testing sample 5 - changed',
sample.get_attribute_value('Description')
sample = Sample.where(external_identifier: 'seek-test-sample-6').first
assert_equal 'seek-test-obs-unit-4', sample.observation_unit.external_identifier
assert_equal 'goat', sample.get_attribute_value('Scientific name')
assert_equal 'test seek sample 6', sample.title


# check:
# seek-test-assay-1 description changed
# seek-test-assay-1 now linked to test-file-6.csv
# seek-test-assay-6 facility changed
# seek-test-assay-7 created, along with new test-file-8.csv data file
assay = Assay.where(external_identifier: 'seek-test-assay-1').first
assert_equal 'testing testing testing testing testing testing testing testing testing testing assay 1 - changed', assay.description
assert_equal 'testing testing testing testing testing testing testing testing testing testing assay 1 - changed',
assay.description
assert_equal ['test-file-6.csv'], assay.data_files.collect(&:external_identifier)
assert_equal ['seek-test-sample-1'], assay.samples.collect(&:external_identifier)
assay = Assay.where(external_identifier: 'seek-test-assay-6').first
assert_equal 'test facility - changed', assay.extended_metadata.get_attribute_value('Facility')
assert_equal ['seek-test-sample-5'], assay.samples.collect(&:external_identifier)
assay = Assay.where(external_identifier: 'seek-test-assay-7').first
assert_equal 'testing testing testing testing testing testing testing testing testing testing assay 7', assay.description
assert_equal 'testing testing testing testing testing testing testing testing testing testing assay 7',
assay.description
assert_equal 'new test facility', assay.extended_metadata.get_attribute_value('Facility')
assert_equal 1, assay.samples.count
assert_equal 'seek-test-sample-6', assay.samples.first.external_identifier
assert_equal ['test-file-8.csv'], assay.data_files.collect(&:external_identifier)

end

test 'update isa with things moving' do
Expand All @@ -350,16 +353,17 @@ class FairDataStationWriterTest < ActiveSupport::TestCase
path = "#{Rails.root}/test/fixtures/files/fairdatastation/seek-fair-data-station-moves-test-case.ttl"
inv = Seek::FairDataStation::Reader.new.parse_graph(path).first

assert_no_difference("Investigation.count") do
assert_no_difference("Study.count") do
assert_no_difference("ObservationUnit.count") do
assert_no_difference("Sample.count") do
assert_no_difference("Assay.count") do
assert_no_difference("DataFile.count") do
assert_no_difference("ObservationUnitAsset.count") do
assert_no_difference("AssayAsset.count") do
assert_no_difference("ExtendedMetadata.count") do
investigation = Seek::FairDataStation::Writer.new.update_isa(investigation, inv, contributor, projects, policy)
assert_no_difference('Investigation.count') do
assert_no_difference('Study.count') do
assert_no_difference('ObservationUnit.count') do
assert_no_difference('Sample.count') do
assert_no_difference('Assay.count') do
assert_no_difference('DataFile.count') do
assert_no_difference('ObservationUnitAsset.count') do
assert_no_difference('AssayAsset.count') do
assert_no_difference('ExtendedMetadata.count') do
investigation = Seek::FairDataStation::Writer.new.update_isa(investigation, inv, contributor,
projects, policy)
investigation.save!
end
end
Expand All @@ -386,7 +390,7 @@ class FairDataStationWriterTest < ActiveSupport::TestCase

sample = Sample.where(external_identifier: 'seek-test-sample-3').first
assert_equal 'seek-test-obs-unit-1', sample.observation_unit.external_identifier
assert_equal ['seek-test-assay-3', 'seek-test-assay-4'], sample.assays.collect(&:external_identifier).sort
assert_equal %w[seek-test-assay-3 seek-test-assay-4], sample.assays.collect(&:external_identifier).sort
sample = Sample.where(external_identifier: 'seek-test-sample-5').first
assert_equal 'seek-test-obs-unit-2', sample.observation_unit.external_identifier
assert_equal ['seek-test-assay-5'], sample.assays.collect(&:external_identifier)
Expand Down

0 comments on commit cf2f06e

Please sign in to comment.