Sha256: c9bce2af6b94fa7f33454f9a6a9fd1a31966f2847a3944ce35d18168935d477a

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

Contents

require '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) { MyApp::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(MyApp::ArtistSerializer, { "include" => "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(MyApp::ArtistSerializer, { "include" => "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

20 entries across 20 versions & 1 rubygems

Version Path
restpack_serializer-0.4.27 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.26 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.25 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.24 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.23 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.21 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.20 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.19 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.18 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.17 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.16 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.15 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.14 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.13 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.12 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.11 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.10 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.9 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.8 spec/serializable/side_loading/has_many_spec.rb
restpack_serializer-0.4.7 spec/serializable/side_loading/has_many_spec.rb