spec/unit/thinking_sphinx_spec.rb in dpickett-thinking-sphinx-1.1.12 vs spec/unit/thinking_sphinx_spec.rb in dpickett-thinking-sphinx-1.1.23
- old
+ new
@@ -49,10 +49,26 @@
ThinkingSphinx.updates_enabled?.should be_false
ThinkingSphinx.updates_enabled = true
ThinkingSphinx.updates_enabled?.should be_true
end
+ it "should always say Sphinx is running if flagged as being on a remote machine" do
+ ThinkingSphinx.remote_sphinx = true
+ ThinkingSphinx.stub_method(:sphinx_running_by_pid? => false)
+
+ ThinkingSphinx.sphinx_running?.should be_true
+ end
+
+ it "should actually pay attention to Sphinx if not on a remote machine" do
+ ThinkingSphinx.remote_sphinx = false
+ ThinkingSphinx.stub_method(:sphinx_running_by_pid? => false)
+ ThinkingSphinx.sphinx_running?.should be_false
+
+ ThinkingSphinx.stub_method(:sphinx_running_by_pid? => true)
+ ThinkingSphinx.sphinx_running?.should be_true
+ end
+
describe "use_group_by_shortcut? method" do
before :each do
adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
pending "No MySQL"
@@ -103,16 +119,18 @@
ThinkingSphinx.use_group_by_shortcut?.should be_false
end
describe "if not using MySQL" do
before :each do
- adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :PostgreSQLAdapter
+ adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
pending "No PostgreSQL"
return
end
- @connection = ::ActiveRecord::ConnectionAdapters.const_get(adapter).stub_instance(
+
+ @connection = stub(adapter).as_null_object
+ @connection.stub!(
:select_all => true,
:config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
)
::ActiveRecord::Base.stub_method(
:connection => @connection
@@ -122,12 +140,12 @@
it "should return false" do
ThinkingSphinx.use_group_by_shortcut?.should be_false
end
it "should not call select_all" do
- ThinkingSphinx.use_group_by_shortcut?
+ @connection.should_not_receive(:select_all)
- @connection.should_not have_received(:select_all)
+ ThinkingSphinx.use_group_by_shortcut?
end
end
end
end