Skip to content

Commit

Permalink
Merge pull request #1665 from ELIXIR-Belgium/replace_fixtures_by_fact…
Browse files Browse the repository at this point in the history
…ories

Replace fixtures by factories
  • Loading branch information
kdp-cloud authored Nov 20, 2023
2 parents 9b55b7a + 265b4fc commit df3195f
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 202 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/single_page/index.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async function exportToExcel(tableName, studyId, assayId, sampleTypeId) {
obj[attr] = val;
}
}
if (!hasHiddenInputs) data.push(obj);
if (!hasHiddenInputs && obj["selected"]) data.push(obj);
}

// Use ajax for POST request with table data in the body
Expand Down
4 changes: 2 additions & 2 deletions app/models/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def resolve_controlled_vocabs_inconsistencies
end

def none_empty_isa_tag
template_attributes.reject { |ta| ta&.title == 'Input' }.map(&:isa_tag_id).none? nil
template_attributes.select { |ta| !ta.title.include?('Input') && ta.isa_tag_id.nil? }.none?
end

def test_tag_occurences
%w[source protocol sample data_file other_material].map do |tag|
tag if template_attributes.reject { |ta| ta&.title == 'Input' }.map(&:isa_tag).compact.map(&:title).count(tag) > 1
tag if template_attributes.reject { |ta| ta.title.include?('Input') }.map(&:isa_tag).compact.map(&:title).count(tag) > 1
end.compact
end

Expand Down
2 changes: 1 addition & 1 deletion lib/isa_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def next_process(samples_hash)

def previous_process(samples_hash)
sample = Sample.find(samples_hash.first[:id])
# hvfjkbdfk

sample_type = sample.linked_samples.first&.sample_type
if (sample_type)
protocol = detect_protocol(sample_type)
Expand Down
57 changes: 57 additions & 0 deletions test/factories/isa_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FactoryBot.define do
# source ISA tag
factory(:source_isa_tag, class: IsaTag) do
title { "source" }
end

# sample ISA tag
factory(:sample_isa_tag, class: IsaTag) do
title { "sample" }
end

# protocol ISA tag
factory(:protocol_isa_tag, class: IsaTag) do
title { "protocol" }
end

# source characteristic ISA tag
factory(:source_characteristic_isa_tag, class: IsaTag) do
title { "source_characteristic" }
end

# sample characteristic ISA tag
factory(:sample_characteristic_isa_tag, class: IsaTag) do
title { "sample_characteristic" }
end

# other material ISA tag
factory(:other_material_isa_tag, class: IsaTag) do
title { "other_material" }
end

# other material characteristic ISA tag
factory(:other_material_characteristic_isa_tag, class: IsaTag) do
title { "other_material_characteristic" }
end

# data file ISA tag
factory(:data_file_isa_tag, class: IsaTag) do
title { "data_file" }
end

# data file comment ISA tag
factory(:data_file_comment_isa_tag, class: IsaTag) do
title { "data_file_comment" }
end

# parameter value ISA tag
factory(:parameter_value_isa_tag, class: IsaTag) do
title { "parameter_value" }
end

# default ISA tag
factory(:default_isa_tag, class: IsaTag) do
title { "default isa-tag" }
end

end
106 changes: 66 additions & 40 deletions test/factories/sample_types.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/factories/template_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
factory(:template_attribute) do
sequence(:title) { |n| "Template attribute #{n}" }
association :template, factory: :template
isa_tag_id { IsaTag.find_by_title('default isa-tag')&.id }
isa_tag_id { FactoryBot.create(:default_isa_tag).id }
end

factory(:apples_controlled_vocab_template_attribute, parent: :template_attribute) do
Expand Down
87 changes: 57 additions & 30 deletions test/factories/templates.rb

Large diffs are not rendered by default.

33 changes: 0 additions & 33 deletions test/fixtures/isa_tags.yml

This file was deleted.

50 changes: 0 additions & 50 deletions test/fixtures/templates.yml

This file was deleted.

16 changes: 9 additions & 7 deletions test/functional/assays_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
sample_collection_st = FactoryBot.create(:isa_sample_collection_sample_type, contributor: person, projects: [project],
linked_sample_type: source_st)

