Skip to content

Commit

Permalink
test with rcov and bring it up to 100% test coverage (yeah!!)
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Apr 7, 2008
1 parent f48248f commit f4a2320
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
/doc
/rails
*.gem
/coverage
9 changes: 9 additions & 0 deletions Rakefile
Expand Up @@ -90,3 +90,12 @@ task :examples do
%x(haml examples/index.haml examples/index.html)
%x(sass examples/pagination.sass examples/pagination.css)
end

task :rcov do
excludes = %w( lib/will_paginate/named_scope*
lib/will_paginate/core_ext.rb
lib/will_paginate.rb
rails* )

system %[rcov -Itest:lib test/*.rb -x #{excludes.join(',')}]
end
12 changes: 5 additions & 7 deletions lib/will_paginate/view_helpers.rb
Expand Up @@ -226,9 +226,11 @@ def visible_page_numbers
if window_to > total_pages
window_from -= window_to - total_pages
window_to = total_pages
elsif window_from < 1
end
if window_from < 1
window_to += 1 - window_from
window_from = 1
window_to = total_pages if window_to > total_pages
end

visible = (1..total_pages).to_a
Expand Down Expand Up @@ -261,12 +263,8 @@ def url_for(page)
stringified_merge @url_params, @options[:params] if @options[:params]

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

stringified_merge @url_params, page_param
else
Expand Down
11 changes: 11 additions & 0 deletions test/finder_test.rb
Expand Up @@ -220,6 +220,8 @@ def test_scoped_paginate
assert_equal 2, entries.size
assert_equal 2, entries.total_entries
end

## named_scope ##

def test_paginate_in_named_scope
entries = Developer.poor.paginate :page => 1, :per_page => 1
Expand Down Expand Up @@ -260,6 +262,15 @@ def test_paginate_in_named_scope_on_has_many_association
end
end

## misc ##

def test_count_and_total_entries_options_are_mutually_exclusive
e = assert_raise ArgumentError do
Developer.paginate :page => 1, :count => {}, :total_entries => 1
end
assert_match /exclusive/, e.to_s
end

def test_readonly
assert_nothing_raised { Developer.paginate :readonly => true, :page => 1 }
end
Expand Down

0 comments on commit f4a2320

Please sign in to comment.