From 23423ba112419026dbb4089d177942554295d1c0 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 31 Oct 2018 13:37:54 +1100 Subject: [PATCH] correct spec and error reporting previous commit misused warn_exception which caused a spec to fail --- app/models/report.rb | 6 +++--- lib/discourse_ip_info.rb | 4 ++-- spec/models/report_spec.rb | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/report.rb b/app/models/report.rb index 523e8eea574..d645520fe05 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1283,11 +1283,11 @@ class Report FROM user_auth_token_logs t JOIN users u ON u.id = t.user_id WHERE t.action = 'suspicious' - AND t.created_at >= '#{report.start_date}' - AND t.created_at <= '#{report.end_date}' + AND t.created_at >= :start_date + AND t.created_at <= :end_date SQL - DB.query(sql).each do |row| + DB.query(sql, start_date: report.start_date, end_date: report.end_date).each do |row| data = {} ipinfo = DiscourseIpInfo.get(row.client_ip) diff --git a/lib/discourse_ip_info.rb b/lib/discourse_ip_info.rb index 751b48c8acc..ad6b2a57558 100644 --- a/lib/discourse_ip_info.rb +++ b/lib/discourse_ip_info.rb @@ -42,7 +42,7 @@ class DiscourseIpInfo ret[:location] = [ret[:city], ret[:region], ret[:country]].reject(&:blank?).join(", ") end rescue => e - Discourse.warn_exception(e, "IP #{ip} could not be looked up in MaxMind GeoLite2-City database.") + Discourse.warn_exception(e, message: "IP #{ip} could not be looked up in MaxMind GeoLite2-City database.") end end @@ -55,7 +55,7 @@ class DiscourseIpInfo ret[:organization] = result["autonomous_system_organization"] end rescue => e - Discourse.warn_exception(e, "IP #{ip} could not be looked up in MaxMind GeoLite2-ASN database.") + Discourse.warn_exception(e, message: "IP #{ip} could not be looked up in MaxMind GeoLite2-ASN database.") end end diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index a5f033b54b9..6a14a38d4d2 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -980,6 +980,9 @@ describe Report do context "with data" do it "works" do + SiteSetting.verbose_auth_token_logging = true + freeze_time DateTime.parse('2017-03-01 12:00') + UserAuthToken.log(action: "suspicious", user_id: robin.id) UserAuthToken.log(action: "suspicious", user_id: joffrey.id) UserAuthToken.log(action: "suspicious", user_id: joffrey.id)