|
338 | 338 | end
|
339 | 339 | end
|
340 | 340 |
|
341 |
| - describe 'GET /admin/player with 3 pages, page 2' do |
| 341 | + context 'List with 3 pages' do |
| 342 | + def visit_page(page) |
| 343 | + visit index_path(model_name: 'player', page: page) |
| 344 | + end |
| 345 | + |
342 | 346 | before do
|
343 | 347 | RailsAdmin.config.default_items_per_page = 1
|
344 |
| - items_per_page = RailsAdmin.config.default_items_per_page |
345 |
| - (items_per_page * 3).times { FactoryGirl.create(:player) } |
346 |
| - visit index_path(model_name: 'player', page: 2) |
| 348 | + (RailsAdmin.config.default_items_per_page * 3).times { FactoryGirl.create(:player) } |
347 | 349 | end
|
348 | 350 |
|
349 |
| - it 'paginates correctly' do |
350 |
| - expect(find('ul.pagination li:first')).to have_content('« Prev') |
351 |
| - expect(find('ul.pagination li:last')).to have_content('Next »') |
352 |
| - expect(find('ul.pagination li.active')).to have_content('2') |
353 |
| - end |
354 |
| - end |
| 351 | + describe 'with limited_pagination=false' do |
| 352 | + it 'page 1' do |
| 353 | + visit_page(1) |
355 | 354 |
|
356 |
| - describe 'list with 3 pages, page 3' do |
357 |
| - before do |
358 |
| - items_per_page = RailsAdmin.config.default_items_per_page |
359 |
| - @players = Array.new((items_per_page * 3)) { FactoryGirl.create(:player) } |
360 |
| - visit index_path(model_name: 'player', page: 3) |
| 355 | + within('ul.pagination') do |
| 356 | + expect(find('li:first')).to have_content('« Prev') |
| 357 | + expect(find('li:last')).to have_content('Next »') |
| 358 | + expect(find('li.active')).to have_content('1') |
| 359 | + end |
| 360 | + end |
| 361 | + |
| 362 | + it 'page 2' do |
| 363 | + visit_page(2) |
| 364 | + |
| 365 | + within('ul.pagination') do |
| 366 | + expect(find('li:first')).to have_content('« Prev') |
| 367 | + expect(find('li:last')).to have_content('Next »') |
| 368 | + expect(find('li.active')).to have_content('2') |
| 369 | + end |
| 370 | + end |
| 371 | + |
| 372 | + it 'page 3' do |
| 373 | + visit_page(3) |
| 374 | + |
| 375 | + within('ul.pagination') do |
| 376 | + expect(find('li:first')).to have_content('« Prev') |
| 377 | + expect(find('li:last')).to have_content('Next »') |
| 378 | + expect(find('li.active')).to have_content('3') |
| 379 | + end |
| 380 | + end |
361 | 381 | end
|
362 | 382 |
|
363 |
| - it 'paginates correctly and contain the right item' do |
364 |
| - expect(find('ul.pagination li:first')).to have_content('« Prev') |
365 |
| - expect(find('ul.pagination li:last')).to have_content('Next »') |
366 |
| - expect(find('ul.pagination li.active')).to have_content('3') |
| 383 | + context 'with limited_pagination=true' do |
| 384 | + before do |
| 385 | + allow(RailsAdmin::AbstractModel.new(Player).config.list). |
| 386 | + to receive(:limited_pagination). |
| 387 | + and_return(true) |
| 388 | + end |
| 389 | + |
| 390 | + it 'page 1' do |
| 391 | + visit_page(1) |
| 392 | + |
| 393 | + within('ul.pagination') do |
| 394 | + expect(find('li:first')).not_to have_content('« Prev') |
| 395 | + expect(find('li:last')).to have_content('Next »') |
| 396 | + end |
| 397 | + end |
| 398 | + |
| 399 | + it 'page 2' do |
| 400 | + visit_page(2) |
| 401 | + |
| 402 | + within('ul.pagination') do |
| 403 | + expect(find('li:first')).to have_content('« Prev') |
| 404 | + expect(find('li:last')).to have_content('Next »') |
| 405 | + end |
| 406 | + end |
| 407 | + |
| 408 | + it 'page 3' do |
| 409 | + visit_page(3) |
| 410 | + |
| 411 | + within('ul.pagination') do |
| 412 | + expect(find('li:first')).to have_content('« Prev') |
| 413 | + expect(find('li:last')).to have_content('Next »') |
| 414 | + end |
| 415 | + end |
367 | 416 | end
|
368 | 417 | end
|
369 | 418 |
|
|
0 commit comments