Sha256: adea0abb0880807cb4471d4d3f4531cb9e83db8dc705be5c2b624bfd16dc5b36

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'
require 'startback/web/magic_assets'

module Startback
  module Web
    describe MagicAssets do
      include Rack::Test::Methods

      context 'when used as an app' do
        let(:app){
          MagicAssets.new({
            folder: Path.dir/"fixtures/assets"
          })
        }

        it 'works as expected' do
          get "/index.js"
          expect(last_response.status).to eql(200)
          expect(last_response.body).to match(/function test/)
        end

        it 'delegates a [] call to sprockets' do
          result = app['index.js']
          expect(result.to_s).to match(/function test/)        
        end

        it 'returns a 404 on unknown' do
          get '/nosuchone.js'
          expect(last_response.status).to eql(404)
        end
      end

      context 'when used as a middleware' do
        let(:app){
          Rack::Builder.new do
            use MagicAssets, {
              folder: Path.dir/"fixtures/assets",
              path: "/my-assets"
            }
            run ->(t){
              [200, {}, ["Hello world"]]
            }
          end
        }

        it 'lets unrelated things pass' do
          get "/hello"
          expect(last_response.status).to eql(200)
          expect(last_response.body).to eql("Hello world")
        end

        it 'serves the assets under the chosen path' do
          get "/my-assets/index.js"
          expect(last_response.status).to eql(200)
          expect(last_response.body).to match(/function test/)
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
startback-0.4.0 spec/unit/web/test_magic_assets.rb