test/unit/importing_test.rb in elasticsearch-model-0.1.1 vs test/unit/importing_test.rb in elasticsearch-model-0.1.2
- old
+ new
@@ -8,10 +8,13 @@
module ::DummyImportingAdapter
module ImportingMixin
def __find_in_batches(options={}, &block)
yield if block_given?
end
+ def __transform
+ lambda {|a|}
+ end
end
def importing_mixin
ImportingMixin
end; module_function :importing_mixin
@@ -39,11 +42,11 @@
client.expects(:bulk).returns({'items' => []})
DummyImportingModel.expects(:client).returns(client)
DummyImportingModel.expects(:index_name).returns('foo')
DummyImportingModel.expects(:document_type).returns('foo')
-
+ DummyImportingModel.stubs(:__batch_to_bulk)
assert_equal 0, DummyImportingModel.import
end
should "return number of errors" do
Elasticsearch::Model::Adapter.expects(:from_class)
@@ -56,10 +59,11 @@
client.expects(:bulk).returns({'items' => [ {'index' => {}}, {'index' => {'error' => 'FAILED'}} ]})
DummyImportingModel.stubs(:client).returns(client)
DummyImportingModel.stubs(:index_name).returns('foo')
DummyImportingModel.stubs(:document_type).returns('foo')
+ DummyImportingModel.stubs(:__batch_to_bulk)
assert_equal 1, DummyImportingModel.import
end
should "yield the response" do
@@ -73,10 +77,11 @@
client.expects(:bulk).returns({'items' => [ {'index' => {}}, {'index' => {'error' => 'FAILED'}} ]})
DummyImportingModel.stubs(:client).returns(client)
DummyImportingModel.stubs(:index_name).returns('foo')
DummyImportingModel.stubs(:document_type).returns('foo')
+ DummyImportingModel.stubs(:__batch_to_bulk)
DummyImportingModel.import do |response|
assert_equal 2, response['items'].size
end
end
@@ -114,10 +119,38 @@
true
end
.returns({'items' => [ {'index' => {} }]})
DummyImportingModel.stubs(:client).returns(client)
+ DummyImportingModel.stubs(:__batch_to_bulk)
DummyImportingModel.import index: 'my-new-index', type: 'my-other-type'
+ end
+
+ should "use the default transform from adapter" do
+ client = mock('client', bulk: {'items' => []})
+ transform = lambda {|a|}
+
+ DummyImportingModel.stubs(:client).returns(client)
+ DummyImportingModel.expects(:__transform).returns(transform)
+ DummyImportingModel.expects(:__batch_to_bulk).with(anything, transform)
+
+ DummyImportingModel.import index: 'foo', type: 'bar'
+ end
+
+ should "use the transformer from options" do
+ client = mock('client', bulk: {'items' => []})
+ transform = lambda {|a|}
+
+ DummyImportingModel.stubs(:client).returns(client)
+ DummyImportingModel.expects(:__batch_to_bulk).with(anything, transform)
+
+ DummyImportingModel.import index: 'foo', type: 'bar', transform: transform
+ end
+
+ should "raise an ArgumentError if transform doesn't respond to the call method" do
+ assert_raise ArgumentError do
+ DummyImportingModel.import index: 'foo', type: 'bar', transform: "not_callable"
+ end
end
end
end