Sha256: 6477376d2361c266cc548ea0bfd5424e34ce1f30b700ec4f8814eea851cca497

Contents?: true

Size: 814 Bytes

Versions: 8

Compression:

Stored size: 814 Bytes

Contents

require 'spec_helper'

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

  let(:resource) { MyApp::SongSerializer.single(params, scope, context) }
  let(:params) { { id: @song.id } }
  let(:scope) { nil }
  let(:context) { { } }

  it "returns a resource by id" do
    expect(resource[:id]).to eq(@song.id.to_s)
    expect(resource[:title]).to eq(@song.title)
  end

  context "with context" do
    let(:context) { { reverse_title?: true } }

    it "returns reversed titles" do
      expect(resource[:title]).to eq(@song.title.reverse)
    end
  end

  context "invalid id" do
    let(:params) { { id: @song.id + 100 } }

    it "returns nil" do
      expect(resource).to eq(nil)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
restpack_serializer-0.6.15 spec/serializable/single_spec.rb
restpack_serializer-0.6.14 spec/serializable/single_spec.rb
restpack_serializer-0.6.13 spec/serializable/single_spec.rb
restpack_serializer-0.6.12 spec/serializable/single_spec.rb
restpack_serializer-0.6.11 spec/serializable/single_spec.rb
restpack_serializer-0.6.10 spec/serializable/single_spec.rb
restpack_serializer-0.6.9 spec/serializable/single_spec.rb
restpack_serializer-0.6.8 spec/serializable/single_spec.rb