Sha256: 2248cf7812e2c2f2c6c9e0fca52c8402c64ba239ad6679af7ceeeb6921ec78bb

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 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 '{"_links": {"self": {"href": "/productions/1"}}}'

        representation.url.must_equal '/productions/1'
      end

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

        representation.url.must_equal nil
      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 'resources' do
      it 'returns resources included in the _embedded section' do
        representation.resources.author.must_be_kind_of Resource
        representation.resources.episodes.first.must_be_kind_of Resource
        representation.resources.episodes.last.must_be_kind_of Resource
      end
    end

    describe 'url' do
      it 'returns the url of the resource grabbed from the representation' do
        representation.url.must_equal '/productions/1'
      end

      it 'returns nil when the representation does not include the resource url' do
        representation = Representation.new({_links: {media: {href: '/media/1'}}})

        representation.url.must_equal nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyperclient-0.0.5 test/hyperclient/representation_test.rb
hyperclient-0.0.4 test/hyperclient/representation_test.rb