Skip to content

Commit

Permalink
Tentative Rails 3.0 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Jan 25, 2012
1 parent 2203058 commit 9d7bf72
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 48 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 9 additions & 2 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions gemfiles/rails_3_0.gemfile
Original file line number Diff line number Diff line change
@@ -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=>"../"
2 changes: 2 additions & 0 deletions gemfiles/rails_3_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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=>"../"
2 changes: 2 additions & 0 deletions gemfiles/rails_3_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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=>"../"
16 changes: 13 additions & 3 deletions lib/thinking_sphinx/active_record/associations.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
71 changes: 34 additions & 37 deletions spec/thinking_sphinx/active_record/associations_spec.rb
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
Expand All @@ -33,40 +38,36 @@ 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])
end

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])
Expand Down Expand Up @@ -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
Expand All @@ -144,23 +144,20 @@ 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])
end

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
Expand All @@ -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])
Expand Down
6 changes: 3 additions & 3 deletions thinking-sphinx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9d7bf72

Please sign in to comment.