X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/62b70f45bc2566d3ca3c0d79c72da7d46d5f49a4..bcf5782fb5a3a916ea036ce78ecd2a1208ace87f:/test/controllers/accounts/pd_declarations_controller_test.rb diff --git a/test/controllers/accounts/pd_declarations_controller_test.rb b/test/controllers/accounts/pd_declarations_controller_test.rb index 4b961e326..fe3c8bad2 100644 --- a/test/controllers/accounts/pd_declarations_controller_test.rb +++ b/test/controllers/accounts/pd_declarations_controller_test.rb @@ -9,6 +9,10 @@ module Accounts { :path => "/account/pd_declaration", :method => :get }, { :controller => "accounts/pd_declarations", :action => "show" } ) + assert_routing( + { :path => "/account/pd_declaration", :method => :post }, + { :controller => "accounts/pd_declarations", :action => "create" } + ) end def test_show_not_logged_in @@ -25,5 +29,64 @@ module Accounts assert_response :success end + + def test_create_not_logged_in + post account_pd_declaration_path + + assert_response :forbidden + end + + def test_create_unconfirmed + user = create(:user) + session_for(user) + + post account_pd_declaration_path + + assert_redirected_to account_path + assert_nil flash[:notice] + assert_equal "You didn't confirm that you consider your edits to be in the Public Domain.", flash[:warning] + + user.reload + assert_not_predicate user, :consider_pd + end + + def test_create_confirmed + user = create(:user) + session_for(user) + + post account_pd_declaration_path, :params => { :consider_pd => true } + + assert_equal "You have successfully declared that you consider your edits to be in the Public Domain.", flash[:notice] + assert_nil flash[:warning] + + user.reload + assert_predicate user, :consider_pd + end + + def test_create_already_declared_unconfirmed + user = create(:user, :consider_pd => true) + session_for(user) + + post account_pd_declaration_path + + assert_nil flash[:notice] + assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning] + + user.reload + assert_predicate user, :consider_pd + end + + def test_create_already_declared_confirmed + user = create(:user, :consider_pd => true) + session_for(user) + + post account_pd_declaration_path, :params => { :consider_pd => true } + + assert_nil flash[:notice] + assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning] + + user.reload + assert_predicate user, :consider_pd + end end end