Skip to content

Commit

Permalink
Merge pull request #488 from barmintor/issue-487
Browse files Browse the repository at this point in the history
WorkShowPresenter should delegate to solr_doc for date fields fixes fixes #487
  • Loading branch information
jcoyne committed Nov 25, 2015
2 parents d367bdc + 628a619 commit fd92cd9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
5 changes: 3 additions & 2 deletions app/presenters/curation_concerns/work_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def page_title
to: :solr_document

# Metadata Methods
delegate :title, :description, :creator, :contributor, :subject, :publisher, :language,
:embargo_release_date, :lease_expiration_date, :rights, to: :solr_document
delegate :title, :date_created, :date_modified, :date_uploaded, :description,
:creator, :contributor, :subject, :publisher, :language, :embargo_release_date,
:lease_expiration_date, :rights, to: :solr_document

def file_presenters
@file_sets ||= PresenterFactory.build_presenters(ordered_ids,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ def representative_id
fetch(Solrizer.solr_name('hasRelatedMediaFragment', :symbol), []).first
end

def date_created
date_field('date_created')
end

def date_modified
date_field('date_modified')
end

def date_uploaded
field = self[Solrizer.solr_name('date_uploaded', :stored_sortable, type: :date)]
return unless field.present?
begin
Date.parse(field).to_formatted_s(:standard)
rescue
Rails.logger.info "Unable to parse date: #{field.first.inspect} for #{self['id']}"
end
date_field('date_uploaded')
end

def depositor(default = '')
Expand Down Expand Up @@ -128,5 +130,17 @@ def visibility
Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
end
end

private

def date_field(field_name)
field = self[Solrizer.solr_name(field_name, :stored_sortable, type: :date)]
return unless field.present?
begin
Date.parse(field).to_formatted_s(:standard)
rescue
Rails.logger.info "Unable to parse date: #{field.first.inspect} for #{self['id']}"
end
end
end
end
14 changes: 13 additions & 1 deletion spec/presenters/curation_concerns/work_show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

describe CurationConcerns::WorkShowPresenter do
let(:solr_document) { SolrDocument.new(attributes) }
let(:date_value) { Date.today }
let(:date_index) { date_value.to_s }
let(:attributes) do
{ "title_tesim" => ["foo bar"],
"human_readable_type_tesim" => ["Generic Work"],
"has_model_ssim" => ["GenericWork"] }
"has_model_ssim" => ["GenericWork"],
"date_created_dtsi" => date_index,
"date_modified_dtsi" => date_index,
"date_uploaded_dtsi" => date_index }
end

let(:ability) { nil }
Expand All @@ -26,6 +31,13 @@
it { is_expected.to be_kind_of ActiveModel::Name }
end

[:date_created, :date_modified, :date_uploaded].each do |date_field|
describe "##{date_field}" do
subject { presenter.send date_field }
it { is_expected.to eq date_value.to_formatted_s(:standard) }
end
end

describe "#permission_badge" do
it "calls the PermissionBadge object" do
expect_any_instance_of(CurationConcerns::PermissionBadge).to receive(:render)
Expand Down

0 comments on commit fd92cd9

Please sign in to comment.