X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/aca2ebb98aeae4744e3c50f9fca7e08a1dd784a2..d4a5eeb90abdaa3785698164249b00d80fa64634:/test/functional/quickvote_controller_test.rb diff --git a/test/functional/quickvote_controller_test.rb b/test/functional/quickvote_controller_test.rb index ceb1b6b..076a104 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" @@ -41,8 +51,68 @@ class QuickvoteControllerTest < Test::Unit::TestCase assert_template "quickvote/create" end + def test_create_quickvote_nil_candidate + post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => nil}) + assert_template "quickvote/create" + post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => []}) + assert_template "quickvote/create" + end + def test_get_quickvote_nonexistent get :index, { 'ident' => "idontexist" } assert_redirected_to :controller => 'site' end + + def test_get_result_empty_vote + test_create_quickvote + get :results, { 'ident' => 'variable' } + assert_response :success + end + + def test_get_result_nonexistent + test_create_quickvote + get :results, { 'ident' => 'asdflaksdjf' } + 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 + + def test_cast_dupe_quickvote + test_create_quickvote + votes = QuickVote.ident_to_quickvote('variable').candidates.collect { |c| c.id} + get :index, { 'ident' => 'variable' } + assert_response :success + + post :confirm, { 'ident' => 'variable', 'rankings-list' => votes.sort_by {rand} } + assert_template 'quickvote/thanks' + + get :index, { 'ident' => 'variable' } + assert_response :success + post :confirm, { 'ident' => 'variable', 'rankings-list' => votes.sort_by {rand} } + assert_redirected_to :controller => 'quickvote', :ident => 'variable' + end end