]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles/heatmaps_controller_test.rb
Merge pull request #6658 from Dimitar5555/patch-1
[rails.git] / test / controllers / profiles / heatmaps_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 module Profiles
6   class HeatmapsControllerTest < ActionDispatch::IntegrationTest
7     ##
8     # test all routes which lead to this controller
9     def test_routes
10       assert_routing(
11         { :path => "/profile/heatmap", :method => :get },
12         { :controller => "profiles/heatmaps", :action => "show" }
13       )
14       assert_routing(
15         { :path => "/profile/heatmap", :method => :put },
16         { :controller => "profiles/heatmaps", :action => "update" }
17       )
18     end
19
20     def test_show
21       user = create(:user)
22       session_for(user)
23
24       get profile_heatmap_path
25
26       assert_response :success
27       assert_template :show
28     end
29
30     def test_show_unauthorized
31       get profile_heatmap_path
32
33       assert_redirected_to login_path(:referer => profile_heatmap_path)
34     end
35
36     def test_update
37       user = create(:user, :public_heatmap => true)
38       session_for(user)
39
40       heatmap_selector = ".heatmap_frame"
41
42       assert_predicate user.reload, :public_heatmap?
43       get user_path(user)
44       assert_select heatmap_selector
45
46       put profile_heatmap_path, :params => { :user => { :public_heatmap => "0" } }
47
48       assert_redirected_to user_path(user)
49       follow_redirect!
50       assert_response :success
51       assert_template :show
52       assert_dom ".alert-success", :text => "Heatmap updated."
53
54       assert_not_predicate user.reload, :public_heatmap?
55       refute_select heatmap_selector
56
57       put profile_heatmap_path, :params => { :user => { :public_heatmap => "1" } }
58
59       assert_redirected_to user_path(user)
60       follow_redirect!
61       assert_response :success
62       assert_template :show
63       assert_dom ".alert-success", :text => "Heatmap updated."
64
65       assert_predicate user.reload, :public_heatmap?
66       assert_select heatmap_selector
67     end
68   end
69 end