From f8baa8af37274cacd3ef0437e9cede5ad5ecbe0d Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Wed, 6 Jan 2016 10:29:41 -0800 Subject: [PATCH] Clean up global state changes in custom web test, fixes #2752 --- lib/sidekiq/web_helpers.rb | 5 +++++ test/test_web.rb | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/sidekiq/web_helpers.rb b/lib/sidekiq/web_helpers.rb index a49c5c33..6e1737bc 100644 --- a/lib/sidekiq/web_helpers.rb +++ b/lib/sidekiq/web_helpers.rb @@ -17,6 +17,11 @@ module Sidekiq end end + def clear_caches + @@strings = nil + @@locale_files = nil + end + def locale_files @@locale_files ||= settings.locales.flat_map do |path| Dir["#{path}/*.yml"] diff --git a/test/test_web.rb b/test/test_web.rb index 72ded94e..7fc2a4d5 100644 --- a/test/test_web.rb +++ b/test/test_web.rb @@ -369,19 +369,24 @@ class TestWeb < Sidekiq::Test assert_equal 200, last_response.status end - Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "fixtures") - it 'can show user defined tab with custom locales' do - begin + describe 'custom locales' do + before do + Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "fixtures") Sidekiq::Web.tabs['Custom Tab'] = '/custom' Sidekiq::Web.get('/custom') do + clear_caches # ugly hack since I can't figure out how to access WebHelpers outside of this context t('translated_text') end + end + after do + Sidekiq::Web.tabs.delete 'Custom Tab' + Sidekiq::Web.settings.locales.pop + end + + it 'can show user defined tab with custom locales' do get '/custom' assert_match(/Changed text/, last_response.body) - - ensure - Sidekiq::Web.tabs.delete 'Custom Tab' end end