Skip to content

Commit

Permalink
Guard prosopite behind an ENV variable
Browse files Browse the repository at this point in the history
Defaults to on in dev but off in test unless you set the variable
  • Loading branch information
fiveNinePlusR committed Oct 15, 2024
1 parent f74b461 commit 3e24517
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ MAPBOX_DEV_API_KEY=
PMTILES_GLYPHS=
PMTILES_SPRITE=
PMTILES_URL=
# run the n+1 checker in development
# RUN_PROSOPITE=true
3 changes: 3 additions & 0 deletions .env.test.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ NO_HEADLESS_CHROME=false

# Use if you need a special chrome path during testing
# CHROME_SERVICE_PATH=

# run the n+1 testing utility prosopite while testing
# RUN_PROSOPITE=true
9 changes: 7 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@
Bullet.add_footer = true
end

config.after_initialize do
Prosopite.rails_logger = true
# default to running prosopite in development unless overriden
ENV['RUN_PROSOPITE'] = ENV.fetch('RUN_PROSOPITE', true)

if ENV['RUN_PROSOPITE']
config.after_initialize do
Prosopite.rails_logger = true
end
end
end
9 changes: 5 additions & 4 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@
# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true


config.after_initialize do
Prosopite.rails_logger = true
Prosopite.raise = true
if ENV.fetch('RUN_PROSOPITE', false)
config.after_initialize do
Prosopite.rails_logger = true
Prosopite.raise = true
end
end

end
2 changes: 1 addition & 1 deletion config/initializers/prosopite.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unless Rails.env.production?
if ENV.fetch('RUN_PROSOPITE', false)
require 'prosopite/middleware/rack'
Rails.configuration.middleware.use(Prosopite::Middleware::Rack)
end
12 changes: 7 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@
)
end

config.before(:each) do
Prosopite.scan
end
if ENV.fetch('RUN_PROSOPHITE', false)
config.before(:each) do
Prosopite.scan
end

config.after(:each) do
Prosopite.finish
config.after(:each) do
Prosopite.finish
end
end

config.before(js: true) do
Expand Down

0 comments on commit 3e24517

Please sign in to comment.