Skip to content

Instantly share code, notes, and snippets.

@royw
Created October 8, 2009 19:48
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 royw/205303 to your computer and use it in GitHub Desktop.
Save royw/205303 to your computer and use it in GitHub Desktop.
require 'mongo_mapper'
require 'spec'
MongoMapper.connection = Mongo::Connection.new('localhost')
MongoMapper.database = 'tmp'
class Test
include MongoMapper::Document
key :first, Integer
key :second, Integer
end
describe 'Wishful Thinking' do
before :all do
# need to add the following server-side function:
javascript = "db.system.js.insert( { _id : 'combine', value : function( a ) " +
"{ return a.first + a.second; } } )"
MongoMapper.database.eval(Mongo::Code.new(javascript))
end
before :each do
Test.collection.clear
Test.create(:first => 10, :second => 15)
Test.create(:first => 17, :second => 23)
end
it "should run server-side command" do
Test.all(:conditions => {"$where" => "combine(this) < 20"}).size.should == 1
end
end
__END__
royw-macbook:tmp royw$ spec where_functions.rb
F
1)
RuntimeError in 'Wishful Thinking should run server-side command'
error on invocation of $where function:
JS Error: ReferenceError: combine is not defined nofile_a:0
./where_functions.rb:28:
Finished in 0.058246 seconds
1 example, 1 failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment