bootstrap_pager 0.9.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 (109) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/.idea/encodings.xml +5 -0
  4. data/.idea/misc.xml +5 -0
  5. data/.idea/modules.xml +9 -0
  6. data/.idea/pager.iml +50 -0
  7. data/.idea/scopes/scope_settings.xml +5 -0
  8. data/.idea/vcs.xml +7 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE +20 -0
  11. data/MIT-LICENSE +20 -0
  12. data/README.rdoc +307 -0
  13. data/Rakefile +42 -0
  14. data/app/assets/javascripts/infinitescroll.js +8 -0
  15. data/app/helpers/pager_helper.rb +5 -0
  16. data/app/views/pager/_first_page.html.erb +11 -0
  17. data/app/views/pager/_first_page.html.haml +9 -0
  18. data/app/views/pager/_first_page.html.slim +10 -0
  19. data/app/views/pager/_gap.html.erb +8 -0
  20. data/app/views/pager/_gap.html.haml +8 -0
  21. data/app/views/pager/_gap.html.slim +10 -0
  22. data/app/views/pager/_last_page.html.erb +11 -0
  23. data/app/views/pager/_last_page.html.haml +9 -0
  24. data/app/views/pager/_last_page.html.slim +10 -0
  25. data/app/views/pager/_next_page.html.erb +11 -0
  26. data/app/views/pager/_next_page.html.haml +9 -0
  27. data/app/views/pager/_next_page.html.slim +10 -0
  28. data/app/views/pager/_page.html.erb +14 -0
  29. data/app/views/pager/_page.html.haml +11 -0
  30. data/app/views/pager/_page.html.slim +13 -0
  31. data/app/views/pager/_paginator.html.erb +25 -0
  32. data/app/views/pager/_paginator.html.haml +19 -0
  33. data/app/views/pager/_paginator.html.slim +20 -0
  34. data/app/views/pager/_prev_page.html.erb +11 -0
  35. data/app/views/pager/_prev_page.html.haml +9 -0
  36. data/app/views/pager/_prev_page.html.slim +10 -0
  37. data/bootstrap_pager.gemspec +36 -0
  38. data/config/locales/pager.yml +19 -0
  39. data/gemfiles/active_record_30.gemfile +9 -0
  40. data/gemfiles/active_record_31.gemfile +7 -0
  41. data/gemfiles/active_record_32.gemfile +10 -0
  42. data/gemfiles/active_record_40.gemfile +8 -0
  43. data/gemfiles/active_record_edge.gemfile +11 -0
  44. data/gemfiles/data_mapper_12.gemfile +15 -0
  45. data/gemfiles/mongo_mapper.gemfile +10 -0
  46. data/gemfiles/mongoid_24.gemfile +7 -0
  47. data/gemfiles/mongoid_30.gemfile +12 -0
  48. data/gemfiles/sinatra_13.gemfile +13 -0
  49. data/gemfiles/sinatra_14.gemfile +13 -0
  50. data/lib/bootstrap_pager/config.rb +51 -0
  51. data/lib/bootstrap_pager/grape.rb +4 -0
  52. data/lib/bootstrap_pager/helpers/action_view_extension.rb +152 -0
  53. data/lib/bootstrap_pager/helpers/paginator.rb +186 -0
  54. data/lib/bootstrap_pager/helpers/sinatra_helpers.rb +144 -0
  55. data/lib/bootstrap_pager/helpers/tags.rb +96 -0
  56. data/lib/bootstrap_pager/hooks.rb +41 -0
  57. data/lib/bootstrap_pager/models/active_record_extension.rb +22 -0
  58. data/lib/bootstrap_pager/models/active_record_model_extension.rb +20 -0
  59. data/lib/bootstrap_pager/models/active_record_relation_methods.rb +29 -0
  60. data/lib/bootstrap_pager/models/array_extension.rb +58 -0
  61. data/lib/bootstrap_pager/models/configuration_methods.rb +48 -0
  62. data/lib/bootstrap_pager/models/data_mapper_collection_methods.rb +15 -0
  63. data/lib/bootstrap_pager/models/data_mapper_extension.rb +48 -0
  64. data/lib/bootstrap_pager/models/mongo_mapper_extension.rb +18 -0
  65. data/lib/bootstrap_pager/models/mongoid_criteria_methods.rb +23 -0
  66. data/lib/bootstrap_pager/models/mongoid_extension.rb +33 -0
  67. data/lib/bootstrap_pager/models/page_scope_methods.rb +70 -0
  68. data/lib/bootstrap_pager/models/plucky_criteria_methods.rb +18 -0
  69. data/lib/bootstrap_pager/railtie.rb +7 -0
  70. data/lib/bootstrap_pager/sinatra.rb +5 -0
  71. data/lib/bootstrap_pager/version.rb +3 -0
  72. data/lib/bootstrap_pager.rb +38 -0
  73. data/lib/generators/pager/config_generator.rb +16 -0
  74. data/lib/generators/pager/templates/pager_config.rb +10 -0
  75. data/lib/generators/pager/views_generator.rb +118 -0
  76. data/spec/config/config_spec.rb +91 -0
  77. data/spec/fake_app/active_record/config.rb +3 -0
  78. data/spec/fake_app/active_record/models.rb +57 -0
  79. data/spec/fake_app/data_mapper/config.rb +7 -0
  80. data/spec/fake_app/data_mapper/models.rb +27 -0
  81. data/spec/fake_app/log/development.log +832 -0
  82. data/spec/fake_app/mongo_mapper/config.rb +2 -0
  83. data/spec/fake_app/mongo_mapper/models.rb +9 -0
  84. data/spec/fake_app/mongoid/config.rb +16 -0
  85. data/spec/fake_app/mongoid/models.rb +22 -0
  86. data/spec/fake_app/rails_app.rb +67 -0
  87. data/spec/fake_app/sinatra_app.rb +22 -0
  88. data/spec/fake_gem.rb +4 -0
  89. data/spec/helpers/action_view_extension_spec.rb +292 -0
  90. data/spec/helpers/helpers_spec.rb +135 -0
  91. data/spec/helpers/sinatra_helpers_spec.rb +170 -0
  92. data/spec/helpers/tags_spec.rb +140 -0
  93. data/spec/models/active_record/active_record_relation_methods_spec.rb +47 -0
  94. data/spec/models/active_record/default_per_page_spec.rb +32 -0
  95. data/spec/models/active_record/max_pages_spec.rb +23 -0
  96. data/spec/models/active_record/max_per_page_spec.rb +32 -0
  97. data/spec/models/active_record/scopes_spec.rb +242 -0
  98. data/spec/models/array_spec.rb +150 -0
  99. data/spec/models/data_mapper/data_mapper_spec.rb +207 -0
  100. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +84 -0
  101. data/spec/models/mongoid/mongoid_spec.rb +126 -0
  102. data/spec/requests/users_spec.rb +53 -0
  103. data/spec/spec_helper.rb +33 -0
  104. data/spec/spec_helper_for_sinatra.rb +34 -0
  105. data/spec/support/database_cleaner.rb +16 -0
  106. data/spec/support/matchers.rb +52 -0
  107. data/vendor/assets/javascripts/jquery.infinitescroll.js +814 -0
  108. data/vendor/assets/javascripts/jquery.infinitescroll.min.js +1 -0
  109. metadata +311 -0
