Skip to content

Commit

Permalink
big refactoring in view tests; rewrite most of them in much nicer way…
Browse files Browse the repository at this point in the history
… to test/view_test.rb
  • Loading branch information
mislav committed Apr 6, 2008
1 parent b00a298 commit efe2c81
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 244 deletions.
2 changes: 1 addition & 1 deletion lib/will_paginate.rb
Expand Up @@ -21,7 +21,7 @@ def enable_actionpack
require 'will_paginate/view_helpers'
ActionView::Base.class_eval { include ViewHelpers }

if ActionController::Base.respond_to? :rescue_responses
if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
end
end
Expand Down
18 changes: 16 additions & 2 deletions test/array_pagination_test.rb → test/collection_test.rb
Expand Up @@ -53,6 +53,20 @@ def test_paginated_collection
assert !collection.out_of_bounds?
end

def test_previous_next_pages
collection = create(1, 1, 3)
assert_nil collection.previous_page
assert_equal 2, collection.next_page

collection = create(2, 1, 3)
assert_equal 1, collection.previous_page
assert_equal 3, collection.next_page

collection = create(3, 1, 3)
assert_equal 2, collection.previous_page
assert_nil collection.next_page
end

def test_out_of_bounds
entries = create(2, 3, 2){}
assert entries.out_of_bounds?
Expand Down Expand Up @@ -95,9 +109,9 @@ def test_guessing_total_count
end

def test_invalid_page
bad_input = [0, -1, nil, '', 'Schnitzel']
bad_inputs = [0, -1, nil, '', 'Schnitzel']

bad_input.each do |bad|
bad_inputs.each do |bad|
assert_raise(WillPaginate::InvalidPage) { create bad }
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/helper.rb
Expand Up @@ -13,6 +13,18 @@ def assert_respond_to_all object, methods
[method.to_s, method.to_sym].each { |m| assert_respond_to object, m }
end
end

def collect_deprecations
old_behavior = WillPaginate::Deprecation.behavior
deprecations = []
WillPaginate::Deprecation.behavior = Proc.new do |message, callstack|
deprecations << message
end
result = yield
[result, deprecations]
ensure
WillPaginate::Deprecation.behavior = old_behavior
end
end

# Wrap tests that use Mocha and skip if unavailable.
Expand Down
21 changes: 0 additions & 21 deletions test/lib/html_inner_text.rb

This file was deleted.

67 changes: 67 additions & 0 deletions test/lib/view_test_process.rb
@@ -0,0 +1,67 @@
require 'action_controller'
require 'action_controller/test_process'

require 'will_paginate'
WillPaginate.enable_actionpack

ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end

ActionController::Base.perform_caching = false

class DummyRequest
def initialize
@get = true
end

def get?
@get
end

def post
@get = false
end

def symbolized_path_parameters
{ :controller => 'foo', :action => 'bar' }
end

def relative_url_root
''
end
end

class DummyController
attr_reader :request
attr_accessor :controller_name

def initialize
@request = DummyRequest.new
@url = ActionController::UrlRewriter.new(@request, {})
end

def url_for(params)
@url.rewrite(params)
end
end

module HTML
Node.class_eval do
def inner_text
children.map(&:inner_text).join('')
end
end

Text.class_eval do
def inner_text
self.to_s
end
end

Tag.class_eval do
def inner_text
childless?? '' : super
end
end
end

0 comments on commit efe2c81

Please sign in to comment.