Skip to content

Commit

Permalink
New named scope patches for 2.0.4 and 1.2.6. Change rake test_all to …
Browse files Browse the repository at this point in the history
…use 2.0.4 vs 2.0.2. Add an empty setup ArrayPaginationTest so that fixtures are not loaded for this case in 1.2.6 tests.
  • Loading branch information
metaskills authored and mislav committed Oct 7, 2008
1 parent 6b1fd99 commit af80782
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 40 deletions.
39 changes: 0 additions & 39 deletions lib/will_paginate/named_scope_patch.rb

This file was deleted.

54 changes: 54 additions & 0 deletions lib/will_paginate/named_scope_patch_1.2.6.rb
@@ -0,0 +1,54 @@

ActiveRecord::Associations::HasManyAssociation.class_eval do
protected
def method_missing(method, *args, &block)
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
super
elsif @reflection.klass.scopes.include?(method)
@reflection.klass.scopes[method].call(self, *args)
else
create_scoping = {}
set_belongs_to_association_for(create_scoping)

@reflection.klass.with_scope(
:create => create_scoping,
:find => {
:conditions => @finder_sql,
:joins => @join_sql,
:readonly => false
}
) do
@reflection.klass.send(method, *args, &block)
end
end
end
end

ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
protected
def method_missing(method, *args, &block)
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
super
elsif @reflection.klass.scopes.include?(method)
@reflection.klass.scopes[method].call(self, *args)
else
@reflection.klass.with_scope(construct_scope) { @reflection.klass.send(method, *args, &block) }
end
end
end

ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
protected
def method_missing(method, *args, &block)
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
super
elsif @reflection.klass.scopes.include?(method)
@reflection.klass.scopes[method].call(self, *args)
else
@reflection.klass.with_scope(:find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false }) do
@reflection.klass.send(method, *args, &block)
end
end
end
end

24 changes: 24 additions & 0 deletions lib/will_paginate/named_scope_patch_2.0.rb
@@ -0,0 +1,24 @@

ActiveRecord::Associations::AssociationCollection.class_eval do
protected
def method_missing(method, *args)
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
if block_given?
super { |*block_args| yield(*block_args) }
else
super
end
elsif @reflection.klass.scopes.include?(method)
@reflection.klass.scopes[method].call(self, *args)
else
with_scope(construct_scope) do
if block_given?
@reflection.klass.send(method, *args) { |*block_args| yield(*block_args) }
else
@reflection.klass.send(method, *args)
end
end
end
end
end

3 changes: 3 additions & 0 deletions test/collection_test.rb
Expand Up @@ -2,6 +2,9 @@
require 'will_paginate/array'

class ArrayPaginationTest < Test::Unit::TestCase

def setup ; end

def test_simple
collection = ('a'..'e').to_a

Expand Down
2 changes: 1 addition & 1 deletion test/tasks.rake
Expand Up @@ -35,7 +35,7 @@ task :test_full => %w(test test_mysql test_postgres)
desc %{Test everything with Rails 2.1.x, 2.0.x & 1.2.x gems}
task :test_all do
all = Rake::Task['test_full']
versions = %w(2.1.0 2.0.2 1.2.6)
versions = %w(2.1.0 2.0.4 1.2.6)
versions.each do |version|
ENV['RAILS_VERSION'] = "~> #{version}"
all.invoke
Expand Down

0 comments on commit af80782

Please sign in to comment.