From 78268ca767a0a18c1de728a8295946243afbd0f4 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Thu, 12 Sep 2024 10:34:38 +1000 Subject: [PATCH] DEV: Fix another report flaky (#28868) Followup 0323b366f3023843468d1024135bbb1c7c6f0483 This was happening because another spec was adding a report using the plugin API, but there was nothing resetting that, so later in the reports controller when we did Report.singleton_methods, we ended up with another report with no translation, causing another error. --- app/models/report.rb | 5 +++++ spec/lib/plugin/instance_spec.rb | 2 ++ 2 files changed, 7 insertions(+) diff --git a/app/models/report.rb b/app/models/report.rb index 970b47c68de..03765b52b98 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -224,6 +224,11 @@ class Report singleton_class.instance_eval { define_method("report_#{name}", &block) } end + # Only used for testing. + def Report.remove_report(name) + singleton_class.instance_eval { remove_method("report_#{name}") } + end + def self._get(type, opts = nil) opts ||= {} diff --git a/spec/lib/plugin/instance_spec.rb b/spec/lib/plugin/instance_spec.rb index 12179700de2..f294cb285bc 100644 --- a/spec/lib/plugin/instance_spec.rb +++ b/spec/lib/plugin/instance_spec.rb @@ -358,6 +358,8 @@ TEXT end describe "#add_report" do + after { Report.remove_report("readers") } + it "adds a report" do plugin = Plugin::Instance.new nil, "/tmp/test.rb" plugin.add_report("readers") {}