Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix-cvs-without-attributes-1659'…
Browse files Browse the repository at this point in the history
… into 1407-add-cm-to-other-resources
  • Loading branch information
whomingbird committed Nov 21, 2023
2 parents af6d6b6 + 6193cef commit 99add07
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/helpers/samples_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ def sample_form_field_for_attribute(attribute, resource)
attribute_form_element(attribute, resource.get_attribute_value(attribute.title), element_name, element_class)
end

def controlled_vocab_form_field(attribute, element_name, values, limit = 1)
def controlled_vocab_form_field(sample_controlled_vocab, element_name, values, allow_new = false, limit = 1)

sample_controlled_vocab = attribute.sample_controlled_vocab
scv_id = sample_controlled_vocab.id
object_struct = Struct.new(:id, :title)
existing_objects = Array(values).collect do |value|
Expand All @@ -33,13 +32,13 @@ def controlled_vocab_form_field(attribute, element_name, values, limit = 1)
objects_input(element_name, existing_objects,
typeahead: typeahead,
limit: limit,
allow_new: attribute.allow_cv_free_text?,
allow_new: allow_new,
class: 'form-control')

end

def controlled_vocab_list_form_field(attribute, element_name, values)
controlled_vocab_form_field(attribute, element_name, values, nil)
def controlled_vocab_list_form_field(sample_controlled_vocab, element_name, values, allow_new)
controlled_vocab_form_field(sample_controlled_vocab, element_name, values, allow_new, nil)
end

def linked_extended_metadata_multi_form_field(attribute, value, element_name, element_class)
Expand Down Expand Up @@ -341,9 +340,9 @@ def attribute_form_element(attribute, value, element_name, element_class, depth=
:title, value.try(:[], 'id'))
select_tag(element_name, options, include_blank: !attribute.required?, class: "form-control #{element_class}")
when Seek::Samples::BaseType::CV
controlled_vocab_form_field attribute, element_name, value
controlled_vocab_form_field attribute.sample_controlled_vocab, element_name, value, attribute.allow_cv_free_text?
when Seek::Samples::BaseType::CV_LIST
controlled_vocab_list_form_field attribute, element_name, value
controlled_vocab_list_form_field attribute.sample_controlled_vocab, element_name, value, attribute.allow_cv_free_text?
when Seek::Samples::BaseType::SEEK_SAMPLE
sample_form_field attribute, element_name, value
when Seek::Samples::BaseType::SEEK_SAMPLE_MULTI
Expand Down
17 changes: 17 additions & 0 deletions test/functional/data_files_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,23 @@ def test_show_item_attributed_to_jerm_file
assert_equal [good_assay],data_file.assays
end

test 'provide metadata with controlled vocabs' do
FactoryBot.create(:data_formats_controlled_vocab)
FactoryBot.create(:data_types_controlled_vocab)
df = FactoryBot.build(:data_file, content_blob:FactoryBot.create(:txt_content_blob))
refute_nil df.content_blob
assay_to_be_created = FactoryBot.build(:assay,title:'new assay')
session[:processed_datafile]=df
session[:processed_assay]=assay_to_be_created

get :provide_metadata

assert_response :success

assert_select 'input+select#data_file_data_type_annotations'
assert_select 'input+select#data_file_data_format_annotations'
end

test 'create assay should be checked with new assay containing title' do
df = FactoryBot.build(:data_file, content_blob:FactoryBot.create(:txt_content_blob))
refute_nil df.content_blob
Expand Down

0 comments on commit 99add07

Please sign in to comment.