From 4bd16f053847f2efe347ebda9136ef2233ee0d2c Mon Sep 17 00:00:00 2001 From: hukl Date: Tue, 28 Apr 2009 00:15:53 +0200 Subject: added thinking_sphinx plugin for fulltext search on nodes and heads --- .../spec/unit/thinking_sphinx_spec.rb | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx_spec.rb (limited to 'vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx_spec.rb') diff --git a/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx_spec.rb b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx_spec.rb new file mode 100644 index 0000000..375e158 --- /dev/null +++ b/vendor/plugins/thinking-sphinx/spec/unit/thinking_sphinx_spec.rb @@ -0,0 +1,133 @@ +require 'spec/spec_helper' + +describe ThinkingSphinx do + it "should define indexes by default" do + ThinkingSphinx.define_indexes?.should be_true + end + + it "should disable index definition" do + ThinkingSphinx.define_indexes = false + ThinkingSphinx.define_indexes?.should be_false + end + + it "should enable index definition" do + ThinkingSphinx.define_indexes = false + ThinkingSphinx.define_indexes?.should be_false + ThinkingSphinx.define_indexes = true + ThinkingSphinx.define_indexes?.should be_true + end + + it "should index deltas by default" do + ThinkingSphinx.deltas_enabled = nil + ThinkingSphinx.deltas_enabled?.should be_true + end + + it "should disable delta indexing" do + ThinkingSphinx.deltas_enabled = false + ThinkingSphinx.deltas_enabled?.should be_false + end + + it "should enable delta indexing" do + ThinkingSphinx.deltas_enabled = false + ThinkingSphinx.deltas_enabled?.should be_false + ThinkingSphinx.deltas_enabled = true + ThinkingSphinx.deltas_enabled?.should be_true + end + + it "should update indexes by default" do + ThinkingSphinx.updates_enabled = nil + ThinkingSphinx.updates_enabled?.should be_true + end + + it "should disable index updating" do + ThinkingSphinx.updates_enabled = false + ThinkingSphinx.updates_enabled?.should be_false + end + + it "should enable index updating" do + ThinkingSphinx.updates_enabled = false + ThinkingSphinx.updates_enabled?.should be_false + ThinkingSphinx.updates_enabled = true + ThinkingSphinx.updates_enabled?.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" + return + end + + @connection = ::ActiveRecord::ConnectionAdapters.const_get(adapter).stub_instance( + :select_all => true, + :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'} + ) + ::ActiveRecord::Base.stub_method( + :connection => @connection + ) + end + + it "should return true if no ONLY_FULL_GROUP_BY" do + @connection.stub_method( + :select_all => {:a => "OTHER SETTINGS"} + ) + + ThinkingSphinx.use_group_by_shortcut?.should be_true + end + + it "should return true if NULL value" do + @connection.stub_method( + :select_all => {:a => nil} + ) + + ThinkingSphinx.use_group_by_shortcut?.should be_true + end + + it "should return false if ONLY_FULL_GROUP_BY is set" do + @connection.stub_method( + :select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"} + ) + + ThinkingSphinx.use_group_by_shortcut?.should be_false + end + + it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do + @connection.stub_method( + :select_all => { + :a => "OTHER SETTINGS", + :b => "ONLY_FULL_GROUP_BY" + } + ) + + ThinkingSphinx.use_group_by_shortcut?.should be_false + end + + describe "if not using MySQL" do + before :each do + 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( + :select_all => true, + :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'} + ) + ::ActiveRecord::Base.stub_method( + :connection => @connection + ) + end + + 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 have_received(:select_all) + end + end + end +end -- cgit v1.3