Permalink
Browse files

Added a `Search#version` method to control returning the `version` fi…

…eld in hits


Closes #190
  • Loading branch information...
1 parent 4bb4cb0 commit 2bf558508e0cf8457c826e7251e80a501ed0340e @greglearns greglearns committed with Dec 29, 2011
Showing with 87 additions and 0 deletions.
  1. +5 −0 lib/tire/search.rb
  2. +70 −0 test/integration/query_return_version_test.rb
  3. +12 −0 test/unit/search_test.rb
View
@@ -77,6 +77,10 @@ def fields(*fields)
self
end
+ def version(value)
+ @version = value
+ end
+
def perform
@response = Configuration.client.get(self.url, self.to_json)
if @response.failure?
@@ -105,6 +109,7 @@ def to_hash
request.update( { :size => @size } ) if @size
request.update( { :from => @from } ) if @from
request.update( { :fields => @fields } ) if @fields
+ request.update( { :version => @version } ) if @version
request
end
@@ -0,0 +1,70 @@
+require 'test_helper'
+
+module Tire
+
+ class DslVersionIntegrationTest < Test::Unit::TestCase
+ include Test::Integration
+
+ context "DSL Version" do
+
+ setup do
+ Tire.index 'articles-test-ids' do
+ delete
+ create
+
+ store :id => 1, :title => 'One'
+ store :id => 2, :title => 'Two'
+
+ refresh
+ end
+ end
+
+ teardown { Tire.index('articles-test-ids').delete }
+
+ should "returns actual version (non-nil) value for records when 'version' is true" do
+ s = Tire.search('articles-test-ids') do
+ version true
+ query { string 'One' }
+ end
+
+ assert_equal 1, s.results.count
+
+ document = s.results.first
+ assert_equal 'One', document.title
+ assert_equal 1, document._version.to_i
+
+ end
+
+ should "returns a nil version field when 'version' is false" do
+ s = Tire.search('articles-test-ids') do
+ version false
+ query { string 'One' }
+ end
+
+ assert_equal 1, s.results.count
+
+ document = s.results.first
+ assert_equal 'One', document.title
+ assert_nil document._version
+
+ end
+
+ should "returns a nil version field when 'version' is not included" do
+ s = Tire.search('articles-test-ids') do
+ query { string 'One' }
+ end
+
+ assert_equal 1, s.results.count
+
+ document = s.results.first
+ assert_equal 'One', document.title
+ assert_nil document._version
+
+ end
+
+ end
+
+ end
+
+end
+
View
@@ -271,6 +271,18 @@ def foo; 'bar'; end
end
+ context "with version" do
+
+ should "set the version value in options" do
+ s = Search::Search.new('index') do
+ version true
+ end
+ hash = MultiJson.decode( s.to_json )
+ assert_equal true, hash['version']
+ end
+
+ end
+
context "with from/size" do
should "set the values in request" do

0 comments on commit 2bf5585

Please sign in to comment.