@@ -0,0 +1,2 @@
1
+ MongoMapper.connection = Mongo::Connection.new 'localhost', 27017
2
+ MongoMapper.database = 'bootstrap_pager_test'
@@ -0,0 +1,9 @@
1
+ class User
2
+ include ::MongoMapper::Document
3
+ key :name, String
4
+ key :age, Integer
5
+ end
6
+
7
+ class User::Address
8
+ include ::MongoMapper::Document
9
+ end
@@ -0,0 +1,16 @@
1
+ # Ensure we use 'syck' instead of 'psych' in 1.9.2
2
+ # RubyGems >= 1.5.0 uses 'psych' on 1.9.2, but
3
+ # Psych does not yet support YAML 1.1 merge keys.
4
+ # Merge keys is often used in mongoid.yml
5
+ # See: http://redmine.ruby-lang.org/issues/show/4300
6
+ if RUBY_VERSION >= '1.9.2'
7
+ YAML::ENGINE.yamler = 'syck'
8
+ end
9
+
10
+ Mongoid.configure do |config|
11
+ if Mongoid::VERSION =~ /^3/
12
+ config.sessions = {:default => {:hosts => ['localhost:27017'], :database => 'bootstrap_pager_test'}}
13
+ else
14
+ config.master = Mongo::Connection.new.db('bootstrap_pager_test')
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ class User
2
+ include ::Mongoid::Document
3
+ field :name, :type => String
4
+ field :age, :type => Integer
5
+ end
6
+
7
+ class User::Address
8
+ include ::Mongoid::Document
9
+ end
10
+
11
+ class MongoMongoidExtensionDeveloper
12
+ include ::Mongoid::Document
13
+ field :salary, :type => Integer
14
+ embeds_many :frameworks
15
+ end
16
+
17
+ class Framework
18
+ include ::Mongoid::Document
19
+ field :name, :type => String
20
+ field :language, :type => String
21
+ embedded_in :mongo_mongoid_extension_developer
22
+ end
@@ -0,0 +1,67 @@
1
+ # require 'rails/all'
2
+ require 'action_controller/railtie'
3
+ require 'action_view/railtie'
4
+
5
+ require 'fake_app/active_record/config' if defined? ActiveRecord
6
+ require 'fake_app/data_mapper/config' if defined? DataMapper
7
+ require 'fake_app/mongoid/config' if defined? Mongoid
8
+ require 'fake_app/mongo_mapper/config' if defined? MongoMapper
9
+ # config
10
+ app = Class.new(Rails::Application)
11
+ app.config.secret_token = '3b7cd727ee24e8444053437c36cc66c4'
12
+ app.config.session_store :cookie_store, :key => '_myapp_session'
13
+ app.config.active_support.deprecation = :log
14
+ app.config.eager_load = false
15
+ # Rais.root
16
+ app.config.root = File.dirname(__FILE__)
17
+ Rails.backtrace_cleaner.remove_silencers!
18
+ app.initialize!
19
+
20
+ # fake engine
21
+ module MyEngine
22
+ class Engine < ::Rails::Engine
23
+ isolate_namespace MyEngine
24
+ routes.draw do
25
+ resources :items
26
+ end
27
+ end
28
+ end
29
+
30
+ # routes
31
+ app.routes.draw do
32
+ mount MyEngine::Engine, :at => '/mounted_engine'
33
+ resources :users
34
+ end
35
+
36
+ #models
37
+ require 'fake_app/active_record/models' if defined? ActiveRecord
38
+ require 'fake_app/data_mapper/models' if defined? DataMapper
39
+ require 'fake_app/mongoid/models' if defined? Mongoid
40
+ require 'fake_app/mongo_mapper/models' if defined? MongoMapper
41
+
42
+ # controllers
43
+ class ApplicationController < ActionController::Base; end
44
+ class UsersController < ApplicationController
45
+ def index
46
+ @users = User.page params[:page]
47
+ render :inline => <<-ERB
48
+ <%= @users.map(&:name).join("\n") %>
49
+ <%= paginate @users %>
50
+ ERB
51
+ end
52
+ end
53
+
54
+ if defined? ActiveRecord
55
+ class AddressesController < ApplicationController
56
+ def index
57
+ @addresses = User::Address.page params[:page]
58
+ render :inline => <<-ERB
59
+ <%= @addresses.map(&:street).join("\n") %>
60
+ <%= paginate @addresses %>
61
+ ERB
62
+ end
63
+ end
64
+ end
65
+
66
+ # helpers
67
+ Object.const_set(:ApplicationHelper, Module.new)
@@ -0,0 +1,22 @@
1
+ require 'fake_app/active_record/config' if defined? ActiveRecord
2
+ require 'fake_app/data_mapper/config' if defined? DataMapper
3
+ require 'fake_app/mongoid/config' if defined? Mongoid
4
+ require 'fake_app/mongo_mapper/config' if defined? MongoMapper
5
+
6
+ #models
7
+ require 'fake_app/active_record/models' if defined? ActiveRecord
8
+ require 'fake_app/data_mapper/models' if defined? DataMapper
9
+ require 'fake_app/mongoid/models' if defined? Mongoid
10
+ require 'fake_app/mongo_mapper/models' if defined? MongoMapper
11
+
12
+ class SinatraApp < Sinatra::Base
13
+ register BootstrapPager::Helpers::SinatraHelpers
14
+
15
+ get '/users' do
16
+ @users = User.page params[:page]
17
+ erb <<-ERB
18
+ <%= @users.map(&:name).join("\n") %>
19
+ <%= paginate @users %>
20
+ ERB
21
+ end
22
+ end
data/spec/fake_gem.rb ADDED
@@ -0,0 +1,4 @@
1
+ # Simulate a gem providing a subclass of ActiveRecord::Base before the Railtie is loaded.
2
+
3
+ class GemDefinedModel < ActiveRecord::Base
4
+ end
@@ -0,0 +1,292 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'BootstrapPager::ActionViewExtension' do
4
+ describe '#paginate' do
5
+ before do
6
+ 50.times {|i| User.create! :name => "user#{i}"}
7
+ @users = User.page(1)
8
+ end
9
+ subject { helper.paginate @users, :params => {:controller => 'users', :action => 'index'} }
10
+ it { should be_a String }
11
+
12
+ context 'escaping the pagination for javascript' do
13
+ it 'should escape for javascript' do
14
+ lambda { helper.escape_javascript(helper.paginate @users, :params => {:controller => 'users', :action => 'index'}) }.should_not raise_error
15
+ end
16
+ end
17
+
18
+ if defined? Rails
19
+ context 'using custom engine namespace' do
20
+ subject { helper.paginate @users, :params => {:controller => 'my_engine/items', :action => 'index'}, :engine_namespace => my_engine }
21
+ it { should match(%r(/mounted_engine/items)) }
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#link_to_previous_page' do
27
+ before do
28
+ 50.times {|i| User.create! :name => "user#{i}"}
29
+ end
30
+ context 'having previous pages' do
31
+ before do
32
+ @users = User.page(50)
33
+ end
34
+ context 'the default behaviour' do
35
+ subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
36
+ it { should be_a String }
37
+ it { should match(/rel="previous"/) }
38
+ end
39
+ context 'overriding rel=' do
40
+ subject { helper.link_to_previous_page @users, 'Previous', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
41
+ it { should match(/rel="external"/) }
42
+ end
43
+ if defined? Rails
44
+ context 'using custom engine namespace' do
45
+ subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'my_engine/items', :action => 'index'}, :engine_namespace => my_engine }
46
+ it { should match(%r(/mounted_engine/items)) }
47
+ end
48
+ end
49
+ end
50
+ context 'the first page' do
51
+ before do
52
+ @users = User.page(1)
53
+ end
54
+ subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
55
+ it { should_not be }
56
+ end
57
+ end
58
+
59
+ describe '#link_to_next_page' do
60
+ before do
61
+ 50.times {|i| User.create! :name => "user#{i}"}
62
+ end
63
+ context 'having more page' do
64
+ before do
65
+ @users = User.page(1)
66
+ end
67
+ context 'the default behaviour' do
68
+ subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
69
+ it { should be_a String }
70
+ it { should match(/rel="next"/) }
71
+ end
72
+ context 'overriding rel=' do
73
+ subject { helper.link_to_next_page @users, 'More', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
74
+ it { should match(/rel="external"/) }
75
+ end
76
+ if defined? Rails
77
+ context 'using custom engine namespace' do
78
+ subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'my_engine/items', :action => 'index'}, :engine_namespace => my_engine }
79
+ it { should match(%r(/mounted_engine/items)) }
80
+ end
81
+ end
82
+ end
83
+ context 'the last page' do
84
+ before do
85
+ @users = User.page(2)
86
+ end
87
+ subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
88
+ it { should_not be }
89
+ end
90
+ end
91
+
92
+ describe '#page_entries_info' do
93
+ context 'on a model without namespace' do
94
+ before do
95
+ @users = User.page(1).per(25)
96
+ end
97
+ context 'having no entries' do
98
+ subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
99
+ it { should == 'No users found' }
100
+
101
+ context 'setting the entry name option to "member"' do
102
+ subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
103
+ it { should == 'No members found' }
104
+ end
105
+ end
106
+
107
+ context 'having 1 entry' do
108
+ before do
109
+ User.create! :name => 'user1'
110
+ @users = User.page(1).per(25)
111
+ end
112
+ subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
113
+ it { should == 'Displaying <b>1</b> user' }
114
+
115
+ context 'setting the entry name option to "member"' do
116
+ subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
117
+ it { should == 'Displaying <b>1</b> member' }
118
+ end
119
+ end
120
+
121
+ context 'having more than 1 but less than a page of entries' do
122
+ before do
123
+ 10.times {|i| User.create! :name => "user#{i}"}
124
+ @users = User.page(1).per(25)
125
+ end
126
+ subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
127
+ it { should == 'Displaying <b>all 10</b> users' }
128
+
129
+ context 'setting the entry name option to "member"' do
130
+ subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
131
+ it { should == 'Displaying <b>all 10</b> members' }
132
+ end
133
+ end
134
+
135
+ context 'having more than one page of entries' do
136
+ before do
137
+ 50.times {|i| User.create! :name => "user#{i}"}
138
+ end
139
+
140
+ describe 'the first page' do
141
+ before do
142
+ @users = User.page(1).per(25)
143
+ end
144
+ subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
145
+ it { should == 'Displaying users <b>1&nbsp;-&nbsp;25</b> of <b>50</b> in total' }
146
+
147
+ context 'setting the entry name option to "member"' do
148
+ subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
149
+ it { should == 'Displaying members <b>1&nbsp;-&nbsp;25</b> of <b>50</b> in total' }
150
+ end
151
+ end
152
+
153
+ describe 'the next page' do
154
+ before do
155
+ @users = User.page(2).per(25)
156
+ end
157
+ subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
158
+ it { should == 'Displaying users <b>26&nbsp;-&nbsp;50</b> of <b>50</b> in total' }
159
+
160
+ context 'setting the entry name option to "member"' do
161
+ subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
162
+ it { should == 'Displaying members <b>26&nbsp;-&nbsp;50</b> of <b>50</b> in total' }
163
+ end
164
+ end
165
+ end
166
+ end
167
+ context 'on a model with namespace' do
168
+ before do
169
+ @addresses = User::Address.page(1).per(25)
170
+ end
171
+ context 'having no entries' do
172
+ subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
173
+ it { should == 'No addresses found' }
174
+ end
175
+
176
+ context 'having 1 entry' do
177
+ before do
178
+ User::Address.create!
179
+ @addresses = User::Address.page(1).per(25)
180
+ end
181
+ subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
182
+ it { should == 'Displaying <b>1</b> address' }
183
+
184
+ context 'setting the entry name option to "place"' do
185
+ subject { helper.page_entries_info @addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'} }
186
+ it { should == 'Displaying <b>1</b> place' }
187
+ end
188
+ end
189
+
190
+ context 'having more than 1 but less than a page of entries' do
191
+ before do
192
+ 10.times {|i| User::Address.create!}
193
+ @addresses = User::Address.page(1).per(25)
194
+ end
195
+ subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
196
+ it { should == 'Displaying <b>all 10</b> addresses' }
197
+
198
+ context 'setting the entry name option to "place"' do
199
+ subject { helper.page_entries_info @addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'} }
200
+ it { should == 'Displaying <b>all 10</b> places' }
201
+ end
202
+ end
203
+
204
+ context 'having more than one page of entries' do
205
+ before do
206
+ 50.times {|i| User::Address.create!}
207
+ end
208
+
209
+ describe 'the first page' do
210
+ before do
211
+ @addresses = User::Address.page(1).per(25)
212
+ end
213
+ subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
214
+ it { should == 'Displaying addresses <b>1&nbsp;-&nbsp;25</b> of <b>50</b> in total' }
215
+
216
+ context 'setting the entry name option to "place"' do
217
+ subject { helper.page_entries_info @addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'} }
218
+ it { should == 'Displaying places <b>1&nbsp;-&nbsp;25</b> of <b>50</b> in total' }
219
+ end
220
+ end
221
+
222
+ describe 'the next page' do
223
+ before do
224
+ @addresses = User::Address.page(2).per(25)
225
+ end
226
+ subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
227
+ it { should == 'Displaying addresses <b>26&nbsp;-&nbsp;50</b> of <b>50</b> in total' }
228
+
229
+ context 'setting the entry name option to "place"' do
230
+ subject { helper.page_entries_info @addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'} }
231
+ it { should == 'Displaying places <b>26&nbsp;-&nbsp;50</b> of <b>50</b> in total' }
232
+ end
233
+ end
234
+ end
235
+ end
236
+
237
+ context 'on a PaginatableArray' do
238
+ before do
239
+ @numbers = BootstrapPager.paginate_array(%w{one two three}).page(1)
240
+ end
241
+ subject { helper.page_entries_info @numbers }
242
+ it { should == 'Displaying <b>all 3</b> entries' }
243
+ end
244
+ end
245
+
246
+ describe '#rel_next_prev_link_tags' do
247
+ shared_context 'using custom engine namespace' do
248
+ if defined? Rails
249
+ context 'using custom engine namespace' do
250
+ subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'my_engine/items', :action => 'index'}, :engine_namespace => my_engine }
251
+ it { should match(%r(/mounted_engine/items)) }
252
+ end
253
+ end
254
+ end
255
+ before do
256
+ 75.times {|i| User.create! :name => "user#{i}"}
257
+ end
258
+ context 'the first page' do
259
+ before do
260
+ @users = User.page(1).per(25)
261
+ end
262
+
263
+ subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'users', :action => 'index'} }
264
+ it { should be_a String }
265
+ it { should match(/rel="next"/) }
266
+ it { should_not match(/rel="prev"/) }
267
+ include_context 'using custom engine namespace'
268
+ end
269
+ context 'the middle page' do
270
+ before do
271
+ @users = User.page(2).per(25)
272
+ end
273
+
274
+ subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'users', :action => 'index'} }
275
+ it { should be_a String }
276
+ it { should match(/rel="next"/) }
277
+ it { should match(/rel="prev"/) }
278
+ include_context 'using custom engine namespace'
279
+ end
280
+ context 'the last page' do
281
+ before do
282
+ @users = User.page(3).per(25)
283
+ end
284
+
285
+ subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'users', :action => 'index'} }
286
+ it { should be_a String }
287
+ it { should_not match(/rel="next"/) }
288
+ it { should match(/rel="prev"/) }
289
+ include_context 'using custom engine namespace'
290
+ end
291
+ end
292
+ end
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+ include BootstrapPager::Helpers
3
+
4
+ describe 'BootstrapPager::Helpers::Paginator' do
5
+ let :template do
6
+ stub(r = Object.new) do
7
+ render.with_any_args
8
+ params { {} }
9
+ options { {} }
10
+ url_for {|h| "/foo?page=#{h[:page]}"}
11
+ end
12
+ r
13
+ end
14
+
15
+ describe '#params' do
16
+ before do
17
+ @paginator = Paginator.new(template, :params => {:controller => 'foo', :action => 'bar'})
18
+ end
19
+ subject { @paginator.page_tag(template).instance_variable_get('@params') }
20
+ it { should == {:controller => 'foo', :action => 'bar'} }
21
+ end
22
+
23
+ describe '#param_name' do
24
+ before do
25
+ @paginator = Paginator.new(template, :param_name => :pagina)
26
+ end
27
+ subject { @paginator.page_tag(template).instance_variable_get('@param_name') }
28
+ it { should == :pagina }
29
+ end
30
+
31
+ #TODO test somehow...
32
+ # describe '#tagify_links' do
33
+ # def tags_with(options)
34
+ # PaginationRenderer.new(template, options).tagify_links
35
+ # end
36
+
37
+ # context '1 page in total' do
38
+ # subject { tags_with :total_pages => 1, :current_page => 1 }
39
+ # it { should have(0).tags }
40
+ # end
41
+
42
+ # context '10 pages in total' do
43
+ # context 'first page' do
44
+ # subject { tags_with :total_pages => 10, :current_page => 1 }
45
+ # it { should_not contain_tag PrevLink }
46
+ # it { should contain_tag PrevSpan }
47
+ # it { should contain_tag CurrentPage }
48
+ # it { should_not contain_tag FirstPageLink }
49
+ # it { should contain_tag LastPageLink }
50
+ # it { should contain_tag PageLink }
51
+ # it { should contain_tag NextLink }
52
+ # it { should_not contain_tag NextSpan }
53
+ # it { should contain_tag TruncatedSpan }
54
+ # end
55
+
56
+ # context 'second page' do
57
+ # subject { tags_with :total_pages => 10, :current_page => 2 }
58
+ # it { should contain_tag PrevLink }
59
+ # it { should_not contain_tag PrevSpan }
60
+ # it { should contain_tag CurrentPage }
61
+ # it { should contain_tag FirstPageLink }
62
+ # it { should contain_tag LastPageLink }
63
+ # it { should contain_tag PageLink }
64
+ # it { should contain_tag NextLink }
65
+ # it { should_not contain_tag NextSpan }
66
+ # it { should contain_tag TruncatedSpan }
67
+ # end
68
+
69
+ # context 'third page' do
70
+ # subject { tags_with :total_pages => 10, :current_page => 3 }
71
+ # it { should contain_tag PrevLink }
72
+ # it { should_not contain_tag PrevSpan }
73
+ # it { should contain_tag CurrentPage }
74
+ # it { should contain_tag FirstPageLink }
75
+ # it { should contain_tag LastPageLink }
76
+ # it { should contain_tag PageLink }
77
+ # it { should contain_tag NextLink }
78
+ # it { should_not contain_tag NextSpan }
79
+ # it { should contain_tag TruncatedSpan }
80
+ # end
81
+
82
+ # context 'fourth page(no truncation)' do
83
+ # subject { tags_with :total_pages => 10, :current_page => 4 }
84
+ # it { should contain_tag PrevLink }
85
+ # it { should_not contain_tag PrevSpan }
86
+ # it { should contain_tag CurrentPage }
87
+ # it { should contain_tag FirstPageLink }
88
+ # it { should contain_tag LastPageLink }
89
+ # it { should contain_tag PageLink }
90
+ # it { should contain_tag NextLink }
91
+ # it { should_not contain_tag NextSpan }
92
+ # it { should_not contain_tag TruncatedSpan }
93
+ # end
94
+
95
+ # context 'seventh page(no truncation)' do
96
+ # subject { tags_with :total_pages => 10, :current_page => 7 }
97
+ # it { should contain_tag PrevLink }
98
+ # it { should_not contain_tag PrevSpan }
99
+ # it { should contain_tag CurrentPage }
100
+ # it { should contain_tag FirstPageLink }
101
+ # it { should contain_tag LastPageLink }
102
+ # it { should contain_tag PageLink }
103
+ # it { should contain_tag NextLink }
104
+ # it { should_not contain_tag NextSpan }
105
+ # it { should_not contain_tag TruncatedSpan }
106
+ # end
107
+
108
+ # context 'eighth page' do
109
+ # subject { tags_with :total_pages => 10, :current_page => 8 }
110
+ # it { should contain_tag PrevLink }
111
+ # it { should_not contain_tag PrevSpan }
112
+ # it { should contain_tag CurrentPage }
113
+ # it { should contain_tag FirstPageLink }
114
+ # it { should contain_tag LastPageLink }
115
+ # it { should contain_tag PageLink }
116
+ # it { should contain_tag NextLink }
117
+ # it { should_not contain_tag NextSpan }
118
+ # it { should contain_tag TruncatedSpan }
119
+ # end
120
+
121
+ # context 'last page' do
122
+ # subject { tags_with :total_pages => 10, :current_page => 10 }
123
+ # it { should contain_tag PrevLink }
124
+ # it { should_not contain_tag PrevSpan }
125
+ # it { should contain_tag CurrentPage }
126
+ # it { should contain_tag FirstPageLink }
127
+ # it { should_not contain_tag LastPageLink }
128
+ # it { should contain_tag PageLink }
129
+ # it { should_not contain_tag NextLink }
130
+ # it { should contain_tag NextSpan }
131
+ # it { should contain_tag TruncatedSpan }
132
+ # end
133
+ # end
134
+ # end
135
+ end