assay_sample_type = FactoryBot.create :isa_assay_sample_type, linked_sample_type: sample_collection_st, contributor: person, isa_template: Template.find_by_title('ISA Assay 1')
assay_sample_type = FactoryBot.create :isa_assay_material_sample_type, linked_sample_type: sample_collection_st, contributor: person, isa_template: FactoryBot.build(:isa_assay_material_template)
assay = FactoryBot.create(:assay,
policy:FactoryBot.create(:private_policy, permissions:[FactoryBot.create(:permission,contributor: person, access_type:Policy::EDITING)]),
sample_type: assay_sample_type,
Expand All @@ -1953,14 +1953,16 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
sample_collection_st = FactoryBot.create(:isa_sample_collection_sample_type, contributor: person, projects: [project],
linked_sample_type: source_st)

assay_st1 = FactoryBot.create(:isa_assay_sample_type, contributor: person, projects: [project],
linked_sample_type: sample_collection_st, isa_template: Template.find_by_title('ISA Assay 1'))

assay_st2 = FactoryBot.create(:isa_assay_sample_type, contributor: person, projects: [project],
linked_sample_type: assay_st1, isa_template: Template.find_by_title('ISA Assay 1'))
assay_template_1 = FactoryBot.create(:isa_assay_material_template)
assay_st1 = FactoryBot.create(:isa_assay_material_sample_type, contributor: person, projects: [project],
linked_sample_type: sample_collection_st, isa_template: assay_template_1)

assay_st3 = FactoryBot.create(:isa_assay_sample_type, contributor: person, projects: [project],
linked_sample_type: assay_st2, isa_template: Template.find_by_title('ISA Assay 1'))
assay_st2 = FactoryBot.create(:isa_assay_material_sample_type, contributor: person, projects: [project],
linked_sample_type: assay_st1, isa_template: assay_template_1)

assay_st3 = FactoryBot.create(:isa_assay_material_sample_type, contributor: person, projects: [project],
linked_sample_type: assay_st2, isa_template: assay_template_1)

study = FactoryBot.create(:study, investigation:, contributor: person,
policy: FactoryBot.create(:private_policy, permissions: [FactoryBot.create(:permission, contributor: person, access_type: Policy::MANAGING)]),
Expand Down
18 changes: 9 additions & 9 deletions test/functional/isa_assays_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ def setup
'0' => {
pos: '1', title: 'a string', required: '1', is_title: '1',
sample_attribute_type_id: FactoryBot.create(:string_sample_attribute_type).id, _destroy: '0',
isa_tag_id: IsaTag.find_by_title(Seek::ISA::TagType::OTHER_MATERIAL).id
isa_tag_id: FactoryBot.create(:other_material_isa_tag).id
},
'1' => {
pos: '2', title: 'protocol', required: '1', is_title: '0',
sample_attribute_type_id: FactoryBot.create(:string_sample_attribute_type).id,
isa_tag_id: IsaTag.find_by_title(Seek::ISA::TagType::PROTOCOL).id, _destroy: '0'
isa_tag_id: FactoryBot.create(:protocol_isa_tag).id, _destroy: '0'
},
'2' => {
pos: '3', title: 'Input', required: '1',
sample_attribute_type_id: FactoryBot.create(:sample_multi_sample_attribute_type).id,
linked_sample_type_id: 'self', _destroy: '0'
},
'3' => {
pos: '4', title: 'Som material characteristic', required: '1',
pos: '4', title: 'Some material characteristic', required: '1',
sample_attribute_type_id: FactoryBot.create(:string_sample_attribute_type).id,
_destroy: '0',
isa_tag_id: IsaTag.find_by_title(Seek::ISA::TagType::OTHER_MATERIAL_CHARACTERISTIC).id
isa_tag_id: FactoryBot.create(:other_material_characteristic_isa_tag).id
}
} } } }
end
Expand Down Expand Up @@ -128,7 +128,7 @@ def setup
source_type = FactoryBot.create(:isa_source_sample_type, contributor: person, projects: [project])
sample_collection_type = FactoryBot.create(:isa_sample_collection_sample_type, contributor: person, projects: [project],
linked_sample_type: source_type)
assay_type = FactoryBot.create(:isa_assay_sample_type, contributor: person, projects: [project],
assay_type = FactoryBot.create(:isa_assay_material_sample_type, contributor: person, projects: [project],
linked_sample_type: sample_collection_type)

study = FactoryBot.create(:study, investigation:, contributor: person,
Expand Down Expand Up @@ -197,23 +197,23 @@ def setup
'0' => {
pos: '1', title: 'a string', required: '1', is_title: '1',
sample_attribute_type_id: FactoryBot.create(:string_sample_attribute_type).id, _destroy: '0',
isa_tag_id: IsaTag.find_by_title(Seek::ISA::TagType::OTHER_MATERIAL).id
isa_tag_id: FactoryBot.create(:other_material_isa_tag).id
},
'1' => {
pos: '2', title: 'protocol', required: '1', is_title: '0',
sample_attribute_type_id: FactoryBot.create(:string_sample_attribute_type).id,
isa_tag_id: IsaTag.find_by_title(Seek::ISA::TagType::PROTOCOL).id, _destroy: '0'
isa_tag_id: FactoryBot.create(:protocol_isa_tag).id, _destroy: '0'
},
'2' => {
pos: '3', title: 'Input', required: '1',
sample_attribute_type_id: FactoryBot.create(:sample_multi_sample_attribute_type).id,
linked_sample_type_id: 'self', _destroy: '0'
},
'3' => {
pos: '4', title: 'Som material characteristic', required: '1',
pos: '4', title: 'Some material characteristic', required: '1',
sample_attribute_type_id: FactoryBot.create(:string_sample_attribute_type).id,
_destroy: '0',
isa_tag_id: IsaTag.find_by_title(Seek::ISA::TagType::OTHER_MATERIAL_CHARACTERISTIC).id
isa_tag_id: FactoryBot.create(:other_material_characteristic_isa_tag).id
}
} } }

Expand Down
Loading

0 comments on commit df3195f

Please sign in to comment.