Sha256: 404ad2c4ab9da9987a03b6b58647c23aa45a89c9b666281cac9802697a77d550

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

describe Kms::TemplatesController, type: :controller do
  context 'when user/content manager' do
    login_user

    describe 'GET index' do
      it 'returns templates json representation' do
        FactoryGirl.create(:template)
        get :index, format: :json

        expect(response).to be_success
        expect(json.length).to eq(1)
      end
    end

  end

  context 'when admin' do
    login_admin

    describe 'POST create' do
      context 'when save failed' do
        it "returns errors" do
          post :create, params: { template: FactoryGirl.attributes_for(:invalid_template) }, format: :json
          expect(response.unprocessable?).to be true
          expect(json['errors']).to_not be nil
        end
      end
      context 'when save successful' do
        let(:template_params) { FactoryGirl.attributes_for(:template) }
        it "returns 204 status" do
          post :create, params: { template: template_params }, format: :json
          expect(response).to have_http_status(204)
        end
        it "substitutes <script> and <link> tags with asset_tag helper in template content" do
          post :create, params: { template: template_params }, format: :json
          template = Kms::Template.find_by(name: template_params[:name])
          expect(template.content).to include("{{ 'compressed.js' | asset_tag }}")
          expect(template.content).to include("{{ 'fonts.css' | asset_tag }}")
        end
        it "substitutes <img src..> with <img src='{{ ... | asset_path }}' helper in template content" do
          post :create, params: { template: template_params }, format: :json
          template = Kms::Template.find_by(name: template_params[:name])
          expect(template.content).to include("{{ 'slide.jpg' | asset_path }}")
        end
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kms-1.1.0 spec/controllers/kms/templates_controller_spec.rb
kms-1.0.1 spec/controllers/kms/templates_controller_spec.rb
kms-1.0.0 spec/controllers/kms/templates_controller_spec.rb