diff --git a/.travis.yml b/.travis.yml index 8e2cee577..11423d1f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,5 +13,6 @@ env: - DATABASE=mysql2 - DATABASE=postgresql gemfile: + - gemfiles/rails_3_0.gemfile - gemfiles/rails_3_1.gemfile - gemfiles/rails_3_2.gemfile diff --git a/Appraisals b/Appraisals index a02c238a8..bddc40150 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,14 @@ +appraise 'rails_3_0' do + gem 'rails', '~> 3.0.0' + gem 'mysql2', '~> 0.2.18' +end + appraise 'rails_3_1' do - gem 'rails', '~> 3.1.0' + gem 'rails', '~> 3.1.0' + gem 'mysql2', '~> 0.3.7' end appraise 'rails_3_2' do - gem 'rails', '~> 3.2.0' + gem 'rails', '~> 3.2.0' + gem 'mysql2', '~> 0.3.7' end diff --git a/Gemfile b/Gemfile index 7f4ea2928..40ce563f3 100644 --- a/Gemfile +++ b/Gemfile @@ -6,5 +6,9 @@ gem 'riddle', gemspec +gem 'combustion', + :git => 'git://github.com/freelancing-god/combustion.git', + :ref => 'bfd507f5f9ddf6c2ce5fe7c12532c12f009ac171' + gem 'pg', '~> 0.11.0', :platform => :ruby gem 'activerecord-jdbcpostgresql-adapter', '~> 1.1.3', :platform => :jruby diff --git a/README.textile b/README.textile index 74071ac1e..1665536fc 100644 --- a/README.textile +++ b/README.textile @@ -83,7 +83,6 @@ A list of what still needs to be implemented, in no particular order: * Attribute Updates * JRuby support * Abstract Inheritance support (maybe - not sure this is something many of people want). -* Rails 3.0 support * Searching from association contexts * Searching by specific indices * Matching many values on a single MVA attribute (:with_all) @@ -121,9 +120,9 @@ TS 3 is built for Sphinx 2.x only. You cannot use 1.10-beta, 0.9.9 or anything e h3. Rails Versions -Currently TS 3 is built to support Rails 3.1. 3.0 will almost certainly be added - not promising anything for Rails 2.3, and anything earlier than that definitely won't be supported. +Currently TS 3 is built to support Rails 3.0 or newer. Sinatra is not yet supported, but it will be. -Sinatra is not yet supported, but it will be. Merb support has been discontinued. +Rails 2.0 or earlier and Merb support have been discontinued. h3. Ruby Versions diff --git a/gemfiles/rails_3_0.gemfile b/gemfiles/rails_3_0.gemfile new file mode 100644 index 000000000..88e68d9d7 --- /dev/null +++ b/gemfiles/rails_3_0.gemfile @@ -0,0 +1,12 @@ +# This file was generated by Appraisal + +source :rubygems + +gem "riddle", :git=>"git://github.com/freelancing-god/riddle.git", :ref=>"6e4a109ae2caeae144bebb5b65c93a73b4d0ab60" +gem "combustion", :git=>"git://github.com/freelancing-god/combustion.git", :ref=>"bfd507f5f9ddf6c2ce5fe7c12532c12f009ac171" +gem "pg", "~> 0.11.0", :platform=>:ruby +gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby +gem "rails", "~> 3.0.0" +gem "mysql2", "~> 0.2.18" + +gemspec :path=>"../" \ No newline at end of file diff --git a/gemfiles/rails_3_1.gemfile b/gemfiles/rails_3_1.gemfile index e63aa579c..a723b9ae4 100644 --- a/gemfiles/rails_3_1.gemfile +++ b/gemfiles/rails_3_1.gemfile @@ -3,8 +3,10 @@ source :rubygems gem "riddle", :git=>"git://github.com/freelancing-god/riddle.git", :ref=>"6e4a109ae2caeae144bebb5b65c93a73b4d0ab60" +gem "combustion", :git=>"git://github.com/freelancing-god/combustion.git", :ref=>"bfd507f5f9ddf6c2ce5fe7c12532c12f009ac171" gem "pg", "~> 0.11.0", :platform=>:ruby gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby gem "rails", "~> 3.1.0" +gem "mysql2", "~> 0.3.7" gemspec :path=>"../" \ No newline at end of file diff --git a/gemfiles/rails_3_2.gemfile b/gemfiles/rails_3_2.gemfile index 4f598be0f..1a72bc4bf 100644 --- a/gemfiles/rails_3_2.gemfile +++ b/gemfiles/rails_3_2.gemfile @@ -3,8 +3,10 @@ source :rubygems gem "riddle", :git=>"git://github.com/freelancing-god/riddle.git", :ref=>"6e4a109ae2caeae144bebb5b65c93a73b4d0ab60" +gem "combustion", :git=>"git://github.com/freelancing-god/combustion.git", :ref=>"bfd507f5f9ddf6c2ce5fe7c12532c12f009ac171" gem "pg", "~> 0.11.0", :platform=>:ruby gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby gem "rails", "~> 3.2.0" +gem "mysql2", "~> 0.3.7" gemspec :path=>"../" \ No newline at end of file diff --git a/lib/thinking_sphinx/active_record/associations.rb b/lib/thinking_sphinx/active_record/associations.rb index e9027e76a..066035a58 100644 --- a/lib/thinking_sphinx/active_record/associations.rb +++ b/lib/thinking_sphinx/active_record/associations.rb @@ -1,4 +1,10 @@ class ThinkingSphinx::ActiveRecord::Associations + JoinDependency = if defined?(::ActiveRecord::Associations::JoinDependency) + ::ActiveRecord::Associations::JoinDependency + else + ::ActiveRecord::Associations::ClassMethods::JoinDependency + end + attr_reader :model def initialize(model) @@ -33,12 +39,12 @@ def join_values private def base - @base ||= ::ActiveRecord::Associations::JoinDependency.new model, [], [] + @base ||= JoinDependency.new model, [], [] end def join_for(stack) @joins[stack] ||= begin - ::ActiveRecord::Associations::JoinDependency::JoinAssociation.new( + JoinDependency::JoinAssociation.new( reflection_for(stack), base, parent_join_for(stack) ).tap { |join| join.join_type = Arel::OuterJoin } end @@ -61,6 +67,10 @@ def parent_join_for(stack) end def reflection_for(stack) - parent_for(stack).active_record.reflections[stack.last] + if parent_for(stack).respond_to?(:active_record) + parent_for(stack).active_record.reflections[stack.last] + else + parent_for(stack).joins.first.active_record.reflections[stack.last] + end end end diff --git a/spec/thinking_sphinx/active_record/associations_spec.rb b/spec/thinking_sphinx/active_record/associations_spec.rb index e76b66961..32bd4706f 100644 --- a/spec/thinking_sphinx/active_record/associations_spec.rb +++ b/spec/thinking_sphinx/active_record/associations_spec.rb @@ -1,6 +1,12 @@ require 'spec_helper' describe ThinkingSphinx::ActiveRecord::Associations do + JoinDependency = if defined?(::ActiveRecord::Associations::JoinDependency) + ::ActiveRecord::Associations::JoinDependency + else + ::ActiveRecord::Associations::ClassMethods::JoinDependency + end + let(:associations) { ThinkingSphinx::ActiveRecord::Associations.new model } let(:model) { model_double 'articles' } let(:base) { @@ -22,9 +28,8 @@ def model_double(table_name = nil) end before :each do - ActiveRecord::Associations::JoinDependency.stub :new => base - ActiveRecord::Associations::JoinDependency::JoinAssociation. - stub(:new).and_return(join, sub_join) + JoinDependency.stub :new => base + JoinDependency::JoinAssociation.stub(:new).and_return(join, sub_join) model.reflections[:user] = join.reflection join.stub :active_record => model_double @@ -33,18 +38,16 @@ def model_double(table_name = nil) describe '#add_join_to' do it "adds just one join for a stack with a single association" do - ActiveRecord::Associations::JoinDependency::JoinAssociation.unstub :new - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).with(join.reflection, base, join_base).once. - and_return(join) + JoinDependency::JoinAssociation.unstub :new + JoinDependency::JoinAssociation.should_receive(:new). + with(join.reflection, base, join_base).once.and_return(join) associations.add_join_to([:user]) end it "does not duplicate joins when given the same stack twice" do - ActiveRecord::Associations::JoinDependency::JoinAssociation.unstub :new - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).once.and_return(join) + JoinDependency::JoinAssociation.unstub :new + JoinDependency::JoinAssociation.should_receive(:new).once.and_return(join) associations.add_join_to([:user]) associations.add_join_to([:user]) @@ -52,21 +55,19 @@ def model_double(table_name = nil) context 'multiple joins' do it "adds two joins for a stack with two associations" do - ActiveRecord::Associations::JoinDependency::JoinAssociation.unstub :new - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).with(join.reflection, base, join_base).once. - and_return(join) - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).with(sub_join.reflection, base, join).once. - and_return(sub_join) + JoinDependency::JoinAssociation.unstub :new + JoinDependency::JoinAssociation.should_receive(:new). + with(join.reflection, base, join_base).once.and_return(join) + JoinDependency::JoinAssociation.should_receive(:new). + with(sub_join.reflection, base, join).once.and_return(sub_join) associations.add_join_to([:user, :posts]) end it "extends upon existing joins when given stacks where parts are already mapped" do - ActiveRecord::Associations::JoinDependency::JoinAssociation.unstub :new - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).twice.and_return(join, sub_join) + JoinDependency::JoinAssociation.unstub :new + JoinDependency::JoinAssociation.should_receive(:new).twice. + and_return(join, sub_join) associations.add_join_to([:user]) associations.add_join_to([:user, :posts]) @@ -131,10 +132,9 @@ def model_double(table_name = nil) end it "adds just one join for a stack with a single association" do - ActiveRecord::Associations::JoinDependency::JoinAssociation.unstub :new - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).with(join.reflection, base, join_base).once. - and_return(join) + JoinDependency::JoinAssociation.unstub :new + JoinDependency::JoinAssociation.should_receive(:new). + with(join.reflection, base, join_base).once.and_return(join) associations.alias_for([:user]) end @@ -144,9 +144,8 @@ def model_double(table_name = nil) end it "does not duplicate joins when given the same stack twice" do - ActiveRecord::Associations::JoinDependency::JoinAssociation.unstub :new - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).once.and_return(join) + JoinDependency::JoinAssociation.unstub :new + JoinDependency::JoinAssociation.should_receive(:new).once.and_return(join) associations.alias_for([:user]) associations.alias_for([:user]) @@ -154,13 +153,11 @@ def model_double(table_name = nil) context 'multiple joins' do it "adds two joins for a stack with two associations" do - ActiveRecord::Associations::JoinDependency::JoinAssociation.unstub :new - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).with(join.reflection, base, join_base).once. - and_return(join) - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).with(sub_join.reflection, base, join).once. - and_return(sub_join) + JoinDependency::JoinAssociation.unstub :new + JoinDependency::JoinAssociation.should_receive(:new). + with(join.reflection, base, join_base).once.and_return(join) + JoinDependency::JoinAssociation.should_receive(:new). + with(sub_join.reflection, base, join).once.and_return(sub_join) associations.alias_for([:user, :posts]) end @@ -170,9 +167,9 @@ def model_double(table_name = nil) end it "extends upon existing joins when given stacks where parts are already mapped" do - ActiveRecord::Associations::JoinDependency::JoinAssociation.unstub :new - ActiveRecord::Associations::JoinDependency::JoinAssociation. - should_receive(:new).twice.and_return(join, sub_join) + JoinDependency::JoinAssociation.unstub :new + JoinDependency::JoinAssociation.should_receive(:new).twice. + and_return(join, sub_join) associations.alias_for([:user]) associations.alias_for([:user, :posts]) diff --git a/thinking-sphinx.gemspec b/thinking-sphinx.gemspec index 30ab51271..c2375aa70 100644 --- a/thinking-sphinx.gemspec +++ b/thinking-sphinx.gemspec @@ -21,13 +21,13 @@ Gem::Specification.new do |s| } s.require_paths = ['lib'] - s.add_runtime_dependency 'activerecord', '>= 3.1.0' + s.add_runtime_dependency 'activerecord', '>= 3.0.0' s.add_runtime_dependency 'builder', '>= 2.1.2' - s.add_runtime_dependency 'mysql2', '>= 0.3.7' + s.add_runtime_dependency 'mysql2', '>= 0.2.18' # s.add_runtime_dependency 'riddle', '>= 1.5.0' s.add_development_dependency 'appraisal', '~> 0.4.0' - s.add_development_dependency 'combustion', '~> 0.3.1' + # s.add_development_dependency 'combustion', '~> 0.3.1' s.add_development_dependency 'database_cleaner', '~> 0.7.1' s.add_development_dependency 'rspec', '~> 2.6.0' end