Sha256: bb0972d1fc8bc79bfef49be6dbe3ce325268b759b779335b956fd24dbcf60174

Contents?: true

Size: 1.53 KB

Versions: 8

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

describe RestPack::Serializer::SideLoading do
  context "when side-loading" do
    let(:side_loads) { MyApp::ArtistSerializer.side_loads(models, options) }

    describe ".has_and_belongs_to_many" do

      before(:each) do
        @artist1 = FactoryGirl.create(:artist_with_stalkers, stalker_count: 2)
        @artist2 = FactoryGirl.create(:artist_with_stalkers, stalker_count: 3)
      end

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

        context "when including :albums" do
          let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, "include" => "stalkers") }
          let(:stalker_count) { @artist1.stalkers.count }

          it "returns side-loaded albums" do
            expect(side_loads[:stalkers].count).to eq(stalker_count)
            expect(side_loads[:meta][:stalkers][:page]).to eq(1)
            expect(side_loads[:meta][:stalkers][:count]).to eq(stalker_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" => "stalkers") }
          let(:stalker_count) { @artist1.stalkers.count + @artist2.stalkers.count }

          it "returns side-loaded albums" do
            expect(side_loads[:stalkers].count).to eq(stalker_count)
            expect(side_loads[:meta][:stalkers][:count]).to eq(stalker_count)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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