Sha256: b033d4f4591b72c62e8358ab7f6085cf9fefd3c4f77f161e55ff75f2d517b786

Contents?: true

Size: 958 Bytes

Versions: 3

Compression:

Stored size: 958 Bytes

Contents

require "spec_helper"

describe Mongoid::Criteria do

  describe "#each" do

    before :each do
      Game.destroy_all
      Person.destroy_all
      @person1 = Person.create(:title => "Sir", :age => 100, :aliases => ["D", "Durran"], :ssn => "666666666")
      @person2 = Person.create(:title => "Madam", :age => 1, :ssn => "098-76-5434")
      @person1.create_game(:score => 10)
      @person2.create_game(:score => 20)
    end

    it "without includes" do
      criteria = Person.all
      criteria.collect(&:title).should == ["Sir", "Madam"]
    end

    it "with includes" do
      criteria = Person.includes(:game)
      criteria.collect(&:title).should == ["Sir", "Madam"]
      criteria.collect(&:game).should == [@person1.game, @person2.game]
    end

    it "empty parent objects with include" do
      Game.destroy_all
      Person.destroy_all
      criteria = Person.includes(:game)
      criteria.collect(&:game).should == []
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-eager-loading-0.3.1 spec/mongoid-eager-loading/mongoid/criteria_spec.rb
mongoid-eager-loading-0.3.0 spec/mongoid-eager-loading/mongoid/criteria_spec.rb
mongoid-eager-loading-0.2.0 spec/mongoid-eager-loading/mongoid/criteria_spec.rb