test/functional/schema.rb in mosql-0.1.2 vs test/functional/schema.rb in mosql-0.2.0

- old
+ new

@@ -13,23 +13,37 @@ with_extra_props: :meta: :table: sqltable2 :extra_props: true :columns: - - _id: INTEGER + - _id: TEXT + with_dotted: + :meta: + :table: sqltable3 + :extra_props: true + :columns: + - _id: TEXT + - var_a: + :source: vars.a + :type: TEXT + - var_b: + :source: vars.b + :type: TEXT EOF before do @map = MoSQL::Schema.new(YAML.load(TEST_MAP)) @sequel.drop_table?(:sqltable) @sequel.drop_table?(:sqltable2) + @sequel.drop_table?(:sqltable3) @map.create_schema(@sequel) end def table; @sequel[:sqltable]; end def table2; @sequel[:sqltable2]; end + def table3; @sequel[:sqltable3]; end it 'Creates the tables with the right columns' do assert_equal(Set.new([:_id, :var]), Set.new(table.columns)) assert_equal(Set.new([:_id, :_extra_props]), @@ -47,9 +61,33 @@ assert_equal(4, table.count) rows = table.select.sort_by { |r| r[:_id] } assert_equal(%w[a b c d], rows.map { |r| r[:_id] }) assert_equal(nil, rows[2][:var]) assert_equal(nil, rows[3][:var]) + end + + it 'Can COPY dotted data' do + objects = [ + {'_id' => "a", 'vars' => {'a' => 1, 'b' => 2}}, + {'_id' => "b", 'vars' => {}}, + {'_id' => "c", 'vars' => {'a' => 2, 'c' => 6}}, + {'_id' => "d", 'vars' => {'a' => 1, 'c' => 7}, 'extra' => 'moo'} + ] + @map.copy_data(@sequel, 'db.with_dotted', objects.map { |o| @map.transform('db.with_dotted', o) } ) + assert_equal(4, table3.count) + o = table3.first(:_id => 'a') + assert_equal("1", o[:var_a]) + assert_equal("2", o[:var_b]) + + o = table3.first(:_id => 'b') + assert_equal({}, JSON.parse(o[:_extra_props])) + + o = table3.first(:_id => 'c') + assert_equal({'vars' => { 'c' => 6} }, JSON.parse(o[:_extra_props])) + + o = table3.first(:_id => 'd') + assert_equal({'vars' => { 'c' => 7}, 'extra' => 'moo' }, JSON.parse(o[:_extra_props])) + assert_equal(nil, o[:var_b]) end it 'Can COPY BSON::ObjectIDs' do o = {'_id' => BSON::ObjectId.new, 'var' => 0} @map.copy_data(@sequel, 'db.collection', [ @map.transform('db.collection', o)] )