From 85234f215eb3578ef4fee03722e07eac296b5163 Mon Sep 17 00:00:00 2001 From: Anna Headley Date: Tue, 13 Mar 2018 11:13:23 -0400 Subject: [PATCH] Handle nil value for fixity_last_success_date in fixity dashboard fixes #897 --- app/helpers/fixity_dashboard_helper.rb | 6 ++++++ app/views/fixity_dashboard/_fixity_table.html.erb | 2 +- spec/helpers/fixity_dashboard_helper_spec.rb | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 app/helpers/fixity_dashboard_helper.rb create mode 100644 spec/helpers/fixity_dashboard_helper_spec.rb diff --git a/app/helpers/fixity_dashboard_helper.rb b/app/helpers/fixity_dashboard_helper.rb new file mode 100644 index 0000000000..32190b4914 --- /dev/null +++ b/app/helpers/fixity_dashboard_helper.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true +module FixityDashboardHelper + def format_fixity_success_date(date) + date.nil? ? 'in progress' : date.strftime("%m/%d/%y %I:%M:%S %p %Z") + end +end diff --git a/app/views/fixity_dashboard/_fixity_table.html.erb b/app/views/fixity_dashboard/_fixity_table.html.erb index f995d0dc17..0372a4c333 100644 --- a/app/views/fixity_dashboard/_fixity_table.html.erb +++ b/app/views/fixity_dashboard/_fixity_table.html.erb @@ -15,7 +15,7 @@ <%= link_to resource.parent.title.first, Valhalla::ContextualPath.new(child: resource.parent).show %> <%= resource.original_file.fixity_success == 0 ? "failed" : "succeeded" %> <%= resource.updated_at %> - <%= resource.original_file.fixity_last_success_date.strftime("%m/%d/%y %I:%M:%S %p %Z") %> + <%= format_fixity_success_date(resource.original_file.fixity_last_success_date) %> <% end %> diff --git a/spec/helpers/fixity_dashboard_helper_spec.rb b/spec/helpers/fixity_dashboard_helper_spec.rb new file mode 100644 index 0000000000..474e778406 --- /dev/null +++ b/spec/helpers/fixity_dashboard_helper_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +require 'rails_helper' + +RSpec.describe FixityDashboardHelper do + describe '#format_fixity_success_date' do + it 'formats the date as expected' do + expect(helper.format_fixity_success_date(nil)).to eq 'in progress' + time = Time.current + expect(helper.format_fixity_success_date(time)).to eq time.strftime("%m/%d/%y %I:%M:%S %p %Z") + end + end +end