From 581d362627d3022fc76f7eaac4a61bc27b0b4b19 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 3 May 2018 17:39:37 +0200 Subject: [PATCH] fix spec --- app/models/report.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/models/report.rb b/app/models/report.rb index 52496a08867..617bde3544d 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -16,7 +16,7 @@ class Report end def self.cache_key(report) - "reports:#{report.type}:#{report.start_date.strftime("%Y%m%d")}:#{report.end_date.strftime("%Y%m%d")}" + "reports:#{report.type}:#{report.start_date.to_date.strftime("%Y%m%d")}:#{report.end_date.to_date.strftime("%Y%m%d")}" end def self.clear_cache @@ -56,8 +56,8 @@ class Report # Load the report report = Report.new(type) - report.start_date = opts[:start_date].to_date if opts[:start_date] - report.end_date = opts[:end_date].to_date if opts[:end_date] + report.start_date = opts[:start_date] if opts[:start_date] + report.end_date = opts[:end_date] if opts[:end_date] report.category_id = opts[:category_id] if opts[:category_id] report.group_id = opts[:group_id] if opts[:group_id] report.async = opts[:async] || false @@ -65,10 +65,12 @@ class Report if respond_to?(report_method) cached_report = Discourse.cache.read(cache_key(report)) - if cached_report - return cached_report - elsif report.async - Jobs.enqueue(:retrieve_report, opts.merge(report_type: type)) + if report.async + if cached_report + return cached_report + else + Jobs.enqueue(:retrieve_report, opts.merge(report_type: type)) + end else send(report_method, report) end @@ -125,6 +127,7 @@ class Report basic_report_about report, User.real, :count_by_signup_date, report.start_date, report.end_date, report.group_id add_counts report, User.real, 'users.created_at' else + report_about report, User.real, :count_by_signup_date end end @@ -245,6 +248,7 @@ class Report def self.basic_report_about(report, subject_class, report_method, *args) report.data = [] + subject_class.send(report_method, *args).each do |date, count| report.data << { x: date, y: count } end