Sha256: d0564a41623f4708a4ffa777acdf621f7111b5c5ff3a9115f57fcbf74e5f6c41

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

module Landable::Api
  describe TemplatesController, json: true do
    routes { Landable::Engine.routes }

    describe '#preview', json: false do
      include_examples 'Authenticated API controller', :make_request
      render_views

      let(:theme) { create :theme, body: '<html><head>{% head_content %}</head><body>Theme content; page content: {{body}}</body></html>' }

      before do
        request.env['HTTP_ACCEPT'] = 'text/html'
      end

      def make_request(attributes = attributes_for(:template, theme_id: theme.id))
        post :preview, template: attributes
      end

      it 'renders JSON' do
        request.env['HTTP_ACCEPT'] = 'application/json'
        make_request
        response.status.should == 200
        last_json['template']['preview'].should be_present
      end

      it 'renders the layout without content if the body is not present' do
        request.env['HTTP_ACCEPT'] = 'application/json'
        make_request attributes_for(:page, body: nil)
        response.status.should == 200
        last_json['template']['preview'].should include('body')
      end

      it 'renders without a layout if no theme is present' do
        request.env['HTTP_ACCEPT'] = 'application/json'
        make_request attributes_for(:page, body: 'raw content')
        response.status.should == 200
        last_json['template']['preview'].should include('raw content')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
landable-1.13.1 spec/controllers/landable/api/templates_controller_spec.rb
landable-1.12.3 spec/controllers/landable/api/templates_controller_spec.rb
landable-1.12.2 spec/controllers/landable/api/templates_controller_spec.rb
landable-1.12.1 spec/controllers/landable/api/templates_controller_spec.rb