Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field definitions for 'files' and 'visibility' to the field guide #35

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions app/lib/zizia/metadata_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@ class MetadataDetails

def details(work_attributes:)
validators = work_attributes.validators
work_attributes.properties.sort.map do |p|
Hash[
attribute: p[0],
predicate: p[1].predicate.to_s,
multiple: p[1].try(:multiple?).to_s,
type: type_to_s(p[1].type),
validator: validator_to_string(validator: validators[p[0].to_sym][0]),
label: I18n.t("simple_form.labels.defaults.#{p[0]}"),
csv_header: csv_header(p[0]),
required_on_form: required_on_form_to_s(p[0]),
usage: MetadataUsage.instance.usage[p[0]]
]
end
detail_list = work_attributes.properties.sort.map { |p| definition_hash_for(p, validators) }
detail_list << visibility_definition
detail_list << file_definition
end

def to_csv(work_attributes:)
Expand Down Expand Up @@ -64,5 +54,47 @@ def validator_to_string(validator:)
'No validation present in the model.'
end
end

def definition_hash_for(field_properties, validators)
Hash[
attribute: field_properties[0],
predicate: field_properties[1].predicate.to_s,
multiple: field_properties[1].try(:multiple?).to_s,
type: type_to_s(field_properties[1].type),
validator: validator_to_string(validator: validators[field_properties[0].to_sym][0]),
label: I18n.t("simple_form.labels.defaults.#{field_properties[0]}"),
csv_header: csv_header(field_properties[0]),
required_on_form: required_on_form_to_s(field_properties[0]),
usage: MetadataUsage.instance.usage[field_properties[0]]
]
end

def file_definition
{
attribute: 'files',
predicate: 'n/a',
multiple: 'true',
type: 'String',
validator: 'Required, must name a file on the server',
label: 'Items (listed at bottom of page)',
csv_header: 'files',
required_on_form: 'true',
usage: MetadataUsage.instance.usage['files']
}
end

def visibility_definition
{
attribute: 'visibility',
predicate: 'n/a',
multiple: 'false',
type: 'String',
validator: 'Required, must exist in the application\'s controlled vocabulary for visiblity levels.',
label: 'Visibility',
csv_header: 'visibility',
required_on_form: 'true',
usage: MetadataUsage.instance.usage['visibility']
}
end
end
end
20 changes: 18 additions & 2 deletions spec/controllers/metadata_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,27 @@
expect(first_row).to include('required_on_form')
end

it 'includes usage' do
it 'includes `usage`' do
get :profile
profile_table = CSV.parse(response.body, headers: :first_row)
title_definition = profile_table.find { |r| r.field('attribute') == 'title' }
expect(title_definition.field('usage')).to include 'name of the resource being described' # match text extracted from ./config/emory/usage.yml
expect(title_definition.field('usage')).to include 'name of the resource being described' # match text extracted from ./config/zizia/usage.yml
end

it 'includes `files`' do
get :profile
profile_table = CSV.parse(response.body, headers: :first_row)
files_definition = profile_table.find { |r| r.field('attribute') == 'files' }
expect(files_definition.field('csv_header')).to eq('files')
expect(files_definition.field('validator')).to match(/Required/)
end

it 'includes `visibility`' do
get :profile
profile_table = CSV.parse(response.body, headers: :first_row)
visibility_definition = profile_table.find { |r| r.field('attribute') == 'visibility' }
expect(visibility_definition.field('csv_header')).to eq('visibility')
expect(visibility_definition.field('validator')).to match(/Required/)
end

it 'includes a date in the filename' do
Expand Down