]> git.openstreetmap.org Git - rails.git/blob - test/controllers/accounts/pd_declarations_controller_test.rb
Merge remote-tracking branch 'upstream/pull/5521'
[rails.git] / test / controllers / accounts / pd_declarations_controller_test.rb
1 require "test_helper"
2
3 module Accounts
4   class PdDeclarationsControllerTest < ActionDispatch::IntegrationTest
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/account/pd_declaration", :method => :get },
10         { :controller => "accounts/pd_declarations", :action => "show" }
11       )
12       assert_routing(
13         { :path => "/account/pd_declaration", :method => :post },
14         { :controller => "accounts/pd_declarations", :action => "create" }
15       )
16     end
17
18     def test_show_not_logged_in
19       get account_pd_declaration_path
20
21       assert_redirected_to login_path(:referer => account_pd_declaration_path)
22     end
23
24     def test_show_agreed
25       user = create(:user)
26       session_for(user)
27
28       get account_pd_declaration_path
29
30       assert_response :success
31     end
32
33     def test_create_not_logged_in
34       post account_pd_declaration_path
35
36       assert_response :forbidden
37     end
38
39     def test_create_unconfirmed
40       user = create(:user)
41       session_for(user)
42
43       post account_pd_declaration_path
44
45       assert_redirected_to edit_account_path
46       assert_nil flash[:notice]
47       assert_equal "You didn't confirm that you consider your edits to be in the Public Domain.", flash[:warning]
48
49       user.reload
50       assert_not_predicate user, :consider_pd
51     end
52
53     def test_create_confirmed
54       user = create(:user)
55       session_for(user)
56
57       post account_pd_declaration_path, :params => { :consider_pd => true }
58
59       assert_equal "You have successfully declared that you consider your edits to be in the Public Domain.", flash[:notice]
60       assert_nil flash[:warning]
61
62       user.reload
63       assert_predicate user, :consider_pd
64     end
65
66     def test_create_already_declared_unconfirmed
67       user = create(:user, :consider_pd => true)
68       session_for(user)
69
70       post account_pd_declaration_path
71
72       assert_nil flash[:notice]
73       assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning]
74
75       user.reload
76       assert_predicate user, :consider_pd
77     end
78
79     def test_create_already_declared_confirmed
80       user = create(:user, :consider_pd => true)
81       session_for(user)
82
83       post account_pd_declaration_path, :params => { :consider_pd => true }
84
85       assert_nil flash[:notice]
86       assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning]
87
88       user.reload
89       assert_predicate user, :consider_pd
90     end
91   end
92 end