]> git.openstreetmap.org Git - rails.git/blob - test/controllers/accounts/pd_declarations_controller_test.rb
Merge pull request #5932 from tomhughes/frozen-strings
[rails.git] / test / controllers / accounts / pd_declarations_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 module Accounts
6   class PdDeclarationsControllerTest < ActionDispatch::IntegrationTest
7     ##
8     # test all routes which lead to this controller
9     def test_routes
10       assert_routing(
11         { :path => "/account/pd_declaration", :method => :get },
12         { :controller => "accounts/pd_declarations", :action => "show" }
13       )
14       assert_routing(
15         { :path => "/account/pd_declaration", :method => :post },
16         { :controller => "accounts/pd_declarations", :action => "create" }
17       )
18     end
19
20     def test_show_not_logged_in
21       get account_pd_declaration_path
22
23       assert_redirected_to login_path(:referer => account_pd_declaration_path)
24     end
25
26     def test_show_agreed
27       user = create(:user)
28       session_for(user)
29
30       get account_pd_declaration_path
31
32       assert_response :success
33     end
34
35     def test_create_not_logged_in
36       post account_pd_declaration_path
37
38       assert_response :forbidden
39     end
40
41     def test_create_unconfirmed
42       user = create(:user)
43       session_for(user)
44
45       post account_pd_declaration_path
46
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]
50
51       user.reload
52       assert_not_predicate user, :consider_pd
53     end
54
55     def test_create_confirmed
56       user = create(:user)
57       session_for(user)
58
59       post account_pd_declaration_path, :params => { :consider_pd => true }
60
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]
63
64       user.reload
65       assert_predicate user, :consider_pd
66     end
67
68     def test_create_already_declared_unconfirmed
69       user = create(:user, :consider_pd => true)
70       session_for(user)
71
72       post account_pd_declaration_path
73
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]
76
77       user.reload
78       assert_predicate user, :consider_pd
79     end
80
81     def test_create_already_declared_confirmed
82       user = create(:user, :consider_pd => true)
83       session_for(user)
84
85       post account_pd_declaration_path, :params => { :consider_pd => true }
86
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]
89
90       user.reload
91       assert_predicate user, :consider_pd
92     end
93   end
94 end