From b4e38e5646e26298d399488c9b954de64fee648f Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 18 Aug 2014 12:12:48 +0530 Subject: [PATCH 1/2] updated checks of environment with Rails.env by Rails.env methods --- app/helpers/common_helper.rb | 4 ++-- app/jobs/scheduled/version_check.rb | 2 +- app/models/admin_dashboard_data.rb | 4 ++-- config/application.rb | 4 ++-- config/routes.rb | 2 +- lib/discourse_hub.rb | 2 +- lib/import/importer.rb | 2 +- lib/scheduler/defer.rb | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/helpers/common_helper.rb b/app/helpers/common_helper.rb index 0ac0cc8b81f..10992b1ae6b 100644 --- a/app/helpers/common_helper.rb +++ b/app/helpers/common_helper.rb @@ -1,12 +1,12 @@ module CommonHelper def render_google_universal_analytics_code - if Rails.env == "production" && SiteSetting.ga_universal_tracking_code.present? + if Rails.env.production? && SiteSetting.ga_universal_tracking_code.present? render partial: "common/google_universal_analytics" end end def render_google_analytics_code - if Rails.env == "production" && SiteSetting.ga_tracking_code.present? + if Rails.env.production? && SiteSetting.ga_tracking_code.present? render partial: "common/google_analytics" end end diff --git a/app/jobs/scheduled/version_check.rb b/app/jobs/scheduled/version_check.rb index f42a4be3904..a2a0920a4c3 100644 --- a/app/jobs/scheduled/version_check.rb +++ b/app/jobs/scheduled/version_check.rb @@ -23,7 +23,7 @@ module Jobs Email::Sender.new(message, :new_version).send end rescue => e - raise e unless Rails.env == 'development' # Fail version check silently in development mode + raise e unless Rails.env.development? # Fail version check silently in development mode end end true diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index e182de003ba..ac792c11a8a 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -84,7 +84,7 @@ class AdminDashboardData end def rails_env_check - I18n.t("dashboard.rails_env_warning", env: Rails.env) unless Rails.env == 'production' + I18n.t("dashboard.rails_env_warning", env: Rails.env) unless Rails.env.production? end def host_names_check @@ -170,7 +170,7 @@ class AdminDashboardData end def send_consumer_email_check - I18n.t('dashboard.consumer_email_warning') if Rails.env == 'production' and ActionMailer::Base.smtp_settings[:address] =~ /gmail\.com|live\.com|yahoo\.com/ + I18n.t('dashboard.consumer_email_warning') if Rails.env.production? and ActionMailer::Base.smtp_settings[:address] =~ /gmail\.com|live\.com|yahoo\.com/ end def site_contact_username_check diff --git a/config/application.rb b/config/application.rb index 0e24c6e6371..f290bd5c9e3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,7 +9,7 @@ require_relative '../lib/discourse_plugin_registry' # Global config require_relative '../app/models/global_setting' -require 'pry-rails' if Rails.env == "development" +require 'pry-rails' if Rails.env.development? if defined?(Bundler) Bundler.require(*Rails.groups(assets: %w(development test profile))) @@ -18,7 +18,7 @@ end module Discourse class Application < Rails::Application def config.database_configuration - if Rails.env == "production" + if Rails.env.production? GlobalSetting.database_config else super diff --git a/config/routes.rb b/config/routes.rb index add9d1604f1..77eceee0ecd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,7 @@ Discourse::Application.routes.draw do match "/404", to: "exceptions#not_found", via: [:get, :post] get "/404-body" => "exceptions#not_found_body" - if Rails.env == "development" + if Rails.env.development? mount Sidekiq::Web => "/sidekiq" mount Logster::Web => "/logs" else diff --git a/lib/discourse_hub.rb b/lib/discourse_hub.rb index fa7ecace86e..e8eafdef24e 100644 --- a/lib/discourse_hub.rb +++ b/lib/discourse_hub.rb @@ -42,7 +42,7 @@ module DiscourseHub end def self.hub_base_url - if Rails.env == 'production' + if Rails.env.production? 'http://api.discourse.org/api' else ENV['HUB_BASE_URL'] || 'http://local.hub:3000/api' diff --git a/lib/import/importer.rb b/lib/import/importer.rb index 36e98718144..7d77dbbbba3 100644 --- a/lib/import/importer.rb +++ b/lib/import/importer.rb @@ -58,7 +58,7 @@ module Import rescue SystemExit log "Restore process was cancelled!" rollback - rescue Exception => ex + rescue => ex log "EXCEPTION: " + ex.message log ex.backtrace.join("\n") rollback diff --git a/lib/scheduler/defer.rb b/lib/scheduler/defer.rb index cac1ca8970d..89522f08abc 100644 --- a/lib/scheduler/defer.rb +++ b/lib/scheduler/defer.rb @@ -1,7 +1,7 @@ module Scheduler module Deferrable def initialize - @async = Rails.env != "test" + @async = !Rails.env.test? @queue = Queue.new @mutex = Mutex.new @thread = nil From fa8d18fb97789d970163019abebbf4e32a297424 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 18 Aug 2014 15:38:25 +0530 Subject: [PATCH 2/2] updated test with proper change of Rails.env during test --- spec/models/admin_dashboard_data_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/models/admin_dashboard_data_spec.rb b/spec/models/admin_dashboard_data_spec.rb index 414c296c261..a441099e2ef 100644 --- a/spec/models/admin_dashboard_data_spec.rb +++ b/spec/models/admin_dashboard_data_spec.rb @@ -6,17 +6,17 @@ describe AdminDashboardData do subject { described_class.new.rails_env_check } it 'returns nil when running in production mode' do - Rails.stubs(:env).returns('production') + Rails.stubs(env: ActiveSupport::StringInquirer.new('production')) subject.should be_nil end it 'returns a string when running in development mode' do - Rails.stubs(:env).returns('development') + Rails.stubs(env: ActiveSupport::StringInquirer.new('development')) subject.should_not be_nil end it 'returns a string when running in test mode' do - Rails.stubs(:env).returns('test') + Rails.stubs(env: ActiveSupport::StringInquirer.new('test')) subject.should_not be_nil end end @@ -119,12 +119,12 @@ describe AdminDashboardData do before { ActionMailer::Base.stubs(:smtp_settings).returns({address: 'smtp.gmail.com'}) } it 'returns nil in development env' do - Rails.stubs(:env).returns('development') + Rails.stubs(env: ActiveSupport::StringInquirer.new('development')) expect(subject).to be_nil end it 'returns a string when in production env' do - Rails.stubs(:env).returns('production') + Rails.stubs(env: ActiveSupport::StringInquirer.new('production')) expect(subject).to_not be_nil end end