Skip to content

Commit ebe055f

Browse files
author
Mat Brown
committed
Fix sunspot options for inheritence
1 parent 9fff510 commit ebe055f

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

lib/sunspot/rails/session_proxy.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@ class SessionProxy
66
class <<self
77
def instance
88
synchronize do
9-
@instance ||= new
9+
@instance ||=
10+
begin
11+
configuration = Sunspot::Rails::Configuration.new
12+
if configuration.has_master?
13+
new(configuration)
14+
else
15+
session = Sunspot::Session.new
16+
session.config.solr.url = URI::HTTP.build(
17+
:host => configuration.hostname,
18+
:port => configuration.port,
19+
:path => configuration.path
20+
).to_s
21+
session
22+
end
23+
end
1024
end
1125
end
1226

@@ -24,8 +38,8 @@ def reset!
2438
:remove_by_id!, :remove_all, :remove_all!, :dirty?, :commit_if_dirty, :batch,
2539
:to => :write_session
2640

27-
def initialize
28-
@configuration = Sunspot::Rails::Configuration.new
41+
def initialize(configuration)
42+
@configuration = configuration
2943
end
3044

3145
private

lib/sunspot/rails/util.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ def sunspot_options
1010

1111
def index_relevant_attribute_changed?( object )
1212
class_key = object.class.to_s.underscore.to_sym
13-
ignore_attributes = (sunspot_options[class_key][:ignore_attribute_changes_of] || [])
13+
ignore_attributes = sunspot_options_for(object.class)[:ignore_attribute_changes_of] || []
1414
!(object.changes.symbolize_keys.keys - ignore_attributes).blank?
1515
end
16-
16+
17+
private
18+
19+
def sunspot_options_for(clazz)
20+
class_key = clazz.to_s.underscore.to_sym
21+
if options = sunspot_options[class_key]
22+
options
23+
elsif superclass = clazz.superclass
24+
sunspot_options_for(superclass)
25+
end
26+
end
1727
end
1828
end
1929
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class PhotoPostWithAuto < PostWithAuto
2+
end

spec/util_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@
1212
@post.should_receive(:changes).and_return(:updated_at => Date.tomorrow)
1313
Sunspot::Rails::Util.index_relevant_attribute_changed?(@post).should == false
1414
end
15+
16+
it "should know about relevant index attributes with subclasses" do
17+
@post = PhotoPostWithAuto.new
18+
@post.should_receive(:changes).and_return(:title => 'new_title')
19+
Sunspot::Rails::Util.index_relevant_attribute_changed?(@post).should == true
20+
end
1521
end

0 commit comments

Comments
 (0)