DEV: stop logging warning when overriding open scope

DEV: stop logging warning when overriding open scope

ActiveRecord defines automatic scopes for enums, the Poll model defines
an enum for {open: 1} this mean Rails wants the scope Poll.all.open
to work which in turn means it has to override open which is defined
privately.

Rails feature req exists for: Add option to disable scopes in `ActiveRecord.enum` · Issue #34599 · rails/rails · GitHub
which will allow us to define enums without scopes which would resolve this
a lot more cleaner.

From 12f5889c85a186daa09487d047f165787968505a Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Mon, 3 Dec 2018 13:52:09 +1100
Subject: [PATCH] DEV: stop logging warning when overriding open scope

ActiveRecord defines automatic scopes for enums, the Poll model defines
an enum for `{open: 1}` this mean Rails wants the scope `Poll.all.open`
to work which in turn means it has to override `open` which is defined
privately.

Rails feature req exists for: https://github.com/rails/rails/issues/34599
which will allow us to define enums without scopes which would resolve this
a lot more cleaner.

diff --git a/config/initializers/100-logster.rb b/config/initializers/100-logster.rb
index 833e1c6..6e607da 100644
--- a/config/initializers/100-logster.rb
+++ b/config/initializers/100-logster.rb
@@ -50,7 +50,15 @@ if Rails.env.production?
 
     # we handle this cleanly in the message bus middleware
     # no point logging to logster
-    /RateLimiter::LimitExceeded.*/m
+    /RateLimiter::LimitExceeded.*/m,
+
+    # see https://github.com/rails/rails/issues/34599
+    # Poll defines an enum with the value `open` ActiveRecord then attempts
+    # AR then warns cause #open is being redefined, it is already defined
+    # privately in Kernel per: http://ruby-doc.org/core-2.5.3/Kernel.html#method-i-open
+    # Once the rails issue is fixed we can stop this error suppression and stop defining
+    # scopes for the enums
+    /^Creating scope :open\. Overwriting existing method Poll\.open\./,
   ]
 end

GitHub

1 Like