require File.join(File.dirname(__FILE__), '../../../_lib.rb') class MoSQL::Test::SchemaTest < MoSQL::Test TEST_MAP = < "row 1", 'var' => 6}) assert_equal(["row 1", 6], out) end it 'Includes extra props' do out = @map.transform('db.with_extra_props', {'_id' => 7, 'var' => 6, 'other var' => {'key' => 'value'}}) assert_equal(2, out.length) assert_equal(7, out[0]) assert_equal({'var' => 6, 'other var' => {'key' => 'value'}}, JSON.parse(out[1])) end it 'gets all_columns right' do assert_equal(['id', 'var'], @map.all_columns(@map.find_ns('db.collection'))) assert_equal(['id', '_extra_props'], @map.all_columns(@map.find_ns('db.with_extra_props'))) end end describe 'when copying data' do it 'quotes special characters' do assert_equal(%q{\\\\}, @map.quote_copy(%q{\\})) assert_equal(%Q{\\\t}, @map.quote_copy( %Q{\t})) assert_equal(%Q{\\\n}, @map.quote_copy( %Q{\n})) assert_equal(%Q{some text}, @map.quote_copy(%Q{some text})) end end describe 'fetch_and_delete_dotted' do def check(orig, path, expect, result) assert_equal(expect, @map.fetch_and_delete_dotted(orig, path)) assert_equal(result, orig) end it 'works on things without dots' do check({'a' => 1, 'b' => 2}, 'a', 1, {'b' => 2}) end it 'works if the key does not exist' do check({'a' => 1, 'b' => 2}, 'c', nil, {'a' => 1, 'b' => 2}) end it 'fetches nested hashes' do check({'a' => 1, 'b' => { 'c' => 1, 'd' => 2 }}, 'b.d', 2, {'a' => 1, 'b' => { 'c' => 1 }}) end it 'fetches deeply nested hashes' do check({'a' => 1, 'b' => { 'c' => { 'e' => 8, 'f' => 9 }, 'd' => 2 }}, 'b.c.e', 8, {'a' => 1, 'b' => { 'c' => { 'f' => 9 }, 'd' => 2 }}) end it 'cleans up empty hashes' do check({'a' => { 'b' => 4}}, 'a.b', 4, {}) check({'a' => { 'b' => { 'c' => 5 }, 'd' => 9}}, 'a.b.c', 5, {'a' => { 'd' => 9 }}) end it 'recursively cleans' do check({'a' => { 'b' => { 'c' => { 'd' => 99 }}}}, 'a.b.c.d', 99, {}) end it 'handles missing path components' do check({'a' => { 'c' => 4 }}, 'a.b.c.d', nil, {'a' => { 'c' => 4 }}) end end end