Sha256: 688009dea93a482aafa574659f77e916c5fcaf03f46d84b882ba10f42389c6d7

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 KB

Contents

require './spec/spec_helper'

describe RestPack::Serializer::Resource do
  before(:each) do
    @album = FactoryGirl.create(:album_with_songs, song_count: 11)
    @song = @album.songs.first
  end

  let(:resource) { SongSerializer.resource(params) }
  let(:params) { { id: @song.id.to_s } }

  it "returns a resource by id" do
    resource[:songs].count.should == 1
    resource[:songs][0][:id].should == @song.id.to_s
  end

  describe "side-loading" do
    let(:params) { { id: @song.id.to_s, includes: 'albums' } }

    it "includes side-loaded models" do
      resource[:albums].count.should == 1
      resource[:albums].first[:id].should == @song.album.id.to_s
    end

    it "includes the side-loads in the main meta data" do
      resource[:meta][:songs][:includes].should == [:albums]
    end
  end

  describe "missing resource" do
    let(:params) { { id: "-99" } }
    it "returns no resource" do
      resource[:songs].length.should == 0
    end

    #TODO: add specs for jsonapi error format when it has been standardised
    # https://github.com/RestPack/restpack_serializer/issues/27
    # https://github.com/json-api/json-api/issues/7
  end

  describe "song with no artist" do
    let(:song) { FactoryGirl.create(:song, :artist => nil) }
    let(:resource) { SongSerializer.resource(id: song.id.to_s) }

    it "should not have an artist link" do
      resource[:songs][0][:links].keys.should_not include(:artist)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
restpack_serializer-0.4.2 spec/serializable/resource_spec.rb
restpack_serializer-0.4.1 spec/serializable/resource_spec.rb
restpack_serializer-0.2.16 spec/serializable/resource_spec.rb
restpack_serializer-0.2.15 spec/serializable/resource_spec.rb
restpack_serializer-0.2.14 spec/serializable/resource_spec.rb
restpack_serializer-0.2.13 spec/serializable/resource_spec.rb
restpack_serializer-0.2.12 spec/serializable/resource_spec.rb
restpack_serializer-0.2.11 spec/serializable/resource_spec.rb
restpack_serializer-0.2.10 spec/serializable/resource_spec.rb