Permalink
Browse files

home page now shows a random Inquest on which the current user has no…

…t ruled
  • Loading branch information...
1 parent c374710 commit feee2a40c57dc0e5f17d94eefd2cfaff0ab6e6db @jamesarosen committed Jan 18, 2010
@@ -15,4 +15,12 @@ def not_found(e = nil)
render :action => '/pages/not_found', :status => :not_found
end
+ def inquest_ids_ruled_on_by_current_user
+ session[:ruled_on_inquest_ids] ||= []
+ end
+
+ def current_user_has_ruled_on_inquest(inquest)
+ inquest_ids_ruled_on_by_current_user << inquest.id
+ end
+
end
@@ -1,7 +1,7 @@
class PagesController < ApplicationController
def home
- @inquest = Inquest.last
+ @inquest = Inquest.random_not_including(inquest_ids_ruled_on_by_current_user)
if @inquest.present?
render :action => '/inquests/show'
else
@@ -1,5 +1,11 @@
require 'test_helper'
+ApplicationController.class_eval do
+ def public_current_user_has_ruled_on_inquest(i)
+ current_user_has_ruled_on_inquest(i)
+ end
+end
+
class PagesControllerTest < ActionController::TestCase
setup do
@@ -13,6 +19,16 @@ class PagesControllerTest < ActionController::TestCase
assert_select "a[href='#{new_inquest_path}']"
assert_template '/inquests/none'
end
+
+ test 'showing the home page when the user has ruled on all inquests should be OK' do
+ Inquest.all.each do |i|
+ @controller.public_current_user_has_ruled_on_inquest(i)
+ end
+ get :home
+ assert_response :success
+ assert_select "a[href='#{new_inquest_path}']"
+ assert_template '/inquests/none'
+ end
test 'should route / to pages/home' do
assert_routing '/', :controller => 'pages', :action => 'home'

0 comments on commit feee2a4

Please sign in to comment.