Skip to content

Instantly share code, notes, and snippets.

@shingara
Created May 9, 2012 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shingara/2643623 to your computer and use it in GitHub Desktop.
Save shingara/2643623 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe "Issue with default_scope and eager loading" do
class Post
include Mongoid::Document
belongs_to :blog
end
class Blog
include Mongoid::Document
has_many :posts
default_scope includes(:posts)
end
let(:blog) {
Blog.create
}
let!(:posts) {
2.times {
blog.posts.create
}
}
it 'should have one post associate' do
Mongoid.identity_map_enabled = true
Mongoid.unit_of_work do
Blog.find(blog.id).posts.should have(2).entries
Blog.where(:_id => blog.id).first.posts.should have(2).entries
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment