diff --git a/.travis.yml b/.travis.yml index fa3722781..edf0f7329 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,18 +6,16 @@ rvm: - jruby-19mode before_install: - gem update --system + - gem install bundler before_script: - "mysql -e 'create database thinking_sphinx;' > /dev/null" - "psql -c 'create database thinking_sphinx;' -U postgres >/dev/null" + - bundle exec appraisal install +script: bundle exec appraisal rspec env: - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.0.10/bin/ SPHINX_VERSION=2.0.10 - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.0.10/bin/ SPHINX_VERSION=2.0.10 - - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.1.8/bin/ SPHINX_VERSION=2.1.8 - - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.1.8/bin/ SPHINX_VERSION=2.1.8 - - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.2.2-beta/bin/ SPHINX_VERSION=2.2.2 - - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.2.2-beta/bin/ SPHINX_VERSION=2.2.2 -gemfile: - - gemfiles/rails_3_2.gemfile - - gemfiles/rails_4_0.gemfile - - gemfiles/rails_4_1.gemfile - - gemfiles/rails_4_2.gemfile + - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.1.9/bin/ SPHINX_VERSION=2.1.9 + - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.1.9/bin/ SPHINX_VERSION=2.1.9 + - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.2.6/bin/ SPHINX_VERSION=2.2.6 + - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.2.6/bin/ SPHINX_VERSION=2.2.6 diff --git a/HISTORY b/HISTORY index e1d552b9e..faa402998 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,16 @@ +2015-06-01: 3.1.4 +* [FIX] Kaminari expects prev_page to be available. +* [CHANGE] Add a contributor code of conduct. +* [FEATURE] Add JSON as a Sphinx type for attributes (Daniel Vandersluis). +* [CHANGE] Remove polymorphic association and HABTM query support (when related to Thinking Sphinx) when ActiveRecord 3.2 is involved. +* [FIX] Don't try to delete guard files if they don't exist (@exAspArk). +* [FEATURE] minimal_group_by? can now be set in config/thinking_sphinx.yml to automatically apply to all index definitions. +* [FIX] Handle database settings reliably, now that ActiveRecord 4.2 uses strings all the time. +* [FIX] More consistent with escaping table names. +* [CHANGE] Remove default charset_type - no longer required for Sphinx 2.2. +* [FIX] Bug fix for association creation (with polymophic fields/attributes). +* [CHANGE] Removing sql_query_info setting, as it's no longer used by Sphinx (nor is it actually used by Thinking Sphinx). + 2015-01-21: 3.1.3 * [CHANGE] Log excerpt SphinxQL queries just like the search queries. * [CHANGE] Load Railtie if Rails::Railtie is defined, instead of just Rails (Andrew Cone). diff --git a/README.textile b/README.textile index e2a8c16bd..97c759b25 100644 --- a/README.textile +++ b/README.textile @@ -1,11 +1,12 @@ h1. Thinking Sphinx -Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v3.1.3. +Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v3.1.4. h2. Upgrading Please refer to the release notes for any changes you need to make when upgrading: +* "v3.1.4":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.4 * "v3.1.3":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.3 * "v3.1.2":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.2 * "v3.1.1":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.1 @@ -18,9 +19,9 @@ h2. Installation It's a gem, so install it like you would any other gem. You will also need to specify the mysql2 gem if you're using MRI, or jdbc-mysql if you're using JRuby: -
gem 'mysql2', '~> 0.3.13', :platform => :ruby
-gem 'jdbc-mysql', '~> 5.1.28', :platform => :jruby
-gem 'thinking-sphinx', '~> 3.1.3'
+gem 'mysql2', '~> 0.3.18', :platform => :ruby
+gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
+gem 'thinking-sphinx', '~> 3.1.4'
The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
@@ -44,6 +45,8 @@ h3. Rails and ActiveRecord
Currently Thinking Sphinx 3 is built to support Rails/ActiveRecord 3.2 or newer. If you're using Sinatra and ActiveRecord instead of Rails, that's fine - just make sure you add the @:require => 'thinking_sphinx/sinatra'@ option when listing @thinking-sphinx@ in your Gemfile.
+Please note that if you're referring to polymorphic associations in your index definitions, you'll want to be using Rails/ActiveRecord 4.0 or newer. Supporting polymorphic associations and Rails/ActiveRecord 3.2 is problematic, and likely will not be addressed in the future.
+
If you want ActiveRecord 3.1 support, then refer to the 3.0.x releases of Thinking Sphinx. Anything older than that, then you're stuck with Thinking Sphinx v2.x (for Rails/ActiveRecord 3.0) or v1.x (Rails 2.3). Please note that these older versions are no longer actively supported.
h3. Ruby
@@ -58,6 +61,8 @@ MySQL 5.x and Postgres 8.4 or better are supported.
h2. Contributing
+Please note that this project now has a "Contributor Code of Conduct":http://contributor-covenant.org/version/1/0/0/. By participating in this project you agree to abide by its terms.
+
To contribute, clone this repository and have a good look through the specs - you'll notice the distinction between acceptance tests that actually use Sphinx and go through the full stack, and unit tests (everything else) which use liberal test doubles to ensure they're only testing the behaviour of the class in question. I've found this leads to far better code design.
All development is done on the @develop@ branch; please base any pull requests off of that branch. Please write the tests and then the code to get them passing, and send through a pull request.
diff --git a/gemfiles/rails_3_2.gemfile b/gemfiles/rails_3_2.gemfile
index 6e8bfa3bf..56b8bfef4 100644
--- a/gemfiles/rails_3_2.gemfile
+++ b/gemfiles/rails_3_2.gemfile
@@ -2,10 +2,10 @@
source "https://rubygems.org"
-gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
-gem "pg", "~> 0.16.0", :platform=>:ruby
-gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby
-gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby
+gem "mysql2", "~> 0.3.12b4", :platform => :ruby
+gem "pg", "~> 0.16.0", :platform => :ruby
+gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
+gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
gem "rails", "~> 3.2.21"
-gemspec :path=>"../"
\ No newline at end of file
+gemspec :path => "../"
diff --git a/gemfiles/rails_4_0.gemfile b/gemfiles/rails_4_0.gemfile
index 7b8dfd189..d1ed7fd27 100644
--- a/gemfiles/rails_4_0.gemfile
+++ b/gemfiles/rails_4_0.gemfile
@@ -2,10 +2,10 @@
source "https://rubygems.org"
-gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
-gem "pg", "~> 0.16.0", :platform=>:ruby
-gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby
-gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby
+gem "mysql2", "~> 0.3.12b4", :platform => :ruby
+gem "pg", "~> 0.16.0", :platform => :ruby
+gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
+gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
gem "rails", "~> 4.0.12"
-gemspec :path=>"../"
\ No newline at end of file
+gemspec :path => "../"
diff --git a/gemfiles/rails_4_1.gemfile b/gemfiles/rails_4_1.gemfile
index f79b9af5d..46c56fe9f 100644
--- a/gemfiles/rails_4_1.gemfile
+++ b/gemfiles/rails_4_1.gemfile
@@ -2,10 +2,10 @@
source "https://rubygems.org"
-gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
-gem "pg", "~> 0.16.0", :platform=>:ruby
-gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby
-gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby
+gem "mysql2", "~> 0.3.12b4", :platform => :ruby
+gem "pg", "~> 0.16.0", :platform => :ruby
+gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
+gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
gem "rails", "~> 4.1.8"
-gemspec :path=>"../"
\ No newline at end of file
+gemspec :path => "../"
diff --git a/gemfiles/rails_4_2.gemfile b/gemfiles/rails_4_2.gemfile
index 7bf8eb808..8ada8d7a4 100644
--- a/gemfiles/rails_4_2.gemfile
+++ b/gemfiles/rails_4_2.gemfile
@@ -2,10 +2,10 @@
source "https://rubygems.org"
-gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
-gem "pg", "~> 0.16.0", :platform=>:ruby
-gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby
-gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby
+gem "mysql2", "~> 0.3.12b4", :platform => :ruby
+gem "pg", "~> 0.16.0", :platform => :ruby
+gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
+gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
gem "rails", "~> 4.2.0"
-gemspec :path=>"../"
\ No newline at end of file
+gemspec :path => "../"
diff --git a/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb b/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
index d253f111c..d33980d52 100644
--- a/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
+++ b/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
@@ -7,7 +7,8 @@ class ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter
:string => :string,
:bigint => :bigint,
:ordinal => :str2ordinal,
- :wordcount => :str2wordcount
+ :wordcount => :str2wordcount,
+ :json => :json
}
def initialize(attribute, source)
diff --git a/lib/thinking_sphinx/active_record/column_sql_presenter.rb b/lib/thinking_sphinx/active_record/column_sql_presenter.rb
index c0b47f54c..145a53c00 100644
--- a/lib/thinking_sphinx/active_record/column_sql_presenter.rb
+++ b/lib/thinking_sphinx/active_record/column_sql_presenter.rb
@@ -13,7 +13,9 @@ def with_table
return __name if string?
return nil unless exists?
- "#{associations.alias_for(__stack)}.#{adapter.quote __name}"
+ quoted_table = escape_table? ? adapter.quote(table) : table
+
+ "#{quoted_table}.#{adapter.quote __name}"
end
private
@@ -22,6 +24,10 @@ def with_table
delegate :__stack, :__name, :string?, :to => :column
+ def escape_table?
+ table[/[`"]/].nil?
+ end
+
def exists?
path.model.column_names.include?(column.__name.to_s)
rescue Joiner::AssociationNotFound
@@ -31,4 +37,12 @@ def exists?
def path
Joiner::Path.new model, column.__stack
end
+
+ def table
+ associations.alias_for __stack
+ end
+
+ def version
+ ActiveRecord::VERSION
+ end
end
diff --git a/lib/thinking_sphinx/active_record/filter_reflection.rb b/lib/thinking_sphinx/active_record/filter_reflection.rb
index d2dff4845..54e3785cd 100644
--- a/lib/thinking_sphinx/active_record/filter_reflection.rb
+++ b/lib/thinking_sphinx/active_record/filter_reflection.rb
@@ -6,8 +6,9 @@ class ThinkingSphinx::ActiveRecord::FilterReflection
def self.call(reflection, name, class_name)
filter = new(reflection, class_name)
klass = reflection.class
+ arity = klass.instance_method(:initialize).arity
- if defined?(ActiveRecord::Reflection::MacroReflection)
+ if defined?(ActiveRecord::Reflection::MacroReflection) && arity == 4
klass.new name, filter.scope, filter.options, reflection.active_record
elsif reflection.respond_to?(:scope)
klass.new reflection.macro, name, filter.scope, filter.options,
diff --git a/lib/thinking_sphinx/active_record/interpreter.rb b/lib/thinking_sphinx/active_record/interpreter.rb
index 25652d344..fd8dfec60 100644
--- a/lib/thinking_sphinx/active_record/interpreter.rb
+++ b/lib/thinking_sphinx/active_record/interpreter.rb
@@ -39,10 +39,10 @@ def sanitize_sql(*arguments)
end
def set_database(hash_or_key)
- configuration = hash_or_key.is_a?(::Hash) ? hash_or_key.symbolize_keys :
+ configuration = hash_or_key.is_a?(::Hash) ? hash_or_key :
::ActiveRecord::Base.configurations[hash_or_key.to_s]
- __source.set_database_settings configuration
+ __source.set_database_settings configuration.symbolize_keys
end
def set_property(properties)
diff --git a/lib/thinking_sphinx/active_record/sql_builder.rb b/lib/thinking_sphinx/active_record/sql_builder.rb
index f611bb477..974f270de 100644
--- a/lib/thinking_sphinx/active_record/sql_builder.rb
+++ b/lib/thinking_sphinx/active_record/sql_builder.rb
@@ -16,10 +16,6 @@ def sql_query_range
statement.to_query_range_relation.to_sql
end
- def sql_query_info
- statement.to_query_info_relation.to_sql
- end
-
def sql_query_pre
query.to_query
end
@@ -96,10 +92,6 @@ def document_id
"#{column} AS #{quoted_alias}"
end
- def reversed_document_id
- "($id - #{source.offset}) / #{config.indices.count}"
- end
-
def range_condition
condition = []
condition << "#{quoted_primary_key} BETWEEN $start AND $end" unless source.disable_range?
diff --git a/lib/thinking_sphinx/active_record/sql_builder/statement.rb b/lib/thinking_sphinx/active_record/sql_builder/statement.rb
index 0c468cfbd..71d7e15eb 100644
--- a/lib/thinking_sphinx/active_record/sql_builder/statement.rb
+++ b/lib/thinking_sphinx/active_record/sql_builder/statement.rb
@@ -20,12 +20,6 @@ def to_query_range_relation
scope
end
- def to_query_info_relation
- filter_by_query_info
-
- scope
- end
-
def to_query_pre
filter_by_query_pre
@@ -49,10 +43,6 @@ def filter_by_query_range
)
end
- def filter_by_query_info
- @scope = scope.where("#{quoted_primary_key} = #{reversed_document_id}")
- end
-
def filter_by_scopes
scope_by_select
scope_by_where_clause
@@ -140,10 +130,16 @@ def group_clause
builder.compose(
presenters_to_group(field_presenters),
presenters_to_group(attribute_presenters)
- ) unless source.options[:minimal_group_by?]
+ ) unless minimal_group_by?
builder.compose(groupings).separated
end
+
+ def minimal_group_by?
+ source.options[:minimal_group_by?] ||
+ config.settings['minimal_group_by?'] ||
+ config.settings['minimal_group_by']
+ end
end
end
end
diff --git a/lib/thinking_sphinx/active_record/sql_source.rb b/lib/thinking_sphinx/active_record/sql_source.rb
index 6ac56227a..faa1fe6eb 100644
--- a/lib/thinking_sphinx/active_record/sql_source.rb
+++ b/lib/thinking_sphinx/active_record/sql_source.rb
@@ -118,7 +118,6 @@ def build_sql_fields
def build_sql_query
@sql_query = builder.sql_query
@sql_query_range ||= builder.sql_query_range
- @sql_query_info ||= builder.sql_query_info
@sql_query_pre += builder.sql_query_pre
@sql_query_post_index += builder.sql_query_post_index
end
diff --git a/lib/thinking_sphinx/core/index.rb b/lib/thinking_sphinx/core/index.rb
index 0a9d1ad22..cee129e65 100644
--- a/lib/thinking_sphinx/core/index.rb
+++ b/lib/thinking_sphinx/core/index.rb
@@ -10,7 +10,6 @@ module ThinkingSphinx::Core::Index
def initialize(reference, options = {})
@reference = reference.to_sym
@docinfo = :extern
- @charset_type = 'utf-8'
@options = options
@offset = config.next_offset(options[:offset_as] || reference)
@type = 'plain'
diff --git a/lib/thinking_sphinx/guard/file.rb b/lib/thinking_sphinx/guard/file.rb
index a1509571c..9d48a681a 100644
--- a/lib/thinking_sphinx/guard/file.rb
+++ b/lib/thinking_sphinx/guard/file.rb
@@ -21,6 +21,6 @@ def path
end
def unlock
- FileUtils.rm path
+ FileUtils.rm(path) if locked?
end
end
diff --git a/lib/thinking_sphinx/masks/pagination_mask.rb b/lib/thinking_sphinx/masks/pagination_mask.rb
index c215e3d75..fe55b0a48 100644
--- a/lib/thinking_sphinx/masks/pagination_mask.rb
+++ b/lib/thinking_sphinx/masks/pagination_mask.rb
@@ -37,6 +37,8 @@ def previous_page
search.current_page == 1 ? nil : search.current_page - 1
end
+ alias_method :prev_page, :previous_page
+
def total_entries
search.meta['total_found'].to_i
end
diff --git a/spec/acceptance/big_integers_spec.rb b/spec/acceptance/big_integers_spec.rb
index 2106aaa98..841e4142a 100644
--- a/spec/acceptance/big_integers_spec.rb
+++ b/spec/acceptance/big_integers_spec.rb
@@ -50,7 +50,7 @@
context 'with Real-Time' do
it 'handles large 32 bit integers with an offset multiplier' do
product = Product.create! :name => "Widget"
- product.update_attribute :id, 980190962
+ product.update_attributes :id => 980190962
expect(
Product.search('widget', :indices => ['product_core']).to_a
).to eq([product])
diff --git a/spec/acceptance/excerpts_spec.rb b/spec/acceptance/excerpts_spec.rb
index abc721fc0..983ec0588 100644
--- a/spec/acceptance/excerpts_spec.rb
+++ b/spec/acceptance/excerpts_spec.rb
@@ -23,7 +23,7 @@
search.first.excerpts.title.
should == 'Война и миръ'
- end
+ end if ENV['SPHINX_VERSION'].try :[], /2.2.\d/
it "does not include class names in excerpts" do
Book.create! :title => 'The Graveyard Book'
diff --git a/spec/acceptance/specifying_sql_spec.rb b/spec/acceptance/specifying_sql_spec.rb
index 234bb546a..255dfb170 100644
--- a/spec/acceptance/specifying_sql_spec.rb
+++ b/spec/acceptance/specifying_sql_spec.rb
@@ -125,8 +125,8 @@
query = index.sources.first.sql_query
query.should match(/LEFT OUTER JOIN .articles. ON .articles.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Article'/)
query.should match(/LEFT OUTER JOIN .books. ON .books.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Book'/)
- query.should match(/articles\..title., books\..title./)
- end
+ query.should match(/.articles.\..title., .books.\..title./)
+ end if ActiveRecord::VERSION::MAJOR > 3
it "concatenates references that have column" do
index = ThinkingSphinx::ActiveRecord::Index.new(:event)
@@ -139,8 +139,8 @@
query = index.sources.first.sql_query
query.should match(/LEFT OUTER JOIN .articles. ON .articles.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Article'/)
query.should_not match(/articles\..title., users\..title./)
- query.should match(/articles\..title./)
- end
+ query.should match(/.articles.\..title./)
+ end if ActiveRecord::VERSION::MAJOR > 3
it "respects deeper associations through polymorphic joins" do
index = ThinkingSphinx::ActiveRecord::Index.new(:event)
@@ -153,9 +153,9 @@
query = index.sources.first.sql_query
query.should match(/LEFT OUTER JOIN .articles. ON .articles.\..id. = .events.\..eventable_id. AND .events.\..eventable_type. = 'Article'/)
query.should match(/LEFT OUTER JOIN .users. ON .users.\..id. = .articles.\..user_id./)
- query.should match(/users\..name./)
+ query.should match(/.users.\..name./)
end
-end
+end if ActiveRecord::VERSION::MAJOR > 3
describe 'separate queries for MVAs' do
let(:index) { ThinkingSphinx::ActiveRecord::Index.new(:article) }
@@ -244,7 +244,7 @@
declaration.should == 'uint genre_ids from query'
query.should match(/^SELECT .books_genres.\..book_id. \* #{count} \+ #{source.offset} AS .id., .books_genres.\..genre_id. AS .genre_ids. FROM .books_genres.\s?$/)
- end
+ end if ActiveRecord::VERSION::MAJOR > 3
it "generates an appropriate range SQL queries for an MVA" do
index.definition_block = Proc.new {
@@ -297,7 +297,7 @@
declaration.should == 'uint genre_ids from ranged-query'
query.should match(/^SELECT .books_genres.\..book_id. \* #{count} \+ #{source.offset} AS .id., .books_genres.\..genre_id. AS .genre_ids. FROM .books_genres. WHERE \(.books_genres.\..book_id. BETWEEN \$start AND \$end\)$/)
range.should match(/^SELECT MIN\(.books_genres.\..book_id.\), MAX\(.books_genres.\..book_id.\) FROM .books_genres.$/)
- end
+ end if ActiveRecord::VERSION::MAJOR > 3
it "respects custom SQL snippets as the query value" do
index.definition_block = Proc.new {
diff --git a/spec/thinking_sphinx/active_record/attribute/type_spec.rb b/spec/thinking_sphinx/active_record/attribute/type_spec.rb
index 6be290190..19a6eeb06 100644
--- a/spec/thinking_sphinx/active_record/attribute/type_spec.rb
+++ b/spec/thinking_sphinx/active_record/attribute/type_spec.rb
@@ -139,6 +139,12 @@ class Attribute; end
type.type.should == :bigint
end
+ it "detects JSON" do
+ db_column.stub :type => :json
+
+ type.type.should == :json
+ end
+
it "respects provided type setting" do
attribute.options[:type] = :timestamp
diff --git a/spec/thinking_sphinx/active_record/filter_reflection_spec.rb b/spec/thinking_sphinx/active_record/filter_reflection_spec.rb
index 0bef35593..148182c8c 100644
--- a/spec/thinking_sphinx/active_record/filter_reflection_spec.rb
+++ b/spec/thinking_sphinx/active_record/filter_reflection_spec.rb
@@ -7,7 +7,9 @@
:foreign_type => :foo_type, :class => reflection_klass) }
let(:options) { {:polymorphic => true} }
let(:filtered_reflection) { double 'filtered reflection' }
- let(:reflection_klass) { double :new => filtered_reflection }
+ let(:reflection_klass) { double :new => filtered_reflection,
+ :instance_method => initialize_method }
+ let(:initialize_method) { double :arity => 4 }
before :each do
reflection.active_record.stub_chain(:connection, :quote_column_name).
diff --git a/spec/thinking_sphinx/active_record/interpreter_spec.rb b/spec/thinking_sphinx/active_record/interpreter_spec.rb
index 3b497ff74..6559055d4 100644
--- a/spec/thinking_sphinx/active_record/interpreter_spec.rb
+++ b/spec/thinking_sphinx/active_record/interpreter_spec.rb
@@ -223,7 +223,7 @@
source.stub :set_database_settings => true
stub_const 'ActiveRecord::Base',
- double(:configurations => {'other' => {:baz => :qux}})
+ double(:configurations => {'other' => {'baz' => 'qux'}})
end
it "sends through a hash if provided" do
@@ -233,13 +233,13 @@
end
it "finds the environment settings if given a string key" do
- source.should_receive(:set_database_settings).with(:baz => :qux)
+ source.should_receive(:set_database_settings).with(:baz => 'qux')
instance.set_database 'other'
end
it "finds the environment settings if given a symbol key" do
- source.should_receive(:set_database_settings).with(:baz => :qux)
+ source.should_receive(:set_database_settings).with(:baz => 'qux')
instance.set_database :other
end
diff --git a/spec/thinking_sphinx/active_record/sql_builder_spec.rb b/spec/thinking_sphinx/active_record/sql_builder_spec.rb
index c7f853b0f..7cdda386b 100644
--- a/spec/thinking_sphinx/active_record/sql_builder_spec.rb
+++ b/spec/thinking_sphinx/active_record/sql_builder_spec.rb
@@ -415,6 +415,55 @@
end
end
+ context 'group by shortcut in global configuration' do
+ before :each do
+ config.settings['minimal_group_by'] = true
+ end
+
+ it "groups by the primary key" do
+ relation.should_receive(:group) do |string|
+ string.should match(/"users"."id"/)
+ relation
+ end
+
+ builder.sql_query
+ end
+
+ it "does not group by fields" do
+ source.fields << double('field')
+
+ relation.should_receive(:group) do |string|
+ string.should_not match(/"name"/)
+ relation
+ end
+
+ builder.sql_query
+ end
+
+ it "does not group by attributes" do
+ source.attributes << double('attribute')
+ presenter.stub!(:to_group => '"created_at"')
+
+ relation.should_receive(:group) do |string|
+ string.should_not match(/"created_at"/)
+ relation
+ end
+
+ builder.sql_query
+ end
+
+ it "groups by source groupings" do
+ source.groupings << '"latitude"'
+
+ relation.should_receive(:group) do |string|
+ string.should match(/"latitude"/)
+ relation
+ end
+
+ builder.sql_query
+ end
+ end
+
context 'STI model' do
before :each do
model.column_names << 'type'
@@ -469,22 +518,6 @@
end
end
- describe 'sql_query_info' do
- it "filters on the reversed document id" do
- relation.should_receive(:where).
- with("`users`.`id` = ($id - #{source.offset}) / #{indices.count}").
- and_return(relation)
-
- builder.sql_query_info
- end
-
- it "returns the generated SQL query" do
- relation.stub(:to_sql).and_return('SELECT * FROM people WHERE id = $id')
-
- builder.sql_query_info.should == 'SELECT * FROM people WHERE id = $id'
- end
- end
-
describe 'sql_query_post_index' do
let(:processor) { double('processor', :reset_query => 'RESET DELTAS') }
diff --git a/spec/thinking_sphinx/active_record/sql_source_spec.rb b/spec/thinking_sphinx/active_record/sql_source_spec.rb
index b131033a6..2616707ac 100644
--- a/spec/thinking_sphinx/active_record/sql_source_spec.rb
+++ b/spec/thinking_sphinx/active_record/sql_source_spec.rb
@@ -186,14 +186,6 @@
source.sql_query_range.should == 'select 0, 10 from table'
end
- it "uses the builder's sql_query_info value" do
- builder.stub! :sql_query_info => 'select * from table where id = ?'
-
- source.render
-
- source.sql_query_info.should == 'select * from table where id = ?'
- end
-
it "appends the builder's sql_query_pre value" do
builder.stub! :sql_query_pre => ['Change Setting']
@@ -333,6 +325,15 @@
source.sql_attr_str2wordcount.should include('name')
end
+ it "adds json attributes to sql_attr_json" do
+ source.attributes << double('attribute')
+ presenter.stub :declaration => 'json', :collection_type => :json
+
+ source.render
+
+ source.sql_attr_json.should include('json')
+ end
+
it "adds relevant settings from thinking_sphinx.yml" do
config.settings['mysql_ssl_cert'] = 'foo.cert'
config.settings['morphology'] = 'stem_en' # should be ignored
diff --git a/thinking-sphinx.gemspec b/thinking-sphinx.gemspec
index 06a43ec62..890278281 100644
--- a/thinking-sphinx.gemspec
+++ b/thinking-sphinx.gemspec
@@ -3,11 +3,11 @@ $:.push File.expand_path('../lib', __FILE__)
Gem::Specification.new do |s|
s.name = 'thinking-sphinx'
- s.version = '3.1.3'
+ s.version = '3.1.4'
s.platform = Gem::Platform::RUBY
s.authors = ["Pat Allan"]
s.email = ["pat@freelancing-gods.com"]
- s.homepage = 'http://pat.github.io/thinking-sphinx/'
+ s.homepage = 'https://pat.github.io/thinking-sphinx/'
s.summary = 'A smart wrapper over Sphinx for ActiveRecord'
s.description = %Q{An intelligent layer for ActiveRecord (via Rails and Sinatra) for the Sphinx full-text search tool.}
s.license = 'MIT'
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'innertube', '>= 1.0.2'
s.add_runtime_dependency 'riddle', '>= 1.5.11'
- s.add_development_dependency 'appraisal', '~> 0.5.2'
+ s.add_development_dependency 'appraisal', '~> 1.0.2'
s.add_development_dependency 'combustion', '~> 0.4.0'
s.add_development_dependency 'database_cleaner', '~> 1.2.0'
s.add_development_dependency 'rspec', '~> 2.13.0'