Skip to content

Commit

Permalink
Merge pull request #178 from reprah/fix-pagination
Browse files Browse the repository at this point in the history
Fix pagination links for support questions
  • Loading branch information
PragTob committed Nov 11, 2013
2 parents d21b6b0 + 198ae34 commit f2e2de8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/questions/index.html.haml
Expand Up @@ -26,4 +26,4 @@
%ul.questions
= render :partial => "list", :collection => collection, :as => :question

= will_paginate
= will_paginate(@questions, renderer: @support ? PrefixLinkRenderer.new('/support') : nil)
13 changes: 13 additions & 0 deletions features/questions_pagination.feature
@@ -0,0 +1,13 @@
Feature: Pagination for different types of questions

As a user of the site, I can view pages of different types of questions

Scenario: View support questions
Given support questions exist
When I visit the support questions page
Then I should see a link to the next page of support questions

Scenario: View non-support questions
Given questions exist
When I visit the questions page
Then I should see a link to the next page of questions
16 changes: 16 additions & 0 deletions features/step_definitions/question_steps.rb
Expand Up @@ -76,3 +76,19 @@ def create_question_for(user)
visit question_path(@question)
page.should_not have_content('Delete')
end

Given /^(\w*)\s?questions exist$/ do |type|
30.times do
Question.create(title: 'Test', description: 'Test',
support: type == 'support' ? true : false)
end
end

When /^I visit the (\w*)\s?questions page$/ do |type|
visit(type == 'support' ? support_questions_path : questions_path)
end

Then /^I should see a link to the next page of (\w*)\s?questions$/ do |type|
href = type == 'support' ? '/support/questions?page=2' : '/questions?page=2'
page.should have_link '2', href: href
end
12 changes: 12 additions & 0 deletions lib/prefix_link_renderer.rb
@@ -0,0 +1,12 @@
class PrefixLinkRenderer < WillPaginate::ActionView::LinkRenderer
def initialize(prefix)
@prefix = prefix
super()
end

protected

def url(page)
@prefix + super
end
end

0 comments on commit f2e2de8

Please sign in to comment.