Updated router. Temporarly replaced routing filter with rails internal.
This commit is contained in:
parent
b71fcdf371
commit
eab16e337e
21 changed files with 190 additions and 128 deletions
|
|
@ -62,7 +62,7 @@ module Caboose #:nodoc:
|
|||
# alias_method :calculate_with_deleted, :calculate
|
||||
alias_method :delete_all!, :delete_all
|
||||
end
|
||||
send :named_scope, :without_deleted, :conditions => {:deleted_at => nil}
|
||||
send :scope, :without_deleted, :conditions => {:deleted_at => nil}
|
||||
end
|
||||
include InstanceMethods
|
||||
end
|
||||
|
|
|
|||
|
|
@ -83,10 +83,10 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_named_scope_left_over
|
||||
make_file("app/models", "post.rb", "named_scope :failure")
|
||||
make_file("app/models", "post.rb", "scope :failure")
|
||||
@checker.check_ar_methods
|
||||
|
||||
assert @checker.alerts.has_key?("named_scope is now just scope")
|
||||
assert @checker.alerts.has_key?("scope is now just scope")
|
||||
end
|
||||
|
||||
def test_check_routes
|
||||
|
|
|
|||
6
vendor/plugins/will_paginate/CHANGELOG.rdoc
vendored
6
vendor/plugins/will_paginate/CHANGELOG.rdoc
vendored
|
|
@ -51,7 +51,7 @@
|
|||
|
||||
== 2.2.1, released 2008-04-08
|
||||
|
||||
* take less risky path when monkeypatching named_scope; fix that it no longer
|
||||
* take less risky path when monkeypatching scope; fix that it no longer
|
||||
requires ActiveRecord::VERSION
|
||||
* use strings in "respond_to?" calls to work around a bug in acts_as_ferret
|
||||
stable (ugh)
|
||||
|
|
@ -79,8 +79,8 @@
|
|||
|
||||
=== Other
|
||||
|
||||
* Add ability to opt-in for Rails 2.1 feature "named_scope" by calling
|
||||
WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2)
|
||||
* Add ability to opt-in for Rails 2.1 feature "scope" by calling
|
||||
WillPaginate.enable_scope (tested in Rails 1.2.6 and 2.0.2)
|
||||
* Support complex page parameters like "developers[page]"
|
||||
* Move Array#paginate definition to will_paginate/array.rb. You can now easily
|
||||
use pagination on arrays outside of Rails:
|
||||
|
|
|
|||
2
vendor/plugins/will_paginate/Rakefile
vendored
2
vendor/plugins/will_paginate/Rakefile
vendored
|
|
@ -16,7 +16,7 @@ desc 'Generate RDoc documentation for the will_paginate plugin.'
|
|||
Rake::RDocTask.new(:rdoc) do |rdoc|
|
||||
rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc').
|
||||
include('lib/**/*.rb').
|
||||
exclude('lib/will_paginate/named_scope*').
|
||||
exclude('lib/will_paginate/scope*').
|
||||
exclude('lib/will_paginate/array.rb').
|
||||
exclude('lib/will_paginate/version.rb')
|
||||
|
||||
|
|
|
|||
|
|
@ -46,18 +46,18 @@ module WillPaginate
|
|||
end
|
||||
end
|
||||
|
||||
# Enable named_scope, a feature of Rails 2.1, even if you have older Rails
|
||||
# Enable scope, a feature of Rails 2.1, even if you have older Rails
|
||||
# (tested on Rails 2.0.2 and 1.2.6).
|
||||
#
|
||||
# You can pass +false+ for +patch+ parameter to skip monkeypatching
|
||||
# *associations*. Use this if you feel that <tt>named_scope</tt> broke
|
||||
# *associations*. Use this if you feel that <tt>scope</tt> broke
|
||||
# has_many, has_many :through or has_and_belongs_to_many associations in
|
||||
# your app. By passing +false+, you can still use <tt>named_scope</tt> in
|
||||
# your app. By passing +false+, you can still use <tt>scope</tt> in
|
||||
# your models, but not through associations.
|
||||
def enable_named_scope(patch = true)
|
||||
def enable_scope(patch = true)
|
||||
return if defined? ActiveRecord::NamedScope
|
||||
require 'will_paginate/named_scope'
|
||||
require 'will_paginate/named_scope_patch' if patch
|
||||
require 'will_paginate/scope'
|
||||
require 'will_paginate/scope_patch' if patch
|
||||
|
||||
ActiveRecord::Base.send :include, WillPaginate::NamedScope
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
## stolen from: http://dev.rubyonrails.org/browser/trunk/activerecord/lib/active_record/named_scope.rb?rev=9084
|
||||
## stolen from: http://dev.rubyonrails.org/browser/trunk/activerecord/lib/active_record/scope.rb?rev=9084
|
||||
|
||||
module WillPaginate
|
||||
# This is a feature backported from Rails 2.1 because of its usefullness not only with will_paginate,
|
||||
# but in other aspects when managing complex conditions that you want to be reusable.
|
||||
module NamedScope
|
||||
# All subclasses of ActiveRecord::Base have two named_scopes:
|
||||
# All subclasses of ActiveRecord::Base have two scopes:
|
||||
# * <tt>all</tt>, which is similar to a <tt>find(:all)</tt> query, and
|
||||
# * <tt>scoped</tt>, which allows for the creation of anonymous scopes, on the fly:
|
||||
#
|
||||
|
|
@ -15,8 +15,8 @@ module WillPaginate
|
|||
def self.included(base)
|
||||
base.class_eval do
|
||||
extend ClassMethods
|
||||
named_scope :all
|
||||
named_scope :scoped, lambda { |scope| scope }
|
||||
scope :all
|
||||
scope :scoped, lambda { |scope| scope }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -29,11 +29,11 @@ module WillPaginate
|
|||
# such as <tt>:conditions => {:color => :red}, :select => 'shirts.*', :include => :washing_instructions</tt>.
|
||||
#
|
||||
# class Shirt < ActiveRecord::Base
|
||||
# named_scope :red, :conditions => {:color => 'red'}
|
||||
# named_scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true]
|
||||
# scope :red, :conditions => {:color => 'red'}
|
||||
# scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true]
|
||||
# end
|
||||
#
|
||||
# The above calls to <tt>named_scope</tt> define class methods <tt>Shirt.red</tt> and <tt>Shirt.dry_clean_only</tt>. <tt>Shirt.red</tt>,
|
||||
# The above calls to <tt>scope</tt> define class methods <tt>Shirt.red</tt> and <tt>Shirt.dry_clean_only</tt>. <tt>Shirt.red</tt>,
|
||||
# in effect, represents the query <tt>Shirt.find(:all, :conditions => {:color => 'red'})</tt>.
|
||||
#
|
||||
# Unlike Shirt.find(...), however, the object returned by <tt>Shirt.red</tt> is not an Array; it resembles the association object
|
||||
|
|
@ -59,7 +59,7 @@ module WillPaginate
|
|||
# Named scopes can also be procedural.
|
||||
#
|
||||
# class Shirt < ActiveRecord::Base
|
||||
# named_scope :colored, lambda { |color|
|
||||
# scope :colored, lambda { |color|
|
||||
# { :conditions => { :color => color } }
|
||||
# }
|
||||
# end
|
||||
|
|
@ -69,14 +69,14 @@ module WillPaginate
|
|||
# Named scopes can also have extensions, just as with <tt>has_many</tt> declarations:
|
||||
#
|
||||
# class Shirt < ActiveRecord::Base
|
||||
# named_scope :red, :conditions => {:color => 'red'} do
|
||||
# scope :red, :conditions => {:color => 'red'} do
|
||||
# def dom_id
|
||||
# 'red_shirts'
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def named_scope(name, options = {}, &block)
|
||||
def scope(name, options = {}, &block)
|
||||
scopes[name] = lambda do |parent_scope, *args|
|
||||
Scope.new(parent_scope, case options
|
||||
when Hash
|
||||
|
|
|
|||
12
vendor/plugins/will_paginate/test/finder_test.rb
vendored
12
vendor/plugins/will_paginate/test/finder_test.rb
vendored
|
|
@ -3,7 +3,7 @@ require 'lib/activerecord_test_case'
|
|||
|
||||
require 'will_paginate'
|
||||
WillPaginate.enable_activerecord
|
||||
WillPaginate.enable_named_scope
|
||||
WillPaginate.enable_scope
|
||||
|
||||
class FinderTest < ActiveRecordTestCase
|
||||
fixtures :topics, :replies, :users, :projects, :developers_projects
|
||||
|
|
@ -221,16 +221,16 @@ class FinderTest < ActiveRecordTestCase
|
|||
assert_equal 2, entries.total_entries
|
||||
end
|
||||
|
||||
## named_scope ##
|
||||
## scope ##
|
||||
|
||||
def test_paginate_in_named_scope
|
||||
def test_paginate_in_scope
|
||||
entries = Developer.poor.paginate :page => 1, :per_page => 1
|
||||
|
||||
assert_equal 1, entries.size
|
||||
assert_equal 2, entries.total_entries
|
||||
end
|
||||
|
||||
def test_paginate_in_named_scope_on_habtm_association
|
||||
def test_paginate_in_scope_on_habtm_association
|
||||
project = projects(:active_record)
|
||||
assert_queries(2) do
|
||||
entries = project.developers.poor.paginate :page => 1, :per_page => 1
|
||||
|
|
@ -240,7 +240,7 @@ class FinderTest < ActiveRecordTestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_paginate_in_named_scope_on_hmt_association
|
||||
def test_paginate_in_scope_on_hmt_association
|
||||
project = projects(:active_record)
|
||||
expected = [replies(:brave)]
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ class FinderTest < ActiveRecordTestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_paginate_in_named_scope_on_has_many_association
|
||||
def test_paginate_in_scope_on_has_many_association
|
||||
project = projects(:active_record)
|
||||
expected = [topics(:ar)]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue