Sha256: 62888d03b9770bca08c2b2027434e3a4cc67ee9b7903c064abb16321da6567b7

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require_relative '../test_helper'
require 'hyperclient/representation'

module Hyperclient
  describe Representation do
    let (:representation) do
      Representation.new JSON.parse(File.read('test/fixtures/element.json'))
    end

    describe 'intialize' do
      it 'handles non-hash representations' do
        representation = Representation.new '{"title": "Hello world"}'

        representation.attributes['title'].must_equal 'Hello world'
      end

      it 'does not raise when non-JSON response is given' do
        representation = Representation.new 'This is not JSON'

        representation.attributes.must_equal({})
      end
    end

    describe 'attributes' do
      it 'returns the resource attributes' do
        representation.attributes['title'].must_equal 'Real World ASP.NET MVC3'
      end

      it 'does not include _links as attributes' do
        representation.attributes.wont_include '_links'
      end

      it 'does not include _embedded as attributes' do
        representation.attributes.wont_include '_embedded'
      end
    end

    describe 'links' do
      it 'returns resources included in the _links section' do
        representation.links.filter.must_be_kind_of Resource
      end
    end

    describe 'embedded' do
      it 'returns resources included in the _embedded section' do
        representation.embedded.author.must_be_kind_of Resource
        representation.embedded.episodes.first.must_be_kind_of Resource
        representation.embedded.episodes.last.must_be_kind_of Resource
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyperclient-0.0.8 test/hyperclient/representation_test.rb
hyperclient-0.0.7 test/hyperclient/representation_test.rb