From aa6f2f886d78c6cf42ee284ded1ce3cd3db1c632 Mon Sep 17 00:00:00 2001 From: John Dong Date: Mon, 20 Aug 2007 15:56:39 -0400 Subject: [PATCH] * Fix the session_id accessor. Previous version looks for wrong method * Added new testcases - Creating same-name quickvote - Test retrieving results of quickvotes with 0, 1, and 5 votes - Test casting a quickvote --- test/functional/quickvote_controller_test.rb | 37 +++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/test/functional/quickvote_controller_test.rb b/test/functional/quickvote_controller_test.rb index 07c9278..a390d94 100644 --- a/test/functional/quickvote_controller_test.rb +++ b/test/functional/quickvote_controller_test.rb @@ -5,7 +5,10 @@ class ActionController::TestSession def session_id # Override this so we can set session ID # pass in the 'test_session_id' session variable to override default - (@session and @session['test_session_id']) or "12345678" + return "12345678" unless @attributes + if @attributes.has_key? 'test_session_id' + return @attributes['test_session_id'] + end end end # Re-raise errors caught by the controller. @@ -31,6 +34,13 @@ class QuickvoteControllerTest < Test::Unit::TestCase assert_response :success end + def test_create_dupe_quickvote + test_create_quickvote + assert_raise(Test::Unit::AssertionFailedError) do + test_create_quickvote + end + end + def test_create_quickvote_badname post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => ["foo", "bar", "foobar"]}) assert_template "quickvote/create" @@ -65,4 +75,29 @@ class QuickvoteControllerTest < Test::Unit::TestCase assert_redirected_to :controller => 'site' end + def test_get_result_with_a_vote + test_cast_quickvote + get :results, { 'ident' => 'variable' } + assert_response :success + end + + def test_get_result_multi_votes + test_create_quickvote + votes = QuickVote.ident_to_quickvote('variable').candidates.collect { |c| c.id} + 5.times do |time| + get :index, { 'ident' => 'variable' }, { 'test_session_id' => (time+1)*50 } + assert_response :success + post :confirm, { 'ident' => 'variable', 'rankings-list' => votes.sort_by {rand} }, { 'test_session_id' => (time+1)*50 } + assert_template 'quickvote/thanks' + end + get :results, { 'ident' => 'variable' } + assert_response :success + end + + def test_cast_quickvote + test_create_quickvote + votes = QuickVote.ident_to_quickvote('variable').candidates.collect { |c| c.id} + post :confirm, { 'ident' => 'variable', 'rankings-list' => votes.sort_by {rand} } + assert_template 'quickvote/thanks' + end end -- 2.39.5