Sha256: bbc78dada6fa0509e723ae0ddf0713df4c1a1dc13bfd13d646e0864a23e31969

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

require './spec/rails_helper'

describe ActionView::PathResolver do
  let(:resolver) { ActionView::PathResolver.new }

  context '#extract_handler_and_format' do
    subject(:template_format) do
      _, format = resolver.extract_handler_and_format("application.#{template_extension}", nil)
      format.to_s
    end

    context 'when only handler and format are present' do
      let(:template_extension) { 'html.erb' }

      it { expect(template_format).to eq 'text/html' }
    end

    context 'when handler, format and version are present' do
      let(:template_extension) { 'json.v1.jbuilder' }

      it { expect(template_format).to eq 'application/json' }
    end

    context 'when handler, format and locale are present' do
      let(:template_extension) { 'en.json.jbuilder' }

      it { expect(template_format).to eq 'application/json' }
    end

    context 'when handler, format, locale and version are present' do
      let(:template_extension) { 'en.json.v1.jbuilder' }

      it { expect(template_format).to eq 'application/json' }
    end

    context 'when in Rails >=4.1' do
      before do
        unless (ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR >= 1) ||
            ActionPack::VERSION::MAJOR > 5
          skip('Template variants are only available in Rails >=4.1')
        end
      end

      context 'when handler, format, variant and version are present' do
        let(:template_extension) { 'application.json+tablet.v1.jbuilder' }

        it { expect(template_format).to eq 'application/json' }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
versioncake-3.4.0 spec/integration/view/view_additions_spec.rb
versioncake-3.3.0 spec/integration/view/view_additions_spec.rb
versioncake-3.2.0 spec/integration/view/view_additions_spec.rb
versioncake-3.1.0 spec/integration/view/view_additions_spec.rb
versioncake-3.0.0 spec/integration/view/view_additions_spec.rb