From 908b0feb1cbfc164973fa1261dd96a0c007acb64 Mon Sep 17 00:00:00 2001 From: Oliver Peate Date: Mon, 5 Oct 2020 10:52:55 +0100 Subject: [PATCH] Add last overall update to Dashboard --- lib/dashboard_stats.rb | 4 ++++ source/dashboard.html.erb | 2 ++ spec/lib/dashboard_stats_spec.rb | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/lib/dashboard_stats.rb b/lib/dashboard_stats.rb index 83d93cb4a..25a87403b 100644 --- a/lib/dashboard_stats.rb +++ b/lib/dashboard_stats.rb @@ -17,6 +17,10 @@ def total_organisations api_catalogue.organisations_apis.count end + def last_updated + by_organisation.max_by(&:last_updated)&.last_updated + end + def by_organisation @_by_organsation ||= calculate_stats_by_organisation end diff --git a/source/dashboard.html.erb b/source/dashboard.html.erb index ab4b7f753..f608df580 100644 --- a/source/dashboard.html.erb +++ b/source/dashboard.html.erb @@ -11,6 +11,7 @@ hide_in_navigation: true Total APIs: Departments Represented: + Last Update: @@ -18,6 +19,7 @@ hide_in_navigation: true <%= dashboard_stats.total_apis %> <%= dashboard_stats.total_organisations %> + <%= dashboard_stats.last_updated %> diff --git a/spec/lib/dashboard_stats_spec.rb b/spec/lib/dashboard_stats_spec.rb index 0fd550f9f..1e405051c 100644 --- a/spec/lib/dashboard_stats_spec.rb +++ b/spec/lib/dashboard_stats_spec.rb @@ -20,6 +20,23 @@ end end + describe "#last_updated" do + let(:apis) do + [ + instance_double(Api, organisation: "A", name: "A1", date_updated: Date.new(2020, 1, 1), date_added: Date.new(2016, 1, 1), provider: nil), + instance_double(Api, organisation: "A", name: "A2", date_updated: Date.new(2019, 1, 1), date_added: Date.new(2016, 1, 1), provider: nil), + instance_double(Api, organisation: "B", name: "B1", date_updated: Date.new(2018, 1, 1), date_added: Date.new(2016, 1, 1), provider: nil), + instance_double(Api, organisation: "C", name: "C1", date_updated: Date.new(2017, 1, 1), date_added: Date.new(2016, 1, 1), provider: nil), + ] + end + + let(:api_catalogue) { ApiCatalogue.new(apis) } + + it "matches the most recently updated API" do + expect(subject.last_updated).to eq Date.new(2020, 1, 1) + end + end + describe "#by_organisation" do it "provides stats per organisation" do nhs_stats = subject.by_organisation.detect do |stats|