pb-will_paginate 2.3.12

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 (51) hide show
  1. data/.gitignore +4 -0
  2. data/.manifest +43 -0
  3. data/CHANGELOG.rdoc +139 -0
  4. data/LICENSE +18 -0
  5. data/README.rdoc +107 -0
  6. data/Rakefile +71 -0
  7. data/VERSION +1 -0
  8. data/examples/apple-circle.gif +0 -0
  9. data/examples/index.haml +69 -0
  10. data/examples/index.html +92 -0
  11. data/examples/pagination.css +90 -0
  12. data/examples/pagination.sass +91 -0
  13. data/init.rb +2 -0
  14. data/lib/will_paginate.rb +90 -0
  15. data/lib/will_paginate/array.rb +16 -0
  16. data/lib/will_paginate/collection.rb +144 -0
  17. data/lib/will_paginate/core_ext.rb +43 -0
  18. data/lib/will_paginate/finder.rb +264 -0
  19. data/lib/will_paginate/i18n.rb +178 -0
  20. data/lib/will_paginate/named_scope.rb +170 -0
  21. data/lib/will_paginate/named_scope_patch.rb +37 -0
  22. data/lib/will_paginate/version.rb +9 -0
  23. data/lib/will_paginate/view_helpers.rb +397 -0
  24. data/locales/en.yml +11 -0
  25. data/pb-will_paginate.gemspec +106 -0
  26. data/test/boot.rb +21 -0
  27. data/test/collection_test.rb +143 -0
  28. data/test/console +8 -0
  29. data/test/database.yml +22 -0
  30. data/test/finder_test.rb +473 -0
  31. data/test/fixtures/admin.rb +3 -0
  32. data/test/fixtures/developer.rb +14 -0
  33. data/test/fixtures/developers_projects.yml +13 -0
  34. data/test/fixtures/project.rb +15 -0
  35. data/test/fixtures/projects.yml +6 -0
  36. data/test/fixtures/replies.yml +29 -0
  37. data/test/fixtures/reply.rb +7 -0
  38. data/test/fixtures/schema.rb +38 -0
  39. data/test/fixtures/topic.rb +10 -0
  40. data/test/fixtures/topics.yml +30 -0
  41. data/test/fixtures/user.rb +2 -0
  42. data/test/fixtures/users.yml +35 -0
  43. data/test/helper.rb +37 -0
  44. data/test/i18n_test.rb +194 -0
  45. data/test/lib/activerecord_test_case.rb +43 -0
  46. data/test/lib/activerecord_test_connector.rb +75 -0
  47. data/test/lib/load_fixtures.rb +11 -0
  48. data/test/lib/view_test_process.rb +179 -0
  49. data/test/tasks.rake +59 -0
  50. data/test/view_test.rb +289 -0
  51. metadata +122 -0
