Sha256: f9f5f28d4e4659e88c01afc4be5ef9fdf051fd52eb93840b0326f7f32e7c10e5

Contents?: true

Size: 1.4 KB

Versions: 9

Compression:

Stored size: 1.4 KB

Contents

require './spec/spec_helper'

describe RestPack::Serializer::SideLoading do
  context "when side-loading" do
    describe ".has_many" do

      before(:each) do
        @artist1 = FactoryGirl.create(:artist_with_albums, album_count: 2)
        @artist2 = FactoryGirl.create(:artist_with_albums, album_count: 1)
      end
      let(:side_loads) { ArtistSerializer.side_loads(models, options) }

      context "with a single model" do
        let(:models) { [@artist1] }

        context "when including :albums" do
          let(:options) { RestPack::Serializer::Options.new(Artist, { "includes" => "albums" }) }

          it "returns side-loaded albums" do
            side_loads[:albums].count.should == @artist1.albums.count
            side_loads[:meta][:albums][:page].should == 1
            side_loads[:meta][:albums][:count].should == @artist1.albums.count
          end
        end
      end

      context "with two models" do
        let(:models) { [@artist1, @artist2] }

        context "when including :albums" do
          let(:options) { RestPack::Serializer::Options.new(Artist, { "includes" => "albums" }) }

          it "returns side-loaded albums" do
            expected_count = @artist1.albums.count + @artist2.albums.count
            side_loads[:albums].count.should == expected_count
            side_loads[:meta][:albums][:count].should == expected_count
          end
        end
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
restpack_serializer-0.2.11 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.2.10 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.2.9 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.2.8 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.2.7 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.2.6 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.2.5 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.2.4 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.2.3 spec/serializable/side_loading/has_many_spec.rb