Permalink
Browse files

test with rcov and bring it up to 100% test coverage (yeah!!)

  • Loading branch information...
1 parent f48248f commit f4a23208344e28c1d89b9d1d2bd68729b7c01800 @mislav committed Apr 7, 2008
Showing with 26 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +9 −0 Rakefile
  3. +5 −7 lib/will_paginate/view_helpers.rb
  4. +11 −0 test/finder_test.rb
View
@@ -1,3 +1,4 @@
/doc
/rails
*.gem
+/coverage
View
@@ -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
@@ -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
@@ -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
View
@@ -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
@@ -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

0 comments on commit f4a2320

Please sign in to comment.