Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Commit

Permalink
[#449] Added support for URL parameters such as refresh or `consist…
Browse files Browse the repository at this point in the history
…ency` in the Index#bulk API
  • Loading branch information
karmi committed Nov 11, 2012
1 parent 91f18b5 commit 34cc508
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/tire/index.rb
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/unit/index_test.rb
Expand Up @@ -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).
Expand Down

0 comments on commit 34cc508

Please sign in to comment.