DEV: Fix flaky UploadSecurity spec

DEV: Fix flaky UploadSecurity spec

diff --git a/lib/upload_security.rb b/lib/upload_security.rb
index 0a2acfd..4572473 100644
--- a/lib/upload_security.rb
+++ b/lib/upload_security.rb
@@ -29,6 +29,11 @@ class UploadSecurity
     @@custom_public_types << type if !@@custom_public_types.include?(type)
   end
 
+  # used in tests
+  def self.reset_custom_public_types
+    @@custom_public_types = []
+  end
+
   def initialize(upload, opts = {})
     @upload = upload
     @opts = opts
diff --git a/spec/lib/upload_security_spec.rb b/spec/lib/upload_security_spec.rb
index 2ff1220..d154528 100644
--- a/spec/lib/upload_security_spec.rb
+++ b/spec/lib/upload_security_spec.rb
@@ -74,6 +74,7 @@ RSpec.describe UploadSecurity do
           it "returns false if the custom type has been added" do
             UploadSecurity.register_custom_public_type(type)
             expect(subject.should_be_secure?).to eq(false)
+            UploadSecurity.reset_custom_public_types
           end
         end
         describe "for_theme" do

GitHub sha: c664ba8f

1 Like

@pmusaraj I am not sure we need a public method just to reset these types for the test; I think a UploadSecurity.class_variable_set(:@@custom_public_types, []) would suffice because I can’t think of a situation where we would need to do this in the actual app code.

1 Like

the downside though is that this makes the tests more fragile long term cause we are reaching to internals to fiddle with stuff. I kind of prefer just leaving this as is.

2 Likes

I guess this is fair enough, just seemed like a smell for me to purely add something for a test but reconsidering I can see that it is a worse smell to mess with internals. Sorry @pmusaraj I guess close your new PR then!

3 Likes