Browse files

[#449] Added support for URL parameters such as `refresh` or `consist…

…ency` in the Index#bulk API
  • Loading branch information...
1 parent 91f18b5 commit 34cc50833c5e009a0cc540f95c6d547d792bbb73 @karmi committed Nov 11, 2012
Showing with 24 additions and 1 deletion.
  1. +7 −1 lib/tire/index.rb
  2. +17 −0 test/unit/index_test.rb
View
8 lib/tire/index.rb
@@ -130,7 +130,13 @@ def bulk(action, documents, options={})
count = 0
begin
- @response = Configuration.client.post("#{url}/_bulk", payload.join("\n"))
+ params = {}
+ params[:consistency] = options.delete(:consistency)
+ params[:refresh] = options.delete(:refresh)
+ params = params.reject { |name,value| !value }
+ params_encoded = params.empty? ? '' : "?#{params.to_param}"
+
+ @response = Configuration.client.post("#{url}/_bulk#{params_encoded}", payload.join("\n"))
raise RuntimeError, "#{@response.code} > #{@response.body}" if @response && @response.failure?
@response
rescue StandardError => error
View
17 test/unit/index_test.rb
@@ -578,6 +578,23 @@ class MyDocument;end; document = MyDocument.new
end
+ should "pass URL parameters such as refresh or consistency" do
+ Configuration.client.
+ expects(:post).
+ with do |url, payload|
+ # p url
+ assert_match /\?consistency=one/, url
+ assert_match /&refresh=true/, url
+ end.
+ returns(mock_response('{}'), 200)
+
+ @index.bulk :index,
+ [ {:id => '1', :title => 'One' } ],
+ :consistency => 'one',
+ :refresh => true
+
+ end
+
should "serialize ActiveModel instances as payload" do
Configuration.client.
expects(:post).

0 comments on commit 34cc508

Please sign in to comment.