Skip to content
This repository
Browse code

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

  • Loading branch information...
commit f4a23208344e28c1d89b9d1d2bd68729b7c01800 1 parent f48248f
Mislav Marohnić authored
1  .gitignore
... ... @@ -1,3 +1,4 @@
1 1 /doc
2 2 /rails
3 3 *.gem
  4 +/coverage
9 Rakefile
@@ -90,3 +90,12 @@ task :examples do
90 90 %x(haml examples/index.haml examples/index.html)
91 91 %x(sass examples/pagination.sass examples/pagination.css)
92 92 end
  93 +
  94 +task :rcov do
  95 + excludes = %w( lib/will_paginate/named_scope*
  96 + lib/will_paginate/core_ext.rb
  97 + lib/will_paginate.rb
  98 + rails* )
  99 +
  100 + system %[rcov -Itest:lib test/*.rb -x #{excludes.join(',')}]
  101 +end
12 lib/will_paginate/view_helpers.rb
@@ -226,9 +226,11 @@ def visible_page_numbers
226 226 if window_to > total_pages
227 227 window_from -= window_to - total_pages
228 228 window_to = total_pages
229   - elsif window_from < 1
  229 + end
  230 + if window_from < 1
230 231 window_to += 1 - window_from
231 232 window_from = 1
  233 + window_to = total_pages if window_to > total_pages
232 234 end
233 235
234 236 visible = (1..total_pages).to_a
@@ -261,12 +263,8 @@ def url_for(page)
261 263 stringified_merge @url_params, @options[:params] if @options[:params]
262 264
263 265 if param_name.index(/[^\w-]/)
264   - page_param = unless defined? CGIMethods
265   - ActionController::AbstractRequest
266   - else
267   - # Rails 1.2
268   - CGIMethods
269   - end.parse_query_parameters("#{param_name}=#{page}")
  266 + page_param = (defined?(CGIMethods) ? CGIMethods : ActionController::AbstractRequest).
  267 + parse_query_parameters("#{param_name}=#{page}")
270 268
271 269 stringified_merge @url_params, page_param
272 270 else
11 test/finder_test.rb
@@ -220,6 +220,8 @@ def test_scoped_paginate
220 220 assert_equal 2, entries.size
221 221 assert_equal 2, entries.total_entries
222 222 end
  223 +
  224 + ## named_scope ##
223 225
224 226 def test_paginate_in_named_scope
225 227 entries = Developer.poor.paginate :page => 1, :per_page => 1
@@ -260,6 +262,15 @@ def test_paginate_in_named_scope_on_has_many_association
260 262 end
261 263 end
262 264
  265 + ## misc ##
  266 +
  267 + def test_count_and_total_entries_options_are_mutually_exclusive
  268 + e = assert_raise ArgumentError do
  269 + Developer.paginate :page => 1, :count => {}, :total_entries => 1
  270 + end
  271 + assert_match /exclusive/, e.to_s
  272 + end
  273 +
263 274 def test_readonly
264 275 assert_nothing_raised { Developer.paginate :readonly => true, :page => 1 }
265 276 end

0 comments on commit f4a2320

Please sign in to comment.
Something went wrong with that request. Please try again.