Sha256: 2527c1db0831041b02ee9926c4b6e3a90954211b9b8ab6a8f923b4a81b396fdf

Contents?: true

Size: 1.73 KB

Versions: 47

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'
require 'startback/web/api'

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

      class JsonDto
        def to(accept, content_type)
          ["application/json", %Q{{"foo":"bar"}}]
        end
      end

      class PathDto
        def to(accept, content_type)
          ["text/plain", Path.file]
        end
      end

      class DtoAble
        def initialize(dto)
          @dto = dto
        end
        def to_dto(context)
          @dto
        end
      end

      class TestedApi < ::Startback::Web::Api
        get '/no-such-one' do
          serve("Something", nil)
        end

        get '/entity' do
          serve('Entity', {foo: "bar"})
        end

        get '/path' do
          serve('Path', Path.file)
        end

        get '/dto-able' do
          serve('DTO', DtoAble.new(JsonDto.new))
        end

        get '/dto-path' do
          serve('DTO', DtoAble.new(PathDto.new))
        end
      end

      let(:app) {
        TestedApi
      }

      it 'convert nil to 404' do
        get '/no-such-one'
        expect(last_response.status).to eql(404)
      end

      it 'supports serving entities' do
        get '/entity'
        expect(last_response.body).to eql(%Q{{"foo":"bar"}})
      end

      it 'supports serving paths' do
        get '/path'
        expect(last_response.body).to eql(Path.file.read)
      end

      it 'supports serving DTO-able objects' do
        get '/dto-able'
        expect(last_response.body).to eql(%Q{{"foo":"bar"}})
      end

      it 'supports serving DTO-able objects eventually returning paths' do
        get '/dto-path'
        expect(last_response.body).to eql(Path.file.read)
      end
    end
  end # module Web
end # module Startback

Version data entries

47 entries across 47 versions & 3 rubygems

Version Path
startback-1.1.0 spec/unit/web/test_api.rb
startback-1.0.3 spec/unit/web/test_api.rb
startback-1.0.2 spec/unit/web/test_api.rb
startback-1.0.1 spec/unit/web/test_api.rb
startback-1.0.0 spec/unit/web/test_api.rb
startback-0.19.4 spec/unit/web/test_api.rb
startback-0.19.3 spec/unit/web/test_api.rb
startback-0.19.1 spec/unit/web/test_api.rb
startback-0.19.0 spec/unit/web/test_api.rb
startback-0.18.2 spec/unit/web/test_api.rb
startback-0.18.1 spec/unit/web/test_api.rb
startback-0.18.0 spec/unit/web/test_api.rb
startback-0.17.4 spec/unit/web/test_api.rb
startback-0.17.3 spec/unit/web/test_api.rb
startback-0.17.2 spec/unit/web/test_api.rb
startback-0.17.1 spec/unit/web/test_api.rb
startback-0.17.0 spec/unit/web/test_api.rb
startback-0.16.0 spec/unit/web/test_api.rb
startback-0.15.5 spec/unit/web/test_api.rb
startback-0.15.4 spec/unit/web/test_api.rb