test/functional/streamer.rb in mosql-0.3.1 vs test/functional/streamer.rb in mosql-0.3.2
- old
+ new
@@ -18,18 +18,43 @@
:meta:
:table: sqltable
:columns:
- _id: TEXT
- var: INTEGER
+ - arry: INTEGER ARRAY
renameid:
:meta:
:table: sqltable2
:columns:
- id:
:source: _id
:type: TEXT
- goats: INTEGER
+
+filter_test:
+ collection:
+ :meta:
+ :table: filter_sqltable
+ :filter:
+ :_id:
+ '$gte': !ruby/object:BSON::ObjectId
+ data:
+ - 83
+ - 179
+ - 75
+ - 128
+ - 0
+ - 0
+ - 0
+ - 0
+ - 0
+ - 0
+ - 0
+ - 0
+ :columns:
+ - _id: TEXT
+ - var: INTEGER
EOF
before do
@map = MoSQL::Schema.new(YAML.load(TEST_MAP))
@adapter = MoSQL::SQLAdapter.new(@map, sql_test_uri)
@@ -107,14 +132,31 @@
'o' => { '_id' => o['_id'] },
})
assert_equal(0, sequel[:sqltable2].where(:id => o['_id'].to_s).count)
end
+ it 'filters unwanted records' do
+ data = [{:_id => BSON::ObjectId.from_time(Time.utc(2014, 7, 1)), :var => 2},
+ {:_id => BSON::ObjectId.from_time(Time.utc(2014, 7, 2)), :var => 3}]
+ collection = mongo["filter_test"]["collection"]
+ collection.drop
+ data.map { |rec| collection.insert(rec)}
+
+ @streamer.options[:skip_tail] = true
+ @streamer.initial_import
+
+ inserted_records = @sequel[:filter_sqltable].select
+ assert_equal(1, inserted_records.count)
+ record = inserted_records.first
+ data[1][:_id] = data[1][:_id].to_s
+ assert_equal(data[1], record)
+ end
+
describe '.bulk_upsert' do
it 'inserts multiple rows' do
objs = [
{ '_id' => BSON::ObjectId.new, 'var' => 0 },
- { '_id' => BSON::ObjectId.new, 'var' => 1 },
+ { '_id' => BSON::ObjectId.new, 'var' => 1, 'arry' => [1, 2] },
{ '_id' => BSON::ObjectId.new, 'var' => 3 },
].map { |o| @map.transform('mosql_test.collection', o) }
@streamer.bulk_upsert(sequel[:sqltable], 'mosql_test.collection',
objs)