Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
Rails 2.3 compat: query parameter parsing with Rack and test suite fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kamal authored and mislav committed Mar 9, 2009
1 parent b9eef89 commit 1d3e813
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
17 changes: 15 additions & 2 deletions lib/will_paginate/view_helpers.rb
Expand Up @@ -321,8 +321,7 @@ def url_for(page)
stringified_merge @url_params, @options[:params] if @options[:params]

if complex = param_name.index(/[^\w-]/)
page_param = (defined?(CGIMethods) ? CGIMethods : ActionController::AbstractRequest).
parse_query_parameters("#{param_name}=#{page}")
page_param = parse_query_parameters("#{param_name}=#{page}")

stringified_merge @url_params, page_param
else
Expand Down Expand Up @@ -385,5 +384,19 @@ def stringified_merge(target, other)
end
end
end

def parse_query_parameters(params)
if defined?(CGIMethods)
CGIMethods.parse_query_parameters(params)
elsif defined?(ActionController::AbstractRequest)
ActionController::AbstractRequest.parse_query_parameters(params)
elsif defined?(ActionController::UrlEncodedPairParser)
# For Rails > 2.2
ActionController::UrlEncodedPairParser.parse_query_parameters(params)
else
# For Rails > 2.3
Rack::Utils.parse_nested_query(params)
end
end
end
end
5 changes: 4 additions & 1 deletion test/helper.rb
Expand Up @@ -29,7 +29,10 @@ def collect_deprecations

# Wrap tests that use Mocha and skip if unavailable.
def uses_mocha(test_name)
require 'mocha' unless Object.const_defined?(:Mocha)
unless Object.const_defined?(:Mocha)
gem 'mocha', '>= 0.9.5'
require 'mocha'
end
rescue LoadError => load_error
$stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
else
Expand Down
7 changes: 7 additions & 0 deletions test/lib/activerecord_test_case.rb
@@ -1,6 +1,13 @@
require 'lib/activerecord_test_connector'

class ActiveRecordTestCase < Test::Unit::TestCase
if defined?(ActiveSupport::Testing::SetupAndTeardown)
include ActiveSupport::Testing::SetupAndTeardown
end

if defined?(ActiveRecord::TestFixtures)
include ActiveRecord::TestFixtures
end
# Set our fixture path
if ActiveRecordTestConnector.able_to_connect
self.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
Expand Down
7 changes: 7 additions & 0 deletions test/lib/view_test_process.rb
Expand Up @@ -17,6 +17,13 @@
ActionController::Base.perform_caching = false

class WillPaginate::ViewTestCase < Test::Unit::TestCase
if defined?(ActionController::TestCase::Assertions)
include ActionController::TestCase::Assertions
end
if defined?(ActiveSupport::Testing::Deprecation)
include ActiveSupport::Testing::Deprecation
end

def setup
super
@controller = DummyController.new
Expand Down

0 comments on commit 1d3e813

Please sign in to comment.