Sha256: 838856d27bb77b2d3a210dc1a33376d31f752d6bfe9f395bb6835565facffe77

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

describe ApplicationController, type: [:controller, :request] do
  context 'when context has constraints' do
    it "checks value via regexp" do
      expect(get: '/en').to route_to('application#index', locale: 'en')
      expect(get: '/ru/locale').to route_to('application#index', locale: 'ru')
      expect(get: '/de').not_to be_routable
    end
  end

  context 'when context has no constraints' do
    it 'allows any value' do
      expect(get: '/ru/moscow/city').to route_to('application#index', locale: 'ru', city: 'moscow')
    end
  end

  context 'when context is required' do
    it 'requires value' do
      expect(get: '/moscow/city').to route_to('application#index', city: 'moscow')
    end
  end

  context 'context locking' do
    it 'overrides current context' do
      get '/ru/locale'
      expect(controller).not_to be_context_locked(:locale)

      controller.lock_context(locale: :en)

      expect(controller).to be_context_locked(:locale)
      expect(controller.locked_context(:locale)).to eq(:en)
      expect(controller.locked_context).to eq('locale' => :en)
    end
  end

  describe '#contexts' do
    it 'returns contexts hash' do
      get '/en'

      expect(controller.contexts[:locale]).to be_a(LocaleContext)
    end
  end

  describe '#current_context' do
    it 'returns current context value' do
      get '/ru/locale'

      expect(controller.current_context(:locale)).to eq(:ru)
      expect(controller.current_context).to eq(locale: :ru)
    end
  end

  context 'url helpers' do
    it 'includes context' do
      get '/ru/moscow/city'

      expect(controller.city_page_path).to eq('/ru/moscow/city')
    end

    it 'allows to customize url option' do
      get '/ru/moscow/city'
      get '/en'

      expect(controller.locale_page_path).to eq('/locale')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contexts-2.0.0 spec/controllers/application_controller_spec.rb