Sha256: 2da9c9ae9bfeb64dbde2c78c082377418416e88df88f698e990205b736c18c52

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Spree::Admin::LocaleController, type: :controller do
  stub_authorization!

  before { I18n.backend.store_translations(:fr, {}) }

  after do
    I18n.locale = :en
    I18n.reload!
  end

  context 'switch_to_locale specified' do
    let(:json_response) { JSON.parse(response.body, symbolize_names: true) }

    before do
      get :set, params: { switch_to_locale: switch_to_locale, format: :json }
    end

    context 'available locale' do
      let(:switch_to_locale) { 'fr' }

      it 'sets locale and returns the location for the redirect' do
        expect(I18n.locale).to eq :fr
        expect(session[:admin_locale]).to eq(switch_to_locale)
        expect(json_response).
          to eq({ locale: switch_to_locale,
                  location: spree.admin_url(host: 'test.host') })
        expect(response).to have_http_status(:ok)
      end
    end

    context 'unavailable locale' do
      let(:switch_to_locale) { 'klingon' }

      it 'does not change locale and returns 404' do
        expect(I18n.locale).to eq :en
        expect(json_response).to eq({ locale: 'en', })
        expect(response).to have_http_status(:not_found)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
solidus_backend-2.10.5 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.10.3 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.10.2 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.9.6 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.10.1 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.9.5 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.10.0 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.9.4 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.9.3 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.9.2 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.10.0.beta1 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.9.1 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.9.0 spec/controllers/spree/admin/locale_controller_spec.rb
solidus_backend-2.9.0.rc.1 spec/controllers/spree/admin/locale_controller_spec.rb