Sha256: f56a52fc63c3c5835d5b185b941ea3f4550b896b6b6b7e5863ffa160488d586f

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'
require 'cuba_api/write_aspect'
require 'cuba_api/config'
require 'cuba_api/response_status'

class E

  def id
    4711
  end

  def initialize( args = nil )
    @errors = (args || {}).delete( :errors ) || {}
    # ruby18 workaround
    def @errors.to_s
      inspect
    end
    @attributes = args
  end
    
  def deleted?
    @attrbutes.nil?
  end

  def errors
    @errors
  end

  def to_s
    @attributes.inspect + @errors.inspect
  end
end


describe CubaApi::ResponseStatus do

  before do
    Cuba.reset!
    Cuba.plugin CubaApi::Config
    Cuba.plugin CubaApi::WriteAspect
    Cuba.plugin CubaApi::ResponseStatus
    Cuba.define do
      on get do
        write E.new :errors => { :name => 'missing name' }
      end
      on post do
        write E.new :message => 'be happy' 
      end
      on put do
        write E.new :message => 'be happy' 
      end
      on delete do
        write E.new
      end
    end
  end

  it 'status 200' do
    status, _, resp = Cuba.call({'REQUEST_METHOD' => 'PUT'})
    status.must.eq 200
    resp.join.must.eq "{:message=>\"be happy\"}{}"
  end

  it 'status 201' do
    status, _, resp = Cuba.call({'REQUEST_METHOD' => 'POST'})
    status.must.eq 201
    resp.join.must.eq "{:message=>\"be happy\"}{}"
  end

  it 'status 204' do
    status, _, resp = Cuba.call({'REQUEST_METHOD' => 'DELETE'})
    status.must.eq 204
    resp.join.must.be :empty?
  end

  it 'status 412' do
    status, _, resp = Cuba.call({'REQUEST_METHOD' => 'GET'})
    status.must.eq 412
    resp.join.must.eq "{:name=>\"missing name\"}"
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cuba-api-0.6.1 spec/response_status_spec.rb
cuba-api-0.6.0 spec/response_status_spec.rb
cuba-api-0.5.1 spec/response_status_spec.rb
cuba-api-0.5.0 spec/response_status_spec.rb
cuba-api-0.4.0 spec/response_status_spec.rb
cuba-api-0.3.3 spec/response_status_spec.rb