Skip to content

Commit 198ae34

Browse files
committed
Fix pagination links for support questions
1 parent d21b6b0 commit 198ae34

4 files changed

Lines changed: 42 additions & 1 deletion

File tree

app/views/questions/index.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
%ul.questions
2727
= render :partial => "list", :collection => collection, :as => :question
2828

29-
= will_paginate
29+
= will_paginate(@questions, renderer: @support ? PrefixLinkRenderer.new('/support') : nil)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Feature: Pagination for different types of questions
2+
3+
As a user of the site, I can view pages of different types of questions
4+
5+
Scenario: View support questions
6+
Given support questions exist
7+
When I visit the support questions page
8+
Then I should see a link to the next page of support questions
9+
10+
Scenario: View non-support questions
11+
Given questions exist
12+
When I visit the questions page
13+
Then I should see a link to the next page of questions

features/step_definitions/question_steps.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,19 @@ def create_question_for(user)
7676
visit question_path(@question)
7777
page.should_not have_content('Delete')
7878
end
79+
80+
Given /^(\w*)\s?questions exist$/ do |type|
81+
30.times do
82+
Question.create(title: 'Test', description: 'Test',
83+
support: type == 'support' ? true : false)
84+
end
85+
end
86+
87+
When /^I visit the (\w*)\s?questions page$/ do |type|
88+
visit(type == 'support' ? support_questions_path : questions_path)
89+
end
90+
91+
Then /^I should see a link to the next page of (\w*)\s?questions$/ do |type|
92+
href = type == 'support' ? '/support/questions?page=2' : '/questions?page=2'
93+
page.should have_link '2', href: href
94+
end

lib/prefix_link_renderer.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class PrefixLinkRenderer < WillPaginate::ActionView::LinkRenderer
2+
def initialize(prefix)
3+
@prefix = prefix
4+
super()
5+
end
6+
7+
protected
8+
9+
def url(page)
10+
@prefix + super
11+
end
12+
end

0 commit comments

Comments
 (0)