tire 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,7 @@ module Tire
21
21
  document.update( {'id' => h['_id']} )
22
22
 
23
23
  # Update the document with meta information
24
- ['_score', '_version', 'sort', 'highlight'].each { |key| document.update( {key => h[key]} || {} ) }
24
+ ['_score', '_type', '_index', '_version', 'sort', 'highlight'].each { |key| document.update( {key => h[key]} || {} ) }
25
25
 
26
26
  object = Configuration.wrapper.new(document)
27
27
  # TODO: Figure out how to circumvent mass assignment protection for id in ActiveRecord
@@ -9,7 +9,7 @@ module Tire
9
9
 
10
10
  def total_pages
11
11
  result = @total.to_f / (@options[:per_page] ? @options[:per_page].to_i : 10 )
12
- result < 1 ? 1 : result.round
12
+ result < 1 ? 1 : result.ceil
13
13
  end
14
14
 
15
15
  def current_page
@@ -1,3 +1,3 @@
1
1
  module Tire
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -41,7 +41,7 @@ module Tire
41
41
  context "wrapping results" do
42
42
 
43
43
  setup do
44
- @response = { 'hits' => { 'hits' => [ { '_id' => 1, '_score' => 0.5, '_source' => { :title => 'Test', :body => 'Lorem' } } ] } }
44
+ @response = { 'hits' => { 'hits' => [ { '_id' => 1, '_score' => 0.5, '_index' => 'testing', '_type' => 'article', '_source' => { :title => 'Test', :body => 'Lorem' } } ] } }
45
45
  end
46
46
 
47
47
  should "wrap hits in Item by default" do
@@ -83,6 +83,16 @@ module Tire
83
83
  assert_equal 1, document.id
84
84
  end
85
85
 
86
+ should "return index" do
87
+ document = Results::Collection.new(@response).first
88
+ assert_equal "testing", document._index
89
+ end
90
+
91
+ should "return type" do
92
+ document = Results::Collection.new(@response).first
93
+ assert_equal "article", document._type
94
+ end
95
+
86
96
  end
87
97
 
88
98
  context "while paginating results" do
@@ -90,19 +100,24 @@ module Tire
90
100
  setup do
91
101
  @default_response = { 'hits' => { 'hits' => [{'_id' => 1, '_score' => 1, '_source' => {:title => 'Test'}},
92
102
  {'_id' => 2},
93
- {'_id' => 3}],
94
- 'total' => 3,
103
+ {'_id' => 3},
104
+ {'_id' => 4}],
105
+ 'total' => 4,
95
106
  'took' => 1 } }
96
107
  @collection = Results::Collection.new( @default_response, :per_page => 1, :page => 2 )
97
108
  end
98
109
 
99
110
  should "return total entries" do
100
- assert_equal 3, @collection.total
101
- assert_equal 3, @collection.total_entries
111
+ assert_equal 4, @collection.total
112
+ assert_equal 4, @collection.total_entries
102
113
  end
103
114
 
104
115
  should "return total pages" do
105
- assert_equal 3, @collection.total_pages
116
+ assert_equal 4, @collection.total_pages
117
+ @collection = Results::Collection.new( @default_response, :per_page => 2, :page => 2 )
118
+ assert_equal 2, @collection.total_pages
119
+ @collection = Results::Collection.new( @default_response, :per_page => 3, :page => 2 )
120
+ assert_equal 2, @collection.total_pages
106
121
  end
107
122
 
108
123
  should "return total pages when per_page option not set" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tire
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Karel Minarik
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-03 00:00:00 +02:00
18
+ date: 2011-05-13 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency