Sha256: 9eb71365a1538638af83cdb566280a8252b0f9c85a884babfd129acbc4d621b7

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

require_relative 'spec_helper'

describe Kanpachi::Response do
  subject do
    Kanpachi::Response.new(:default)
  end

  it 'initializes with the status' do
    subject.status.must_equal 200
  end

  it 'initializes with a headers hash' do
    subject.headers.must_equal Hash.new
  end

  it 'returns headers' do
    subject.headers['Content-Type'] = 'application/json'
    subject.headers.keys.must_include 'Content-Type'
  end

  it 'has a representation accessor' do
    representation = Module.new do
      include Kanpachi::Response::Representation
      property :title
    end
    subject.representation = representation
    subject.representation.must_equal representation
  end

  it 'representation is a Roar decorator' do
    subject.representation.superclass.must_equal Roar::Decorator
    subject.representation.ancestors.must_include Roar::Representer::JSON
    subject.representation.ancestors.must_include Roar::Decorator::HypermediaConsumer
  end

  it 'representation returns properties' do
    user_representer = Module.new do
      include Kanpachi::Response::Representation
      property :name, type: String
      property :email, type: String
    end

    representation = Module.new do
      include Kanpachi::Response::Representation
      property :id, type: Integer
      collection :people, extend: user_representer
      hash :user, extend: user_representer
    end
    representation.properties.keys.must_include 'id'
    representation.properties.keys.must_include 'people'
    representation.properties.keys.must_include 'user'
    representation.properties['id'][:type].must_equal Integer
    representation.properties['people'][:collection].must_equal true
    representation.properties['people']['name'][:type].must_equal String
    representation.properties['people']['email'][:type].must_equal String
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kanpachi-0.0.7 spec/response_spec.rb
kanpachi-0.0.6 spec/response_spec.rb
kanpachi-0.0.5 spec/response_spec.rb