@@ -0,0 +1,3 @@
1
+ class Admin < User
2
+ has_many :companies, :finder_sql => 'SELECT * FROM companies'
3
+ end
@@ -0,0 +1,14 @@
1
+ class Developer < User
2
+ has_and_belongs_to_many :projects, :include => :topics, :order => 'projects.name'
3
+
4
+ def self.with_poor_ones(&block)
5
+ with_scope :find => { :conditions => ['salary <= ?', 80000], :order => 'salary' } do
6
+ yield
7
+ end
8
+ end
9
+
10
+ named_scope :distinct, :select => 'DISTINCT `users`.*'
11
+ named_scope :poor, :conditions => ['salary <= ?', 80000], :order => 'salary'
12
+
13
+ def self.per_page() 10 end
14
+ end
@@ -0,0 +1,13 @@
1
+ david_action_controller:
2
+ developer_id: 1
3
+ project_id: 2
4
+ joined_on: 2004-10-10
5
+
6
+ david_active_record:
7
+ developer_id: 1
8
+ project_id: 1
9
+ joined_on: 2004-10-10
10
+
11
+ jamis_active_record:
12
+ developer_id: 2
13
+ project_id: 1
@@ -0,0 +1,15 @@
1
+ class Project < ActiveRecord::Base
2
+ has_and_belongs_to_many :developers, :uniq => true
3
+
4
+ has_many :topics
5
+ # :finder_sql => 'SELECT * FROM topics WHERE (topics.project_id = #{id})',
6
+ # :counter_sql => 'SELECT COUNT(*) FROM topics WHERE (topics.project_id = #{id})'
7
+
8
+ has_many :replies, :through => :topics do
9
+ def find_recent(params = {})
10
+ with_scope :find => { :conditions => ['replies.created_at > ?', 15.minutes.ago] } do
11
+ find :all, params
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ active_record:
2
+ id: 1
3
+ name: Active Record
4
+ action_controller:
5
+ id: 2
6
+ name: Active Controller
@@ -0,0 +1,29 @@
1
+ witty_retort:
2
+ id: 1
3
+ topic_id: 1
4
+ content: Birdman is better!
5
+ created_at: <%= 6.hours.ago.to_s(:db) %>
6
+
7
+ another:
8
+ id: 2
9
+ topic_id: 2
10
+ content: Nuh uh!
11
+ created_at: <%= 1.hour.ago.to_s(:db) %>
12
+
13
+ spam:
14
+ id: 3
15
+ topic_id: 1
16
+ content: Nice site!
17
+ created_at: <%= 1.hour.ago.to_s(:db) %>
18
+
19
+ decisive:
20
+ id: 4
21
+ topic_id: 4
22
+ content: "I'm getting to the bottom of this"
23
+ created_at: <%= 30.minutes.ago.to_s(:db) %>
24
+
25
+ brave:
26
+ id: 5
27
+ topic_id: 4
28
+ content: "AR doesn't scare me a bit"
29
+ created_at: <%= 10.minutes.ago.to_s(:db) %>
@@ -0,0 +1,7 @@
1
+ class Reply < ActiveRecord::Base
2
+ belongs_to :topic, :include => [:replies]
3
+
4
+ named_scope :recent, :conditions => ['replies.created_at > ?', 15.minutes.ago]
5
+
6
+ validates_presence_of :content
7
+ end
@@ -0,0 +1,38 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ create_table "users", :force => true do |t|
4
+ t.column "name", :text
5
+ t.column "salary", :integer, :default => 70000
6
+ t.column "created_at", :datetime
7
+ t.column "updated_at", :datetime
8
+ t.column "type", :text
9
+ end
10
+
11
+ create_table "projects", :force => true do |t|
12
+ t.column "name", :text
13
+ end
14
+
15
+ create_table "developers_projects", :id => false, :force => true do |t|
16
+ t.column "developer_id", :integer, :null => false
17
+ t.column "project_id", :integer, :null => false
18
+ t.column "joined_on", :date
19
+ t.column "access_level", :integer, :default => 1
20
+ end
21
+
22
+ create_table "topics", :force => true do |t|
23
+ t.column "project_id", :integer
24
+ t.column "title", :string
25
+ t.column "subtitle", :string
26
+ t.column "content", :text
27
+ t.column "created_at", :datetime
28
+ t.column "updated_at", :datetime
29
+ end
30
+
31
+ create_table "replies", :force => true do |t|
32
+ t.column "content", :text
33
+ t.column "created_at", :datetime
34
+ t.column "updated_at", :datetime
35
+ t.column "topic_id", :integer
36
+ end
37
+
38
+ end
@@ -0,0 +1,10 @@
1
+ class Topic < ActiveRecord::Base
2
+ has_many :replies, :dependent => :destroy, :order => 'replies.created_at DESC'
3
+ belongs_to :project
4
+
5
+ named_scope :mentions_activerecord, :conditions => ['topics.title LIKE ?', '%ActiveRecord%']
6
+
7
+ named_scope :with_replies_starting_with, lambda { |text|
8
+ { :conditions => "replies.content LIKE '#{text}%' ", :include => :replies }
9
+ }
10
+ end
@@ -0,0 +1,30 @@
1
+ futurama:
2
+ id: 1
3
+ title: Isnt futurama awesome?
4
+ subtitle: It really is, isnt it.
5
+ content: I like futurama
6
+ created_at: <%= 1.day.ago.to_s(:db) %>
7
+ updated_at:
8
+
9
+ harvey_birdman:
10
+ id: 2
11
+ title: Harvey Birdman is the king of all men
12
+ subtitle: yup
13
+ content: He really is
14
+ created_at: <%= 2.hours.ago.to_s(:db) %>
15
+ updated_at:
16
+
17
+ rails:
18
+ id: 3
19
+ project_id: 1
20
+ title: Rails is nice
21
+ subtitle: It makes me happy
22
+ content: except when I have to hack internals to fix pagination. even then really.
23
+ created_at: <%= 20.minutes.ago.to_s(:db) %>
24
+
25
+ ar:
26
+ id: 4
27
+ project_id: 1
28
+ title: ActiveRecord sometimes freaks me out
29
+ content: "I mean, what's the deal with eager loading?"
30
+ created_at: <%= 15.minutes.ago.to_s(:db) %>
@@ -0,0 +1,2 @@
1
+ class User < ActiveRecord::Base
2
+ end
@@ -0,0 +1,35 @@
1
+ david:
2
+ id: 1
3
+ name: David
4
+ salary: 80000
5
+ type: Developer
6
+
7
+ jamis:
8
+ id: 2
9
+ name: Jamis
10
+ salary: 150000
11
+ type: Developer
12
+
13
+ <% for digit in 3..10 %>
14
+ dev_<%= digit %>:
15
+ id: <%= digit %>
16
+ name: fixture_<%= digit %>
17
+ salary: 100000
18
+ type: Developer
19
+ <% end %>
20
+
21
+ poor_jamis:
22
+ id: 11
23
+ name: Jamis
24
+ salary: 9000
25
+ type: Developer
26
+
27
+ admin:
28
+ id: 12
29
+ name: admin
30
+ type: Admin
31
+
32
+ goofy:
33
+ id: 13
34
+ name: Goofy
35
+ type: Admin
@@ -0,0 +1,37 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+
4
+ # gem install redgreen for colored test output
5
+ begin require 'redgreen'; rescue LoadError; end
6
+
7
+ require 'boot' unless defined?(ActiveRecord)
8
+
9
+ class Test::Unit::TestCase
10
+ protected
11
+ def assert_respond_to_all object, methods
12
+ methods.each do |method|
13
+ [method.to_s, method.to_sym].each { |m| assert_respond_to object, m }
14
+ end
15
+ end
16
+
17
+ def collect_deprecations
18
+ old_behavior = WillPaginate::Deprecation.behavior
19
+ deprecations = []
20
+ WillPaginate::Deprecation.behavior = Proc.new do |message, callstack|
21
+ deprecations << message
22
+ end
23
+ result = yield
24
+ [result, deprecations]
25
+ ensure
26
+ WillPaginate::Deprecation.behavior = old_behavior
27
+ end
28
+ end
29
+
30
+ # Wrap tests that use Mocha and skip if unavailable.
31
+ def uses_mocha(test_name)
32
+ require 'mocha'
33
+ rescue LoadError
34
+ $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
35
+ else
36
+ yield
37
+ end
@@ -0,0 +1,194 @@
1
+ require 'helper'
2
+ require 'lib/view_test_process'
3
+
4
+ class I18nTest < WillPaginate::ViewTestCase
5
+
6
+ ## basic pagination ##
7
+
8
+ def setup
9
+ clear_translations
10
+ super
11
+ end
12
+
13
+ def teardown
14
+ clear_translations
15
+ super
16
+ end
17
+
18
+ def clear_translations
19
+ translations = ::I18n.backend.send(:instance_variable_get, :@translations)
20
+ translations.clear unless translations.nil?
21
+ WillPaginate::I18n.append_translations_load_path
22
+ ::I18n.backend.load_translations(*::I18n.load_path)
23
+ end
24
+
25
+ def test_will_paginate_with_default_previous_label
26
+ paginate({ :page => 2 }) do
27
+ assert_select 'a[href]' do |elements|
28
+ assert_select elements.first, 'a', '&laquo; Previous'
29
+ end
30
+ end
31
+ end
32
+
33
+ def test_will_paginate_with_custom_global_previous_label
34
+ I18n.backend.store_translations :en, :will_paginate => { :previous_label => '<~ Prev' }
35
+ paginate({ :page => 2 }) do
36
+ assert_select 'a[href]' do |elements|
37
+ assert_select elements.first, 'a', '<~ Prev'
38
+ end
39
+ end
40
+ end
41
+
42
+ def test_will_paginate_with_default_next_label
43
+ paginate({ :page => 2 }) do
44
+ assert_select 'a[href]' do |elements|
45
+ assert_select elements.last, 'a', 'Next &raquo;'
46
+ end
47
+ end
48
+ end
49
+
50
+ def test_will_paginate_with_custom_global_next_label
51
+ I18n.backend.store_translations :en, :will_paginate => { :next_label => 'Next ~>' }
52
+ paginate({ :page => 2 }) do
53
+ assert_select 'a[href]' do |elements|
54
+ assert_select elements.last, 'a', 'Next ~>'
55
+ end
56
+ end
57
+ end
58
+
59
+ def test_will_paginate_with_default_gap_marker
60
+ paginate({ :per_page => 2 }, :inner_window => 0, :outer_window => 0) do
61
+ assert_select 'span.gap', '&hellip;'
62
+ end
63
+ end
64
+
65
+ def test_will_paginate_with_custom_global_gap_marker
66
+ I18n.backend.store_translations :en, :will_paginate => { :gap_marker => '<abbr title="pages elided">~~</abbr>' }
67
+ paginate({ :per_page => 2 }, :inner_window => 0, :outer_window => 0) do
68
+ assert_select 'abbr', '~~'
69
+ end
70
+ end
71
+
72
+ def test_default_page_entries_info_0
73
+ @template = '<%= page_entries_info collection %>'
74
+ array = []
75
+ paginate array.paginate
76
+ assert_equal "No entries found", @html_result
77
+ end
78
+
79
+ def test_default_page_entries_info_1
80
+ @template = '<%= page_entries_info collection %>'
81
+ array = ['Foo']
82
+ paginate array.paginate
83
+ assert_equal "Displaying <em>1</em> string", @html_result
84
+ end
85
+
86
+ def test_default_page_entries_info_all
87
+ @template = '<%= page_entries_info collection %>'
88
+ array = ['Foo', 'Bar']
89
+ paginate array.paginate({ :per_page => array.size + 1 })
90
+ assert_equal "Displaying <em>all 2</em> strings", @html_result
91
+ end
92
+
93
+ def test_default_page_entries_info_n_to_m_of_x
94
+ @template = '<%= page_entries_info collection %>'
95
+ array = ('a'..'z').to_a
96
+
97
+ paginate array.paginate(:page => 2, :per_page => 5)
98
+ assert_equal %{Displaying strings <em>6&nbsp;-&nbsp;10</em> of <em>26</em> in total},
99
+ @html_result
100
+
101
+ paginate array.paginate(:page => 7, :per_page => 4)
102
+ assert_equal %{Displaying strings <em>25&nbsp;-&nbsp;26</em> of <em>26</em> in total},
103
+ @html_result
104
+ end
105
+
106
+ def test_page_entries_info_with_custom_globals
107
+ I18n.backend.store_translations :en, :will_paginate => {
108
+ :page_entries_info => {
109
+ :zero => 'No {{pluralized_entry_name}}',
110
+ :one => 'One {{entry_name}}:',
111
+ :all => 'All {{total_count}} {{pluralized_entry_name}}:',
112
+ :n_to_m_of_x => '{{pluralized_entry_name}} {{start_count}} to {{end_count}} of {{total_count}}:'
113
+ }
114
+ }
115
+ @template = '<%= page_entries_info collection %>'
116
+
117
+ paginate [].paginate
118
+ assert_equal 'No entries', @html_result
119
+
120
+ paginate ['Baz'].paginate
121
+ assert_equal 'One string:', @html_result
122
+
123
+ paginate ['Wonderment', 'Traction'].paginate
124
+ assert_equal 'All 2 strings:', @html_result
125
+
126
+ paginate ('a'..'z').to_a.paginate(:page => 3, :per_page => 3)
127
+ assert_equal 'strings 7 to 9 of 26:', @html_result
128
+ end
129
+
130
+ def test_page_entries_info_uses_human_name
131
+ I18n.backend.store_translations :en, :activerecord => {
132
+ :models => {
133
+ :developer => {
134
+ :one => 'Code Monkey',
135
+ :other => 'Code Monkeys'
136
+ }
137
+ }
138
+ }
139
+ @template = '<%= page_entries_info collection %>'
140
+
141
+ paginate [Developer.new].paginate
142
+ assert_equal 'Displaying <em>1</em> Code Monkey', @html_result
143
+
144
+ paginate [Developer.new, Developer.new].paginate
145
+ assert_equal 'Displaying <em>all 2</em> Code Monkeys', @html_result
146
+ end
147
+
148
+ uses_mocha 'class name' do
149
+ def test_page_entries_info_with_longer_class_name
150
+ @template = '<%= page_entries_info collection %>'
151
+ collection = ('a'..'z').to_a.paginate
152
+ collection.first.stubs(:class).returns(mock('class', :name => 'ProjectType'))
153
+
154
+ paginate collection
155
+ assert @html_result.index('project types'), "expected <#{@html_result.inspect}> to mention 'project types'"
156
+ end
157
+ end
158
+
159
+ def test_previous_label_deprecated
160
+ assert_deprecated ':previous_label' do
161
+ paginate({ :page => 2 }, :previous_label => 'Prev') do
162
+ assert_select 'a[href]:first-child', 'Prev'
163
+ end
164
+ end
165
+ end
166
+
167
+ def test_prev_label_deprecated
168
+ assert_deprecated ':prev_label' do
169
+ paginate({ :page => 2 }, :prev_label => 'Prev') do
170
+ assert_select 'a[href]:first-child', 'Prev'
171
+ end
172
+ end
173
+ end
174
+
175
+ def test_setting_gap_marker_manually_is_deprecated
176
+ assert_deprecated 'gap' do
177
+ renderer = WillPaginate::LinkRenderer.new
178
+ renderer.gap_marker = '<span class="my-gap">~~</span>'
179
+ paginate({ :per_page => 2 }, :inner_window => 0, :outer_window => 0, :renderer => renderer) do
180
+ assert_select 'span.my-gap', '~~'
181
+ end
182
+ end
183
+ end
184
+
185
+ def test_entry_name_is_deprecated
186
+ assert_deprecated ':entry_name' do
187
+ @template = '<%= page_entries_info collection, :entry_name => "author" %>'
188
+ entries = []
189
+ paginate(entries.paginate)
190
+ assert_equal %{No authors found}, @html_result
191
+ end
192
+ end
193
+
194
+ end