Permalink
Browse files

Fix ThinkingSphinx::Context#load_models to work again with Rails 3.2.…

…9 in case subdirectories exist.
  • Loading branch information...
1 parent fa47069 commit 023e3bf7977204e4fd2f511ceab0bff3c89db7ec @kenn kenn committed Nov 19, 2012
Showing with 10 additions and 5 deletions.
  1. +6 −2 lib/thinking_sphinx/context.rb
  2. +4 −3 spec/thinking_sphinx/context_spec.rb
@@ -62,9 +62,13 @@ def load_models
begin
camelized_model.constantize
- rescue LoadError
+ rescue LoadError, NameError
# Make sure that STI subclasses in subfolders are loaded.
- model_name.gsub!(/.*[\/\\]/, '').nil? ? next : retry
+ if camelized_model.gsub!(/.+::/, '').nil?
+ STDERR.puts "ThinkingSphinx: error loading #{file}"
+ else
+ retry
+ end
rescue Exception => err
STDERR.puts "Warning: Error loading #{file}:"
STDERR.puts err.message
@@ -34,16 +34,17 @@
it "should report name errors but not raise them" do
class_name.stub(:constantize).and_raise(NameError)
STDERR.stub!(:puts => '')
- STDERR.should_receive(:puts).with('Warning: Error loading a.rb:')
+ STDERR.should_receive(:puts).with('ThinkingSphinx: error loading a.rb')
lambda {
ts_context.prepare
}.should_not raise_error
end
- it "should retry if the first load fails and contains a directory" do
- model_name_lower.should_receive(:gsub!).twice.and_return(true, nil)
+ it "should report load errors but not raise them" do
class_name.stub(:constantize).and_raise(LoadError)
+ STDERR.stub!(:puts => '')
+ STDERR.should_receive(:puts).with('ThinkingSphinx: error loading a.rb')
lambda {
ts_context.prepare

0 comments on commit 023e3bf

Please sign in to comment.