From 1065bb146990cce88666af0f0545cdb2354f8151 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 16 May 2023 14:53:22 -0500 Subject: [PATCH 1/6] We needed to change the method to reference a class that exists, ensuring that the class gets required. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Legato dynamically creates methods based on classes/modules that extend it’s model. And depending on the load sequence of classes, these dynamic methods can vary. By adding an explicit require, we ensure that those methods are properly defined on the profile. co-authored-by: jeremy --- app/models/file_download_stat.rb | 30 +++++++++ app/models/hyrax/statistic.rb | 101 +++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 app/models/file_download_stat.rb create mode 100644 app/models/hyrax/statistic.rb diff --git a/app/models/file_download_stat.rb b/app/models/file_download_stat.rb new file mode 100644 index 000000000..4f9201ed5 --- /dev/null +++ b/app/models/file_download_stat.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'hyrax/download' + +class FileDownloadStat < Hyrax::Statistic + self.cache_column = :downloads + self.event_type = :totalEvents + + class << self + # Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download + # see Legato::ProfileMethods.method_name_from_klass + def ga_statistics(start_date, file) + profile = Hyrax::Analytics.profile + unless profile + Hyrax.logger.error("Google Analytics profile has not been established. Unable to fetch statistics.") + return [] + end + profile.hyrax__download(sort: 'date', + start_date: start_date, + end_date: Date.yesterday, + limit: 10_000) + .for_file(file.id) + end + + # this is called by the parent class + def filter(file) + { file_id: file.id } + end + end +end \ No newline at end of file diff --git a/app/models/hyrax/statistic.rb b/app/models/hyrax/statistic.rb new file mode 100644 index 000000000..5a036f336 --- /dev/null +++ b/app/models/hyrax/statistic.rb @@ -0,0 +1,101 @@ +# frozen_string_literal: true + +require 'hyrax/pageview' + +module Hyrax + class Statistic < ActiveRecord::Base + self.abstract_class = true + + class_attribute :cache_column, :event_type + + class << self + include ActionDispatch::Routing::PolymorphicRoutes + include Rails.application.routes.url_helpers + + def statistics_for(object) + where(filter(object)) + end + + def build_for(object, attrs) + new attrs.merge(filter(object)) + end + + def convert_date(date_time) + date_time.to_datetime.to_i * 1000 + end + + def statistics(object, start_date, user_id = nil) + combined_stats object, start_date, cache_column, event_type, user_id + end + + # Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download + # see Legato::ProfileMethods.method_name_from_klass + def ga_statistics(start_date, object) + path = polymorphic_path(object) + profile = Hyrax::Analytics.profile + unless profile + Rails.logger.error("Google Analytics profile has not been established. Unable to fetch statistics.") + return [] + end + profile.hyrax__pageview(sort: 'date', + start_date: start_date, + end_date: Date.yesterday, + limit: 10_000) + .for_path(path) + end + + def query_works(query) + models = Hyrax.config.curation_concerns.map { |m| "\"#{m}\"" } + ActiveFedora::SolrService.query("has_model_ssim:(#{models.join(' OR ')})", fl: query, rows: 100_000) + end + + def work_types + results = query_works("human_readable_type_tesim") + results.group_by { |result| result['human_readable_type_tesim'].join('') }.transform_values(&:count) + end + + def resource_types + results = query_works("resource_type_tesim") + resource_types = [] + results.each do |y| + if y["resource_type_tesim"].nil? || (y["resource_type_tesim"] == [""]) + resource_types.push("Unknown") + elsif y["resource_type_tesim"].count > 1 + y["resource_type_tesim"].each do |t| + resource_types.push(t) + end + else + resource_types.push(y["resource_type_tesim"].join("")) + end + end + resource_types.group_by { |rt| rt }.transform_values(&:count) + end + + private + + def cached_stats(object, start_date, _method) + stats = statistics_for(object).order(date: :asc) + ga_start_date = stats.any? ? stats[stats.size - 1].date + 1.day : start_date.to_date + { ga_start_date: ga_start_date, cached_stats: stats.to_a } + end + + def combined_stats(object, start_date, object_method, ga_key, user_id = nil) + stat_cache_info = cached_stats(object, start_date, object_method) + stats = stat_cache_info[:cached_stats] + if stat_cache_info[:ga_start_date] < Time.zone.today + ga_stats = ga_statistics(stat_cache_info[:ga_start_date], object) + ga_stats.each do |stat| + lstat = build_for(object, date: stat[:date], object_method => stat[ga_key], user_id: user_id) + lstat.save unless Date.parse(stat[:date]) == Time.zone.today + stats << lstat + end + end + stats + end + end + + def to_flot + [self.class.convert_date(date), send(cache_column)] + end + end +end \ No newline at end of file From 1245dac915c4df41586fd02db7e38e16e1bb37c5 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 16 May 2023 15:00:43 -0500 Subject: [PATCH 2/6] update the related pageview and download specs --- app/models/work_view_stat_spec.rb | 108 +++++++++++++++++++++++++ spec/models/file_download_stat_spec.rb | 105 ++++++++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 app/models/work_view_stat_spec.rb create mode 100644 spec/models/file_download_stat_spec.rb diff --git a/app/models/work_view_stat_spec.rb b/app/models/work_view_stat_spec.rb new file mode 100644 index 000000000..1e102c4c0 --- /dev/null +++ b/app/models/work_view_stat_spec.rb @@ -0,0 +1,108 @@ +# frozen_string_literal: true +RSpec.describe WorkViewStat, type: :model do + let(:work_id) { work.id } + let(:user_id) { 123 } + let(:date) { DateTime.new.in_time_zone } + let(:work_stat) { described_class.create(work_views: "25", date: date, work_id: work_id, user_id: user_id) } + let(:work) { mock_model(GenericWork, id: 199) } + + it "has attributes" do + expect(work_stat).to respond_to(:work_views) + expect(work_stat).to respond_to(:date) + expect(work_stat).to respond_to(:work_id) + expect(work_stat.work_id).to eq("199") + expect(work_stat.date).to eq(date) + expect(work_stat.work_views).to eq(25) + expect(work_stat.user_id).to eq(user_id) + end + + describe ".ga_statistic" do + let(:start_date) { 2.days.ago } + let(:expected_path) { Rails.application.routes.url_helpers.hyrax_generic_work_path(work) } + + before do + allow(Hyrax::Analytics).to receive(:profile).and_return(profile) + end + context "when a profile is available" do + let(:views) { double } + let(:profile) { double(hyrax__pageviews: views) } + + it "calls the Legato method with the correct path" do + expect(views).to receive(:for_path).with(expected_path) + described_class.ga_statistics(start_date, work) + end + end + + context "when a profile not available" do + let(:profile) { nil } + + it "calls the Legato method with the correct path" do + expect(described_class.ga_statistics(start_date, work)).to be_empty + end + end + end + + describe "#statistics" do + let(:dates) do + ldates = [] + 4.downto(0) { |idx| ldates << (Time.zone.today - idx.day) } + ldates + end + let(:date_strs) do + dates.map { |date| date.strftime("%Y%m%d") } + end + + let(:view_output) do + [[statistic_date(dates[0]), 4], [statistic_date(dates[1]), 8], [statistic_date(dates[2]), 6], [statistic_date(dates[3]), 10]] + end + + # This is what the data looks like that's returned from Google Analytics (GA) via the Legato gem + # Due to the nature of querying GA, testing this data in an automated fashion is problematc. + # Sample data structures were created by sending real events to GA from a test instance of + # Scholarsphere. The data below are essentially a "cut and paste" from the output of query + # results from the Legato gem. + let(:sample_work_pageview_statistics) do + [ + SpecStatistic.new(date: date_strs[0], pageviews: 4), + SpecStatistic.new(date: date_strs[1], pageviews: 8), + SpecStatistic.new(date: date_strs[2], pageviews: 6), + SpecStatistic.new(date: date_strs[3], pageviews: 10) + ] + end + + describe "cache empty" do + let(:stats) do + expect(described_class).to receive(:ga_statistics).and_return(sample_work_pageview_statistics) + described_class.statistics(work, Time.zone.today - 4.days, user_id) + end + + it "includes cached ga data" do + expect(stats.map(&:to_flot)).to include(*view_output) + end + + it "caches data" do + expect(stats.map(&:to_flot)).to include(*view_output) + expect(stats.first.user_id).to eq user_id + + # at this point all data should be cached + allow(described_class).to receive(:ga_statistics).with(Time.zone.today, work).and_raise("We should not call Google Analytics All data should be cached!") + + stats2 = described_class.statistics(work, Time.zone.today - 5.days) + expect(stats2.map(&:to_flot)).to include(*view_output) + end + end + + describe "cache loaded" do + let!(:work_view_stat) { described_class.create(date: (Time.zone.today - 5.days).to_datetime, work_id: work_id, work_views: "25") } + + let(:stats) do + expect(described_class).to receive(:ga_statistics).and_return(sample_work_pageview_statistics) + described_class.statistics(work, Time.zone.today - 5.days) + end + + it "includes cached data" do + expect(stats.map(&:to_flot)).to include([work_view_stat.date.to_i * 1000, work_view_stat.work_views], *view_output) + end + end + end +end \ No newline at end of file diff --git a/spec/models/file_download_stat_spec.rb b/spec/models/file_download_stat_spec.rb new file mode 100644 index 000000000..ee337c0ce --- /dev/null +++ b/spec/models/file_download_stat_spec.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true +RSpec.describe FileDownloadStat, type: :model do + let(:file_id) { file.id } + let(:date) { Time.current } + let(:file_stat) { described_class.new(downloads: "2", date: date, file_id: file_id) } + let(:file) { mock_model(FileSet, id: 99) } + + it "has attributes" do + expect(file_stat).to respond_to(:downloads) + expect(file_stat).to respond_to(:date) + expect(file_stat).to respond_to(:file_id) + expect(file_stat.file_id).to eq("99") + expect(file_stat.date).to eq(date) + expect(file_stat.downloads).to eq(2) + end + + describe ".ga_statistic" do + let(:start_date) { 2.days.ago } + let(:expected_path) { Rails.application.routes.url_helpers.hyrax_file_set_path(file) } + + before do + allow(Hyrax::Analytics).to receive(:profile).and_return(profile) + end + context "when a profile is available" do + let(:views) { double } + let(:profile) { double(hyrax__download: views) } + + it "calls the Legato method with the correct path" do + expect(views).to receive(:for_file).with(99) + described_class.ga_statistics(start_date, file) + end + end + + context "when a profile not available" do + let(:profile) { nil } + + it "calls the Legato method with the correct path" do + expect(described_class.ga_statistics(start_date, file)).to be_empty + end + end + end + + describe "#statistics" do + let(:dates) do + ldates = [] + 4.downto(0) { |idx| ldates << (Time.zone.today - idx.day) } + ldates + end + let(:date_strs) do + dates.map { |date| date.strftime("%Y%m%d") } + end + + let(:download_output) do + [[statistic_date(dates[0]), 1], [statistic_date(dates[1]), 1], [statistic_date(dates[2]), 2], [statistic_date(dates[3]), 3]] + end + + # This is what the data looks like that's returned from Google Analytics (GA) via the Legato gem + # Due to the nature of querying GA, testing this data in an automated fashion is problematc. + # Sample data structures were created by sending real events to GA from a test instance of + # Scholarsphere. The data below are essentially a "cut and paste" from the output of query + # results from the Legato gem. + let(:sample_download_statistics) do + [ + SpecStatistic.new(eventCategory: "Files", eventAction: "Downloaded", eventLabel: "hyrax:x920fw85p", date: date_strs[0], totalEvents: "1"), + SpecStatistic.new(eventCategory: "Files", eventAction: "Downloaded", eventLabel: "hyrax:x920fw85p", date: date_strs[1], totalEvents: "1"), + SpecStatistic.new(eventCategory: "Files", eventAction: "Downloaded", eventLabel: "hyrax:x920fw85p", date: date_strs[2], totalEvents: "2"), + SpecStatistic.new(eventCategory: "Files", eventAction: "Downloaded", eventLabel: "hyrax:x920fw85p", date: date_strs[3], totalEvents: "3") + ] + end + + describe "cache empty" do + let(:stats) do + expect(described_class).to receive(:ga_statistics).and_return(sample_download_statistics) + described_class.statistics(file, Time.zone.today - 4.days) + end + + it "includes cached ga data" do + expect(stats.map(&:to_flot)).to include(*download_output) + end + + it "caches data" do + expect(stats.map(&:to_flot)).to include(*download_output) + + # at this point all data should be cached + allow(described_class).to receive(:ga_statistics).with(Time.zone.today, file).and_raise("We should not call Google Analytics All data should be cached!") + + stats2 = described_class.statistics(file, Time.zone.today - 4.days) + expect(stats2.map(&:to_flot)).to include(*download_output) + end + end + + describe "cache loaded" do + let!(:file_download_stat) { described_class.create(date: (Time.zone.today - 5.days).to_datetime, file_id: file_id, downloads: "25") } + + let(:stats) do + expect(described_class).to receive(:ga_statistics).and_return(sample_download_statistics) + described_class.statistics(file, Time.zone.today - 5.days) + end + + it "includes cached data" do + expect(stats.map(&:to_flot)).to include([file_download_stat.date.to_i * 1000, file_download_stat.downloads], *download_output) + end + end + end +end \ No newline at end of file From 97fcddf8b069a78dea5edf56f65c8e6ae8f4dbec Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 16 May 2023 15:12:42 -0500 Subject: [PATCH 3/6] use decorator syntax instead. add comments --- app/models/file_download_stat.rb | 30 ------ app/models/file_download_stat_decorator.rb | 25 +++++ app/models/hyrax/statistic.rb | 101 --------------------- app/models/hyrax/statistic_decorator.rb | 28 ++++++ app/models/work_view_stat_spec.rb | 4 + spec/models/file_download_stat_spec.rb | 4 + 6 files changed, 61 insertions(+), 131 deletions(-) delete mode 100644 app/models/file_download_stat.rb create mode 100644 app/models/file_download_stat_decorator.rb delete mode 100644 app/models/hyrax/statistic.rb create mode 100644 app/models/hyrax/statistic_decorator.rb diff --git a/app/models/file_download_stat.rb b/app/models/file_download_stat.rb deleted file mode 100644 index 4f9201ed5..000000000 --- a/app/models/file_download_stat.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -require 'hyrax/download' - -class FileDownloadStat < Hyrax::Statistic - self.cache_column = :downloads - self.event_type = :totalEvents - - class << self - # Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download - # see Legato::ProfileMethods.method_name_from_klass - def ga_statistics(start_date, file) - profile = Hyrax::Analytics.profile - unless profile - Hyrax.logger.error("Google Analytics profile has not been established. Unable to fetch statistics.") - return [] - end - profile.hyrax__download(sort: 'date', - start_date: start_date, - end_date: Date.yesterday, - limit: 10_000) - .for_file(file.id) - end - - # this is called by the parent class - def filter(file) - { file_id: file.id } - end - end -end \ No newline at end of file diff --git a/app/models/file_download_stat_decorator.rb b/app/models/file_download_stat_decorator.rb new file mode 100644 index 000000000..cf43605d2 --- /dev/null +++ b/app/models/file_download_stat_decorator.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# OVERRIDE Hyrax hyrax-v3.5.0 to require Hyrax::Download so the method below doesn't fail + +require 'hyrax/download' + +module FileDownloadStatClass + # Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download + # see Legato::ProfileMethods.method_name_from_klass + def ga_statistics(start_date, file) + profile = Hyrax::Analytics.profile + unless profile + Hyrax.logger.error("Google Analytics profile has not been established. Unable to fetch statistics.") + return [] + end + # OVERRIDE Hyrax hyrax-v3.5.0 + profile.hyrax__download(sort: 'date', + start_date: start_date, + end_date: Date.yesterday, + limit: 10_000) + .for_file(file.id) + end +end + +FileDownloadStat.singleton_class.send(:prepend, FileDownloadStatClass) diff --git a/app/models/hyrax/statistic.rb b/app/models/hyrax/statistic.rb deleted file mode 100644 index 5a036f336..000000000 --- a/app/models/hyrax/statistic.rb +++ /dev/null @@ -1,101 +0,0 @@ -# frozen_string_literal: true - -require 'hyrax/pageview' - -module Hyrax - class Statistic < ActiveRecord::Base - self.abstract_class = true - - class_attribute :cache_column, :event_type - - class << self - include ActionDispatch::Routing::PolymorphicRoutes - include Rails.application.routes.url_helpers - - def statistics_for(object) - where(filter(object)) - end - - def build_for(object, attrs) - new attrs.merge(filter(object)) - end - - def convert_date(date_time) - date_time.to_datetime.to_i * 1000 - end - - def statistics(object, start_date, user_id = nil) - combined_stats object, start_date, cache_column, event_type, user_id - end - - # Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download - # see Legato::ProfileMethods.method_name_from_klass - def ga_statistics(start_date, object) - path = polymorphic_path(object) - profile = Hyrax::Analytics.profile - unless profile - Rails.logger.error("Google Analytics profile has not been established. Unable to fetch statistics.") - return [] - end - profile.hyrax__pageview(sort: 'date', - start_date: start_date, - end_date: Date.yesterday, - limit: 10_000) - .for_path(path) - end - - def query_works(query) - models = Hyrax.config.curation_concerns.map { |m| "\"#{m}\"" } - ActiveFedora::SolrService.query("has_model_ssim:(#{models.join(' OR ')})", fl: query, rows: 100_000) - end - - def work_types - results = query_works("human_readable_type_tesim") - results.group_by { |result| result['human_readable_type_tesim'].join('') }.transform_values(&:count) - end - - def resource_types - results = query_works("resource_type_tesim") - resource_types = [] - results.each do |y| - if y["resource_type_tesim"].nil? || (y["resource_type_tesim"] == [""]) - resource_types.push("Unknown") - elsif y["resource_type_tesim"].count > 1 - y["resource_type_tesim"].each do |t| - resource_types.push(t) - end - else - resource_types.push(y["resource_type_tesim"].join("")) - end - end - resource_types.group_by { |rt| rt }.transform_values(&:count) - end - - private - - def cached_stats(object, start_date, _method) - stats = statistics_for(object).order(date: :asc) - ga_start_date = stats.any? ? stats[stats.size - 1].date + 1.day : start_date.to_date - { ga_start_date: ga_start_date, cached_stats: stats.to_a } - end - - def combined_stats(object, start_date, object_method, ga_key, user_id = nil) - stat_cache_info = cached_stats(object, start_date, object_method) - stats = stat_cache_info[:cached_stats] - if stat_cache_info[:ga_start_date] < Time.zone.today - ga_stats = ga_statistics(stat_cache_info[:ga_start_date], object) - ga_stats.each do |stat| - lstat = build_for(object, date: stat[:date], object_method => stat[ga_key], user_id: user_id) - lstat.save unless Date.parse(stat[:date]) == Time.zone.today - stats << lstat - end - end - stats - end - end - - def to_flot - [self.class.convert_date(date), send(cache_column)] - end - end -end \ No newline at end of file diff --git a/app/models/hyrax/statistic_decorator.rb b/app/models/hyrax/statistic_decorator.rb new file mode 100644 index 000000000..0213c88d4 --- /dev/null +++ b/app/models/hyrax/statistic_decorator.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# OVERRIDE Hyrax hyrax-v3.5.0 to require Hyrax::Pageview so the method below doesn't fail + +require 'hyrax/pageview' + +module Hyrax + module StatisticClassDecorator + # Hyrax::Pageview is sent to Hyrax::Analytics.profile as #hyrax__pageview + # see Legato::ProfileMethods.method_name_from_klass + def ga_statistics(start_date, object) + path = polymorphic_path(object) + profile = Hyrax::Analytics.profile + unless profile + Rails.logger.error("Google Analytics profile has not been established. Unable to fetch statistics.") + return [] + end + # OVERRIDE Hyrax hyrax-v3.5.0 + profile.hyrax__pageview(sort: 'date', + start_date: start_date, + end_date: Date.yesterday, + limit: 10_000) + .for_path(path) + end + end +end + +Hyrax::Statistic.singleton_class.send(:prepend, Hyrax::StatisticClassDecorator) diff --git a/app/models/work_view_stat_spec.rb b/app/models/work_view_stat_spec.rb index 1e102c4c0..919a00f84 100644 --- a/app/models/work_view_stat_spec.rb +++ b/app/models/work_view_stat_spec.rb @@ -1,4 +1,7 @@ # frozen_string_literal: true + +# OVERRIDE Hyrax hyrax-v3.5.0 to reference hyrax__pageviews as listed in app/models/hyrax/statistic_decorator.rb + RSpec.describe WorkViewStat, type: :model do let(:work_id) { work.id } let(:user_id) { 123 } @@ -25,6 +28,7 @@ end context "when a profile is available" do let(:views) { double } + # OVERRIDE Hyrax hyrax-v3.5.0 let(:profile) { double(hyrax__pageviews: views) } it "calls the Legato method with the correct path" do diff --git a/spec/models/file_download_stat_spec.rb b/spec/models/file_download_stat_spec.rb index ee337c0ce..990587af7 100644 --- a/spec/models/file_download_stat_spec.rb +++ b/spec/models/file_download_stat_spec.rb @@ -1,4 +1,7 @@ # frozen_string_literal: true + +# OVERRIDE Hyrax hyrax-v3.5.0 to reference hyrax__pageviews as listed in app/models/file_download_stat_decorator.rb + RSpec.describe FileDownloadStat, type: :model do let(:file_id) { file.id } let(:date) { Time.current } @@ -23,6 +26,7 @@ end context "when a profile is available" do let(:views) { double } + # OVERRIDE Hyrax hyrax-v3.5.0 let(:profile) { double(hyrax__download: views) } it "calls the Legato method with the correct path" do From df968cb55c0bf7c88e4f88d51db0576322da8c9d Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 16 May 2023 15:15:12 -0500 Subject: [PATCH 4/6] rubocop fixes --- app/models/file_download_stat_decorator.rb | 2 +- app/models/hyrax/statistic_decorator.rb | 2 +- app/models/work_view_stat_spec.rb | 4 ++-- spec/models/file_download_stat_spec.rb | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/file_download_stat_decorator.rb b/app/models/file_download_stat_decorator.rb index cf43605d2..f28d5322b 100644 --- a/app/models/file_download_stat_decorator.rb +++ b/app/models/file_download_stat_decorator.rb @@ -18,7 +18,7 @@ def ga_statistics(start_date, file) start_date: start_date, end_date: Date.yesterday, limit: 10_000) - .for_file(file.id) + .for_file(file.id) end end diff --git a/app/models/hyrax/statistic_decorator.rb b/app/models/hyrax/statistic_decorator.rb index 0213c88d4..762ed82e9 100644 --- a/app/models/hyrax/statistic_decorator.rb +++ b/app/models/hyrax/statistic_decorator.rb @@ -20,7 +20,7 @@ def ga_statistics(start_date, object) start_date: start_date, end_date: Date.yesterday, limit: 10_000) - .for_path(path) + .for_path(path) end end end diff --git a/app/models/work_view_stat_spec.rb b/app/models/work_view_stat_spec.rb index 919a00f84..d48904d41 100644 --- a/app/models/work_view_stat_spec.rb +++ b/app/models/work_view_stat_spec.rb @@ -28,7 +28,7 @@ end context "when a profile is available" do let(:views) { double } - # OVERRIDE Hyrax hyrax-v3.5.0 + # OVERRIDE Hyrax hyrax-v3.5.0 let(:profile) { double(hyrax__pageviews: views) } it "calls the Legato method with the correct path" do @@ -109,4 +109,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/models/file_download_stat_spec.rb b/spec/models/file_download_stat_spec.rb index 990587af7..e7d9575b4 100644 --- a/spec/models/file_download_stat_spec.rb +++ b/spec/models/file_download_stat_spec.rb @@ -26,7 +26,7 @@ end context "when a profile is available" do let(:views) { double } - # OVERRIDE Hyrax hyrax-v3.5.0 + # OVERRIDE Hyrax hyrax-v3.5.0 let(:profile) { double(hyrax__download: views) } it "calls the Legato method with the correct path" do @@ -106,4 +106,4 @@ end end end -end \ No newline at end of file +end From ece7ab005b0d09997b0a942ad9606fbaa079b883 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 16 May 2023 17:09:19 -0500 Subject: [PATCH 5/6] directly call the classes instead of requiring the files --- app/models/file_download_stat_decorator.rb | 2 +- app/models/hyrax/statistic_decorator.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/file_download_stat_decorator.rb b/app/models/file_download_stat_decorator.rb index f28d5322b..9dbbb8ace 100644 --- a/app/models/file_download_stat_decorator.rb +++ b/app/models/file_download_stat_decorator.rb @@ -2,7 +2,7 @@ # OVERRIDE Hyrax hyrax-v3.5.0 to require Hyrax::Download so the method below doesn't fail -require 'hyrax/download' +Hyrax::Download module FileDownloadStatClass # Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download diff --git a/app/models/hyrax/statistic_decorator.rb b/app/models/hyrax/statistic_decorator.rb index 762ed82e9..530cc5812 100644 --- a/app/models/hyrax/statistic_decorator.rb +++ b/app/models/hyrax/statistic_decorator.rb @@ -2,7 +2,7 @@ # OVERRIDE Hyrax hyrax-v3.5.0 to require Hyrax::Pageview so the method below doesn't fail -require 'hyrax/pageview' +Hyrax::Pageview module Hyrax module StatisticClassDecorator From 6b7f8a7fe05932d469ab6d98a85f91c0cfb012f0 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 16 May 2023 19:39:33 -0500 Subject: [PATCH 6/6] rubocop fixes --- app/models/file_download_stat_decorator.rb | 2 +- app/models/hyrax/statistic_decorator.rb | 2 +- app/models/work_view_stat_spec.rb | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/file_download_stat_decorator.rb b/app/models/file_download_stat_decorator.rb index 9dbbb8ace..b545d90d2 100644 --- a/app/models/file_download_stat_decorator.rb +++ b/app/models/file_download_stat_decorator.rb @@ -2,7 +2,7 @@ # OVERRIDE Hyrax hyrax-v3.5.0 to require Hyrax::Download so the method below doesn't fail -Hyrax::Download +Hyrax::Download # rubocop:disable Lint/Void module FileDownloadStatClass # Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download diff --git a/app/models/hyrax/statistic_decorator.rb b/app/models/hyrax/statistic_decorator.rb index 530cc5812..547bd6cce 100644 --- a/app/models/hyrax/statistic_decorator.rb +++ b/app/models/hyrax/statistic_decorator.rb @@ -2,7 +2,7 @@ # OVERRIDE Hyrax hyrax-v3.5.0 to require Hyrax::Pageview so the method below doesn't fail -Hyrax::Pageview +Hyrax::Pageview # rubocop:disable Lint/Void module Hyrax module StatisticClassDecorator diff --git a/app/models/work_view_stat_spec.rb b/app/models/work_view_stat_spec.rb index d48904d41..316ea19a6 100644 --- a/app/models/work_view_stat_spec.rb +++ b/app/models/work_view_stat_spec.rb @@ -2,10 +2,11 @@ # OVERRIDE Hyrax hyrax-v3.5.0 to reference hyrax__pageviews as listed in app/models/hyrax/statistic_decorator.rb +# rubocop:disable Metrics/BlockLength RSpec.describe WorkViewStat, type: :model do let(:work_id) { work.id } let(:user_id) { 123 } - let(:date) { DateTime.new.in_time_zone } + let(:date) { Time.new.in_time_zone } let(:work_stat) { described_class.create(work_views: "25", date: date, work_id: work_id, user_id: user_id) } let(:work) { mock_model(GenericWork, id: 199) } @@ -110,3 +111,4 @@ end end end +# rubocop:enable Metrics/BlockLength