outoftime-sunspot 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 5
2
+ :patch: 6
3
3
  :major: 0
4
4
  :minor: 9
@@ -57,6 +57,10 @@ module Sunspot
57
57
  end
58
58
  @instance
59
59
  end
60
+
61
+ def inspect
62
+ "#<Sunspot::Search::Hit:#{@class_name} #{@primary_key}>"
63
+ end
60
64
  end
61
65
  end
62
66
  end
@@ -159,16 +159,14 @@ module Sunspot
159
159
  end
160
160
 
161
161
  def populate_hits! #:nodoc:
162
- type_hit_hash = Hash.new { |h, k| h[k] = [] }
163
- id_hit_hash = {}
164
- for hit in hits
165
- type_hit_hash[hit.class_name] << hit
166
- id_hit_hash[hit.primary_key] = hit
162
+ id_hit_hash = Hash.new { |h, k| h[k] = {} }
163
+ hits.each do |hit|
164
+ id_hit_hash[hit.class_name][hit.primary_key] = hit
167
165
  end
168
- type_hit_hash.each_pair do |class_name, hits|
169
- ids = hits.map { |hit| hit.primary_key }
170
- for instance in data_accessor_for(Util.full_const_get(class_name)).load_all(ids)
171
- hit = id_hit_hash[Adapters::InstanceAdapter.adapt(instance).id.to_s]
166
+ id_hit_hash.each_pair do |class_name, hits|
167
+ ids = hits.map { |id, hit| hit.primary_key }
168
+ data_accessor_for(Util.full_const_get(class_name)).load_all(ids).each do |instance|
169
+ hit = id_hit_hash[class_name][Adapters::InstanceAdapter.adapt(instance).id.to_s]
172
170
  hit.instance = instance
173
171
  end
174
172
  end
@@ -15,6 +15,16 @@ describe 'retrieving search' do
15
15
  session.search(Post).results.should == [post_2, post_1]
16
16
  end
17
17
 
18
+ # This is a reduction of a crazy bug I found in production where some hits
19
+ # were inexplicably not being populated.
20
+ it 'properly loads results of multiple classes that have the same primary key' do
21
+ Post.reset!
22
+ Namespaced::Comment.reset!
23
+ results = [Post.new, Namespaced::Comment.new]
24
+ stub_results(*results)
25
+ session.search(Post, Namespaced::Comment).results.should == results
26
+ end
27
+
18
28
  if ENV['USE_WILL_PAGINATE']
19
29
 
20
30
  it 'should return search total as attribute of results if pagination is provided' do
@@ -5,6 +5,13 @@ class MockRecord
5
5
 
6
6
  attr_reader :id
7
7
 
8
+ class <<self
9
+ def reset!
10
+ IDS[name.to_sym] = 0
11
+ INSTANCES[name.to_sym] = {}
12
+ end
13
+ end
14
+
8
15
  def initialize(attrs = {})
9
16
  attrs.each_pair do |name, value|
10
17
  send(:"#{name}=", value)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outoftime-sunspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-08-13 00:00:00 -07:00
15
+ date: 2009-08-21 00:00:00 -07:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency