My application’s layout has this piece of code:
<%= render 'shared/analytics' if Rails.env == 'production' %>
This partial contains a small script to track analytics. How would I test to make sure this gets rendered in production but not anywhere else?
I had a feeling that trying to set the environment in a test was a bad idea. So I did some digging and started to use a global constant hash (like APP_CONFIG[:show_analytics]
) with any number of variables I could set. So now my layout has this line of code:
<%= render 'shared/analytics' if APP_CONFIG[:show_analytics] %>
Now in a test I can just set APP_CONFIG[:show_analytics] = true
and then false
for clean up. However, where do I test this? Is there such thing as a layout spec, or is it a special view spec? Am I even using the right pattern?
Sorry for the double question.