Sha256: 7c4e42c99c3e634e2b34d833163d0620508503cf41cde3f65ae1ef04872a2941

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

require 'spec_helper'
require 'roar_extensions'

describe Roar::Representer::JSON::HAL do
  module AttributesContructor
    def initialize(attrs={})
      attrs.each do |k,v|
        instance_variable_set("@#{k}", v)
      end
    end
  end

  class Item
    include AttributesContructor
    attr_accessor :value
  end

  class Order
    include AttributesContructor
    attr_accessor :id, :items
  end

  describe "_embedded key type" do
    it "defaults the _embedded key to be a string" do
      Bla = Module.new do
        include Roar::Representer::JSON::HAL
        property :value
        link :self do
          "http://items/#{value}"
        end
      end
      
      @order_rep = Module.new do
        include Roar::Representer::JSON::HAL
        property :id
        collection :items, :class => Item, :extend => Bla, :embedded => true
        link :self do
          "http://orders/#{id}"
        end
      end

      @order = Order.new(:items => [Item.new(:value => "Beer")], :id => 1).extend(@order_rep)

      @order.to_hash.should have_key('_embedded')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roar-extensions-0.1.0 spec/roar/representer/json/hal_spec.rb
roar-extensions-0.0.4 spec/roar/representer/json/hal_spec.rb
roar-extensions-0.0.3 spec/roar/representer/json/hal_spec.rb
roar-extensions-0.0.2 spec/roar/representer/json/hal_spec.rb