Sha256: dd2a5dee351c91b4df4f2b503247e42aaaaff917e74efda86150b6f051b6ea29

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

describe Kms::AssetsController, type: :controller do
  login_user
  describe 'GET index' do
    it 'returns assets json representation' do
      FactoryGirl.create(:asset)
      get :index, format: :json

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

  describe 'POST create' do
    it 'returns 200 status and creates asset' do
      asset_params = FactoryGirl.attributes_for(:asset)
      post :create, params: { asset: asset_params }, format: :json
      expect(response).to be_success
      expect(Kms::Asset.count).to eq(1)
    end
  end

  describe 'PUT update' do
    it 'returns 200 status and updates asset' do
      css_asset = FactoryGirl.create(:css_asset)
      put :update, params: { id: css_asset.id, asset: {performing_plain_text: true, text: 'h1 {}'} }, format: :json
      expect(response).to be_success
      expect(Kms::Asset.find(css_asset.id).text).to be_eql('h1 {}')
    end
  end

  describe 'GET show' do
    it 'returns asset json representation' do
      css_asset = FactoryGirl.create(:css_asset)
      get :index, params: { id: css_asset.id }, format: :json

      expect(response).to be_success
      expect(json[0]['text']).to eq(css_asset.text)
    end
  end

  describe 'DELETE destroy' do
    it "deletes asset" do
      asset = FactoryGirl.create(:asset)
      delete :destroy, params: { id: asset.id }, format: :json
      expect(response).to have_http_status(204)
      expect { Kms::Asset.find(asset.id) }.to raise_error(ActiveRecord::RecordNotFound)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kms-1.0.1 spec/controllers/kms/assets_controller_spec.rb
kms-1.0.0 spec/controllers/kms/assets_controller_spec.rb