X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/aa6f2f886d78c6cf42ee284ded1ce3cd3db1c632..215cf287e52da41605cb033da236a6b0aeee4f3a:/test/functional/quickvote_controller_test.rb?ds=sidebyside diff --git a/test/functional/quickvote_controller_test.rb b/test/functional/quickvote_controller_test.rb index a390d94..e116c0d 100644 --- a/test/functional/quickvote_controller_test.rb +++ b/test/functional/quickvote_controller_test.rb @@ -28,7 +28,7 @@ class QuickvoteControllerTest < Test::Unit::TestCase end def test_create_quickvote - post(:create, {'commit' =>"Create Quickvote", 'quickvote' =>{'name' =>"variable", 'description' =>"Favorite variable."}}, nil, {:candlist=>["foo", "bar", "foobar"]}) + post(:create, {'commit' =>"Create Quickvote", 'quickvote' =>{'name' =>"variable", 'description' =>"Favorite variable."}}, nil, {:candidate_names=>["foo", "bar", "foobar"]}) assert_template "quickvote/success" get :index, { 'ident' => "variable"} assert_response :success @@ -42,25 +42,25 @@ class QuickvoteControllerTest < Test::Unit::TestCase 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" + post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candidate_names => ["foo", "bar", "foobar"]}) + assert_template "quickvote/_create_sidebar" end def test_create_quickvote_dupe_candidate - post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => ["foo", "bar", "bar", "foobar"]}) - assert_template "quickvote/create" + post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candidate_names => ["foo", "bar", "bar", "foobar"]}) + assert_template "quickvote/_create_sidebar" 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" + post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candidate_names => nil}) + assert_template "quickvote/_create_sidebar" + post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candidate_names => []}) + assert_template "quickvote/_create_sidebar" end def test_get_quickvote_nonexistent get :index, { 'ident' => "idontexist" } - assert_redirected_to :controller => 'site' + assert_redirected_to :controller => 'front' end def test_get_result_empty_vote @@ -72,7 +72,7 @@ class QuickvoteControllerTest < Test::Unit::TestCase def test_get_result_nonexistent test_create_quickvote get :results, { 'ident' => 'asdflaksdjf' } - assert_redirected_to :controller => 'site' + assert_redirected_to :controller => 'front' end def test_get_result_with_a_vote @@ -100,4 +100,55 @@ class QuickvoteControllerTest < Test::Unit::TestCase 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 + + def test_display_tainted_quickvote + # create quickvote with tainted data + test_create_quickvote + qv=QuickVote.ident_to_quickvote('variable') + qv.description="foo" + qv.candidate_names = ["foo", "bar", "", + 'bar'] + qv.save! + + # display the vote/index page and check for bad tags and the ability + # to make an image tag + get :index, { 'ident' => 'variable' } + assert_response :success + assert_no_tag :tag => "object" + assert_no_tag :tag => "foobar" + assert_tag :tag => "img", + :parent => { :tag => "li", :attributes => { :class => "moveable" } } + + # actually vote + votes = QuickVote.ident_to_quickvote('variable').candidates.collect { |c| c.id} + post :confirm, { 'ident' => 'variable', 'rankings-list' => votes.sort_by {rand} } + + # check for bad/good tags + assert_template('quickvote/thanks') + assert_no_tag :tag => "object" + assert_no_tag :tag => "foobar" + assert_tag :tag => "img", :parent => { :tag => "li" } + + # get the results page and check for good/bad tags + get :results, { 'ident' => 'variable' } + assert_response :success + assert_no_tag :tag => "object" + assert_no_tag :tag => "foobar" + assert_tag :tag => "img", :parent => { :tag => "li" } + end end