1 # frozen_string_literal: true
 
   6   class PdDeclarationsControllerTest < ActionDispatch::IntegrationTest
 
   8     # test all routes which lead to this controller
 
  11         { :path => "/account/pd_declaration", :method => :get },
 
  12         { :controller => "accounts/pd_declarations", :action => "show" }
 
  15         { :path => "/account/pd_declaration", :method => :post },
 
  16         { :controller => "accounts/pd_declarations", :action => "create" }
 
  20     def test_show_not_logged_in
 
  21       get account_pd_declaration_path
 
  23       assert_redirected_to login_path(:referer => account_pd_declaration_path)
 
  30       get account_pd_declaration_path
 
  32       assert_response :success
 
  35     def test_create_not_logged_in
 
  36       post account_pd_declaration_path
 
  38       assert_response :forbidden
 
  41     def test_create_unconfirmed
 
  45       post account_pd_declaration_path
 
  47       assert_redirected_to account_path
 
  48       assert_nil flash[:notice]
 
  49       assert_equal "You didn't confirm that you consider your edits to be in the Public Domain.", flash[:warning]
 
  52       assert_not_predicate user, :consider_pd
 
  55     def test_create_confirmed
 
  59       post account_pd_declaration_path, :params => { :consider_pd => true }
 
  61       assert_equal "You have successfully declared that you consider your edits to be in the Public Domain.", flash[:notice]
 
  62       assert_nil flash[:warning]
 
  65       assert_predicate user, :consider_pd
 
  68     def test_create_already_declared_unconfirmed
 
  69       user = create(:user, :consider_pd => true)
 
  72       post account_pd_declaration_path
 
  74       assert_nil flash[:notice]
 
  75       assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning]
 
  78       assert_predicate user, :consider_pd
 
  81     def test_create_already_declared_confirmed
 
  82       user = create(:user, :consider_pd => true)
 
  85       post account_pd_declaration_path, :params => { :consider_pd => true }
 
  87       assert_nil flash[:notice]
 
  88       assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning]
 
  91       assert_predicate user, :consider_pd