]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles/heatmaps_controller_test.rb
First stab at hiding the heatmap
[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 => :put },
12         { :controller => "profiles/heatmaps", :action => "update" }
13       )
14     end
15
16     def test_update
17       user = create(:user, :public_heatmap => true)
18       session_for(user)
19
20       heatmap_selector = ".heatmap_frame"
21
22       assert_predicate user.reload, :public_heatmap?
23       get user_path(user)
24       assert_select heatmap_selector
25
26       put profile_heatmap_path, :params => { :user => { :public_heatmap => "0" } }
27
28       assert_redirected_to user_path(user)
29       follow_redirect!
30       assert_response :success
31       assert_template :show
32       assert_dom ".alert-success", :text => "Heatmap updated."
33
34       assert_not_predicate user.reload, :public_heatmap?
35       refute_select heatmap_selector
36
37       put profile_heatmap_path, :params => { :user => { :public_heatmap => "1" } }
38
39       assert_redirected_to user_path(user)
40       follow_redirect!
41       assert_response :success
42       assert_template :show
43       assert_dom ".alert-success", :text => "Heatmap updated."
44
45       assert_predicate user.reload, :public_heatmap?
46       assert_select heatmap_selector
47     end
48   end
49 end