|
203 | 203 | page.should have_content('Displaying 1 Post')
|
204 | 204 | end
|
205 | 205 | end
|
206 |
| - |
207 | 206 | end
|
| 207 | + |
| 208 | + context 'with 100 posts' do |
| 209 | + let(:per_page) { 30 } |
| 210 | + let(:posts_size) { 100 } |
| 211 | + |
| 212 | + before do |
| 213 | + posts_size.times { |n| |
| 214 | + Post.create!(title: "Quick Brown Fox #{n}", body: 'The quick brown fox jumps over the lazy dog.', view_count: 5, admin_user: admin_user, other_user: other_user) |
| 215 | + } |
| 216 | + |
| 217 | + click_on 'Posts' |
| 218 | + end |
| 219 | + |
| 220 | + describe "paginator" do |
| 221 | + it "must have paginator with 4 pages" do |
| 222 | + page.should have_css('.pagination > .page.current') |
| 223 | + page.all(:css, '.pagination > .page').size.should == 4 |
| 224 | + end |
| 225 | + |
| 226 | + it "must show each page correctly" do |
| 227 | + # temprorary go to page 2 |
| 228 | + page.find('.pagination > .page > a', text: '2').click |
| 229 | + |
| 230 | + nbsp = Nokogiri::HTML(" ").text |
| 231 | + |
| 232 | + (1..4).each do |page_number| |
| 233 | + page.find('.pagination > .page > a', text: page_number).click |
| 234 | + page.find('.pagination_information').should have_content('Displaying Posts') |
| 235 | + |
| 236 | + offset = (page_number - 1) * per_page |
| 237 | + collection_size = [per_page, posts_size - (page_number - 1) * per_page].min |
| 238 | + |
| 239 | + display_total_text = I18n.t 'active_admin.pagination.multiple', :model => 'Posts', :total => posts_size, |
| 240 | + :from => offset + 1, :to => offset + collection_size |
| 241 | + |
| 242 | + pagination_information = page.find('.pagination_information').native.to_s.gsub(nbsp,' ') |
| 243 | + pagination_information.should include(display_total_text.gsub(' ', ' ')) |
| 244 | + end |
| 245 | + end |
| 246 | + end |
| 247 | + end # context 'with 100 posts' |
| 248 | + |
208 | 249 | end
|
209 | 250 |
|
210 | 251 | end
|
0 commit comments