will_paginate 3.2.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -5
  3. data/lib/will_paginate/active_record.rb +3 -3
  4. data/lib/will_paginate/i18n.rb +3 -3
  5. data/lib/will_paginate/locale/en.yml +2 -0
  6. data/lib/will_paginate/page_number.rb +1 -2
  7. data/lib/will_paginate/railtie.rb +2 -2
  8. data/lib/will_paginate/version.rb +2 -2
  9. data/lib/will_paginate/view_helpers/action_view.rb +7 -3
  10. data/lib/will_paginate/view_helpers/link_renderer.rb +7 -5
  11. data/lib/will_paginate.rb +0 -12
  12. metadata +12 -49
  13. data/lib/will_paginate/data_mapper.rb +0 -100
  14. data/lib/will_paginate/view_helpers/merb.rb +0 -26
  15. data/spec/collection_spec.rb +0 -139
  16. data/spec/console +0 -12
  17. data/spec/console_fixtures.rb +0 -28
  18. data/spec/database.yml +0 -29
  19. data/spec/fake_rubygems.rb +0 -18
  20. data/spec/finders/active_record_spec.rb +0 -417
  21. data/spec/finders/activerecord_test_connector.rb +0 -140
  22. data/spec/finders/data_mapper_spec.rb +0 -114
  23. data/spec/finders/data_mapper_test_connector.rb +0 -54
  24. data/spec/finders/mongoid_spec.rb +0 -145
  25. data/spec/finders/sequel_spec.rb +0 -65
  26. data/spec/finders/sequel_test_connector.rb +0 -15
  27. data/spec/fixtures/admin.rb +0 -3
  28. data/spec/fixtures/developer.rb +0 -9
  29. data/spec/fixtures/developers_projects.yml +0 -13
  30. data/spec/fixtures/project.rb +0 -13
  31. data/spec/fixtures/projects.yml +0 -6
  32. data/spec/fixtures/replies.yml +0 -29
  33. data/spec/fixtures/reply.rb +0 -8
  34. data/spec/fixtures/schema.rb +0 -38
  35. data/spec/fixtures/topic.rb +0 -8
  36. data/spec/fixtures/topics.yml +0 -30
  37. data/spec/fixtures/user.rb +0 -2
  38. data/spec/fixtures/users.yml +0 -35
  39. data/spec/matchers/deprecation_matcher.rb +0 -27
  40. data/spec/matchers/phrase_matcher.rb +0 -19
  41. data/spec/matchers/query_count_matcher.rb +0 -36
  42. data/spec/page_number_spec.rb +0 -82
  43. data/spec/per_page_spec.rb +0 -41
  44. data/spec/spec_helper.rb +0 -46
  45. data/spec/view_helpers/action_view_spec.rb +0 -480
  46. data/spec/view_helpers/base_spec.rb +0 -143
  47. data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
  48. data/spec/view_helpers/view_example_group.rb +0 -146
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
- require 'will_paginate/view_helpers/link_renderer_base'
3
- require 'will_paginate/collection'
4
-
5
- describe WillPaginate::ViewHelpers::LinkRendererBase do
6
-
7
- before do
8
- @renderer = described_class.new
9
- end
10
-
11
- it "should raise error when unprepared" do
12
- lambda {
13
- @renderer.pagination
14
- }.should raise_error
15
- end
16
-
17
- it "should prepare with collection and options" do
18
- prepare({})
19
- @renderer.send(:current_page).should == 1
20
- end
21
-
22
- it "should have total_pages accessor" do
23
- prepare :total_pages => 42
24
- @renderer.send(:total_pages).should == 42
25
- end
26
-
27
- it "should clear old cached values when prepared" do
28
- prepare(:total_pages => 1)
29
- @renderer.send(:total_pages).should == 1
30
- # prepare with different object:
31
- prepare(:total_pages => 2)
32
- @renderer.send(:total_pages).should == 2
33
- end
34
-
35
- it "should have pagination definition" do
36
- prepare({ :total_pages => 1 }, :page_links => true)
37
- @renderer.pagination.should == [:previous_page, 1, :next_page]
38
- end
39
-
40
- describe "visible page numbers" do
41
- it "should calculate windowed visible links" do
42
- prepare({ :page => 6, :total_pages => 11 }, :inner_window => 1, :outer_window => 1)
43
- showing_pages 1, 2, :gap, 5, 6, 7, :gap, 10, 11
44
- end
45
-
46
- it "should eliminate small gaps" do
47
- prepare({ :page => 6, :total_pages => 11 }, :inner_window => 2, :outer_window => 1)
48
- # pages 4 and 8 appear instead of the gap
49
- showing_pages 1..11
50
- end
51
-
52
- it "should support having no windows at all" do
53
- prepare({ :page => 4, :total_pages => 7 }, :inner_window => 0, :outer_window => 0)
54
- showing_pages 1, :gap, 4, :gap, 7
55
- end
56
-
57
- it "should adjust upper limit if lower is out of bounds" do
58
- prepare({ :page => 1, :total_pages => 10 }, :inner_window => 2, :outer_window => 1)
59
- showing_pages 1, 2, 3, 4, 5, :gap, 9, 10
60
- end
61
-
62
- it "should adjust lower limit if upper is out of bounds" do
63
- prepare({ :page => 10, :total_pages => 10 }, :inner_window => 2, :outer_window => 1)
64
- showing_pages 1, 2, :gap, 6, 7, 8, 9, 10
65
- end
66
-
67
- def showing_pages(*pages)
68
- pages = pages.first.to_a if Array === pages.first or Range === pages.first
69
- @renderer.send(:windowed_page_numbers).should == pages
70
- end
71
- end
72
-
73
- protected
74
-
75
- def collection(params = {})
76
- if params[:total_pages]
77
- params[:per_page] = 1
78
- params[:total_entries] = params[:total_pages]
79
- end
80
- WillPaginate::Collection.new(params[:page] || 1, params[:per_page] || 30, params[:total_entries])
81
- end
82
-
83
- def prepare(collection_options, options = {})
84
- @renderer.prepare(collection(collection_options), options)
85
- end
86
-
87
- end
@@ -1,146 +0,0 @@
1
- require 'active_support'
2
- require 'stringio'
3
- begin
4
- $stderr = StringIO.new
5
- require 'minitest/unit'
6
- rescue LoadError
7
- # Fails on Ruby 1.8, but it's OK since we only need MiniTest::Assertions
8
- # on Rails 4 which doesn't support 1.8 anyway.
9
- ensure
10
- $stderr = STDERR
11
- end
12
-
13
- begin
14
- require 'rails/dom/testing/assertions'
15
- rescue LoadError
16
- require 'action_dispatch/testing/assertions'
17
- end
18
- require 'will_paginate/array'
19
-
20
- module ViewExampleGroup
21
-
22
- if defined?(Rails::Dom::Testing::Assertions)
23
- include Rails::Dom::Testing::Assertions::SelectorAssertions
24
- else
25
- include ActionDispatch::Assertions::SelectorAssertions
26
- end
27
- include MiniTest::Assertions if defined? MiniTest
28
-
29
- def assert(value, message)
30
- raise message unless value
31
- end
32
-
33
- def paginate(collection = {}, options = {}, &block)
34
- if collection.instance_of? Hash
35
- page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection)
36
- collection = [1].paginate(page_options)
37
- end
38
-
39
- locals = { :collection => collection, :options => options }
40
-
41
- @render_output = render(locals)
42
- @html_document = nil
43
-
44
- if block_given?
45
- classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class]
46
- assert_select("div.#{classname}", 1, 'no main DIV', &block)
47
- end
48
-
49
- @render_output
50
- end
51
-
52
- def parse_html_document(html)
53
- if defined?(Rails::Dom::Testing::Assertions)
54
- Nokogiri::HTML::Document.parse(html)
55
- else
56
- HTML::Document.new(html, true, false)
57
- end
58
- end
59
-
60
- def html_document
61
- @html_document ||= parse_html_document(@render_output)
62
- end
63
-
64
- def document_root_element
65
- html_document.root
66
- end
67
-
68
- def response_from_page_or_rjs
69
- html_document.root
70
- end
71
-
72
- def validate_page_numbers(expected, links, param_name = :page)
73
- param_pattern = /\W#{Regexp.escape(param_name.to_s)}=([^&]*)/
74
-
75
- links.map { |el|
76
- unescape_href(el) =~ param_pattern
77
- $1 ? $1.to_i : $1
78
- }.should == expected
79
- end
80
-
81
- def assert_links_match(pattern, links = nil, numbers = nil)
82
- links ||= assert_select 'div.pagination a[href]' do |elements|
83
- elements
84
- end
85
-
86
- pages = [] if numbers
87
-
88
- links.each do |el|
89
- href = unescape_href(el)
90
- href.should =~ pattern
91
- if numbers
92
- href =~ pattern
93
- pages << ($1.nil?? nil : $1.to_i)
94
- end
95
- end
96
-
97
- pages.should == numbers if numbers
98
- end
99
-
100
- def assert_no_links_match(pattern)
101
- assert_select 'div.pagination a[href]' do |elements|
102
- elements.each do |el|
103
- unescape_href(el).should_not =~ pattern
104
- end
105
- end
106
- end
107
-
108
- def unescape_href(el)
109
- CGI.unescape CGI.unescapeHTML(el['href'])
110
- end
111
-
112
- def build_message(message, pattern, *args)
113
- built_message = pattern.dup
114
- for value in args
115
- built_message.sub! '?', value.inspect
116
- end
117
- built_message
118
- end
119
-
120
- end
121
-
122
- RSpec.configure do |config|
123
- config.include ViewExampleGroup, :type => :view, :example_group => {
124
- :file_path => %r{spec/view_helpers/}
125
- }
126
- end
127
-
128
- module HTML
129
- Node.class_eval do
130
- def inner_text
131
- children.map(&:inner_text).join('')
132
- end
133
- end
134
-
135
- Text.class_eval do
136
- def inner_text
137
- self.to_s
138
- end
139
- end
140
-
141
- Tag.class_eval do
142
- def inner_text
143
- childless?? '' : super
144
- end
145
- end
146
- end if defined?(HTML)