require File.join(File.dirname(__FILE__), '_lib.rb') require 'mosql/cli' class MoSQL::Test::Functional::CLITest < MoSQL::Test::Functional TEST_MAP = < BSON::ObjectId.new, 'var' => 17 } @adapter.upsert_ns('mosql_test.collection', o) @cli.handle_op({ 'ns' => 'mosql_test.collection', 'op' => 'u', 'o2' => { '_id' => o['_id'] }, 'o' => { 'var' => 27 } }) assert_equal(27, sequel[:sqltable].where(:_id => o['_id'].to_s).select.first[:var]) end it 'handle "d" ops with BSON::ObjectIds' do o = { '_id' => BSON::ObjectId.new, 'var' => 17 } @adapter.upsert_ns('mosql_test.collection', o) @cli.handle_op({ 'ns' => 'mosql_test.collection', 'op' => 'd', 'o' => { '_id' => o['_id'] }, }) assert_equal(0, sequel[:sqltable].where(:_id => o['_id'].to_s).count) end it 'handle "u" ops with $set and BSON::ObjectIDs' do o = { '_id' => BSON::ObjectId.new, 'var' => 17 } @adapter.upsert_ns('mosql_test.collection', o) # $set's are currently a bit of a hack where we read the object # from the db, so make sure the new object exists in mongo connect_mongo['mosql_test']['collection'].insert(o.merge('var' => 100), :w => 1) @cli.handle_op({ 'ns' => 'mosql_test.collection', 'op' => 'u', 'o2' => { '_id' => o['_id'] }, 'o' => { '$set' => { 'var' => 100 } }, }) assert_equal(100, sequel[:sqltable].where(:_id => o['_id'].to_s).select.first[:var]) end end