Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Get 1.1 working with AR 3.0 - 4.0

  • Loading branch information...
commit e3fa6577775df8c9d76f1bdaf78fface19f3def7 1 parent 42703dd
@ernie ernie authored
View
3  .travis.yml
@@ -3,3 +3,6 @@ rvm:
env:
- RAILS=4-0-stable AREL=master
+ - RAILS=3-2-stable AREL=3-0-stable
+ - RAILS=3-1-stable AREL=2-2-stable
+ - RAILS=3-0-stable AREL=2-0-stable
View
13 lib/squeel/adapters/active_record/4.0/association_scope_extensions.rb
@@ -1,13 +0,0 @@
-module ActiveRecord
- module Associations
- class AssociationScope
- def eval_scope(klass, scope)
- if scope.is_a?(Relation)
- scope
- else
- klass.unscoped.instance_exec(owner, &scope).visited
- end
- end
- end
- end
-end
View
16 lib/squeel/adapters/active_record/4.0/compat.rb
@@ -1 +1,17 @@
require 'squeel/adapters/active_record/compat'
+
+module ActiveRecord
+ module Associations
+ class AssociationScope
+ # 4.0's eval_scope doesn't play nicely with different bases. Need to do
+ # a similar workaround to the one for AR::Relation#merge, visiting it
+ def eval_scope(klass, scope)
+ if scope.is_a?(Relation)
+ scope
+ else
+ klass.unscoped.instance_exec(owner, &scope).visited
+ end
+ end
+ end
+ end
+end
View
1  lib/squeel/adapters/active_record/relation_extensions.rb
@@ -45,6 +45,7 @@ def merge(r, equalities_resolved = false)
merge_resolving_duplicate_squeel_equalities(r)
end
else
+ puts r.inspect if r.is_a?(Proc)
super(r)
end
end
View
4 spec/spec_helper.rb
@@ -3,12 +3,10 @@
require 'faker'
module ActiveRecord
+ # Shamelessly swiped from the AR test code
class SQLCounter
IGNORED_SQL = [/^PRAGMA /, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/,
/SELECT name\s+FROM sqlite_master\s+WHERE type = 'table' AND NOT name = 'sqlite_sequence'/]
-
- # FIXME: this needs to be refactored so specific database can add their own
- # ignored SQL. This ignored SQL is for Oracle.
IGNORED_SQL.concat [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from all_triggers/im]
def initialize
View
27 spec/support/models.rb
@@ -2,13 +2,24 @@ class Person < ActiveRecord::Base
belongs_to :parent, :class_name => 'Person', :foreign_key => :parent_id
has_many :children, :class_name => 'Person', :foreign_key => :parent_id
has_many :articles
- has_many :articles_with_condition, lambda { where :title => 'Condition' },
- :class_name => 'Article'
has_many :comments
+ if ActiveRecord::VERSION::MAJOR == 4
+ has_many :articles_with_condition, lambda { where :title => 'Condition' },
+ :class_name => 'Article'
+ has_many :article_comments_with_first_post,
+ lambda { where :body => 'first post' },
+ :through => :articles, :source => :comments
+ else
+ has_many :articles_with_condition, :conditions => {:title => 'Condition'},
+ :class_name => 'Article'
+ has_many :article_comments_with_first_post,
+ :conditions => { :body => 'first post' },
+ :through => :articles, :source => :comments
+ end
has_many :condition_article_comments, :through => :articles_with_condition, :source => :comments
- has_many :article_comments_with_first_post,
- lambda { where :body => 'first post' },
- :through => :articles, :source => :comments
+ if ActiveRecord::VERSION::MAJOR == 4
+ else
+ end
has_many :authored_article_comments, :through => :articles,
:source => :comments
has_many :notes, :as => :notable
@@ -40,7 +51,11 @@ class PersonWithNamePrimaryKey < ActiveRecord::Base
class PersonNamedBill < ActiveRecord::Base
self.table_name = 'people'
belongs_to :parent, :class_name => 'Person', :foreign_key => :parent_id
- default_scope lambda { where{name == 'Bill'}.order{id} }
+ if ActiveRecord::VERSION::MAJOR > 3 || ActiveRecord::VERSION::MINOR > 0
+ default_scope lambda { where{name == 'Bill'}.order{id} }
+ else # 3.0 doesn't support callables for default_scope
+ default_scope where{name == 'Bill'}.order{id}
+ end
scope :highly_compensated, lambda { where {salary > 200000} }
scope :ending_with_ill, lambda { where{name =~ '%ill'} }
scope :with_salary_equal_to, lambda { |value| where{abs(salary) == value} }

1 comment on commit e3fa657

@gamov

Awesome! this makes my transition from 3.0 to 3.2 less risky and smoother!

Please sign in to comment.
Something went wrong with that request. Please try again.