Skip to content

Instantly share code, notes, and snippets.

@iboard
Created June 24, 2011 10:03
Show Gist options
  • Save iboard/1044531 to your computer and use it in GitHub Desktop.
Save iboard/1044531 to your computer and use it in GitHub Desktop.
default_scope doesn't work on debian
# MODEL
class Page
include Mongoid::Document
include Mongoid::Timestamps
include CoverPicture
#....
field :is_template, :type => Boolean, :default => false
default_scope where(is_template: false )
scope :templates, where(is_template: true )
# On Mac OS X (Lion preview 3) everything works fine.
# On Debian it doesn't. Page.all is always empty.
# Versions of Ruby, Rails, Mongo, MongoID all the same on both machines.
# Tests
test "Page select should not include templates" do
Page.delete_all
template_page = Page.create(:title => 'This is a template page', :body => "I'm a template", :is_template => true)
standard_page = Page.create(:title => 'This is a standard page', :body => "Standard")
sp = Page.first
tp = Page.templates.first
assert sp.title == 'This is a standard page', 'First without param is_template should be the standard page'
assert tp.title == 'This is a template page', 'Using Page.templates.first should be the template page'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment