Sha256: 4cb969fd6dc5d1c34195dbbe726108fd1dcd10f709222087b8ecec1bc8c72a25

Contents?: true

Size: 1.05 KB

Versions: 15

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true
require_relative 'helper'

class TestWebHelpers < Sidekiq::Test

  class Helpers
    include Sidekiq::WebHelpers

    def initialize(params={})
      @thehash = default.merge(params)
    end

    def request
      self
    end

    def settings
      self
    end

    def locales
      ['web/locales']
    end

    def env
      @thehash
    end

    def default
      {
      }
    end
  end

  def test_locale_determination
    obj = Helpers.new
    assert_equal 'en', obj.locale

    obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,ru;q=0.2')
    assert_equal 'fr', obj.locale

    obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,ru;q=0.2')
    assert_equal 'zh-cn', obj.locale

    obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'nb-NO,nb;q=0.2')
    assert_equal 'nb', obj.locale

    obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'en-us; *')
    assert_equal 'en', obj.locale

    obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => '*')
    assert_equal 'en', obj.locale
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
sidekiq-5.0.0.beta1 test/test_web_helpers.rb
sidekiq-4.2.9 test/test_web_helpers.rb
sidekiq-4.2.8 test/test_web_helpers.rb
sidekiq-4.2.7 test/test_web_helpers.rb
sidekiq-4.2.6 test/test_web_helpers.rb
sidekiq-4.2.5 test/test_web_helpers.rb
sidekiq-4.2.4 test/test_web_helpers.rb
sidekiq-4.2.3 test/test_web_helpers.rb
sidekiq-4.2.2 test/test_web_helpers.rb
sidekiq-4.2.1 test/test_web_helpers.rb
sidekiq-4.2.0 test/test_web_helpers.rb
sidekiq-4.1.4 test/test_web_helpers.rb
sidekiq-4.1.3 test/test_web_helpers.rb
sr-sidekiq-4.1.6 test/test_web_helpers.rb
sidekiq-4.1.2 test/test_web_helpers.rb