]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles/locations_controller_test.rb
Merge pull request #5932 from tomhughes/frozen-strings
[rails.git] / test / controllers / profiles / locations_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 module Profiles
6   class LocationsControllerTest < ActionDispatch::IntegrationTest
7     ##
8     # test all routes which lead to this controller
9     def test_routes
10       assert_routing(
11         { :path => "/profile/location", :method => :get },
12         { :controller => "profiles/locations", :action => "show" }
13       )
14       assert_routing(
15         { :path => "/profile/location", :method => :put },
16         { :controller => "profiles/locations", :action => "update" }
17       )
18     end
19
20     def test_show
21       user = create(:user)
22       session_for(user)
23
24       get profile_location_path
25
26       assert_response :success
27       assert_template :show
28     end
29
30     def test_show_unauthorized
31       get profile_location_path
32
33       assert_redirected_to login_path(:referer => profile_location_path)
34     end
35
36     def test_update
37       user = create(:user)
38       session_for(user)
39
40       put profile_location_path, :params => { :user => { :home_lat => 60, :home_lon => 30, :home_location_name => "Лисий Нос" } }
41
42       assert_redirected_to user_path(user)
43       follow_redirect!
44       assert_response :success
45       assert_template :show
46       assert_dom ".alert-success", :text => "Profile location updated."
47
48       user.reload
49       assert_equal 60, user.home_lat
50       assert_equal 30, user.home_lon
51       assert_equal "Лисий Нос", user.home_location_name
52       assert_equal 3543348019, user.home_tile
53     end
54
55     def test_update_lat_out_of_range
56       user = create(:user)
57       session_for(user)
58
59       put profile_location_path, :params => { :user => { :home_lat => 91, :home_lon => 30, :home_location_name => "Лисий Нос" } }
60
61       assert_response :success
62       assert_template :show
63       assert_dom ".alert-danger", :text => "Couldn't update profile location."
64
65       user.reload
66       assert_nil user.home_lat
67       assert_nil user.home_lon
68       assert_nil user.home_location_name
69       assert_nil user.home_tile
70     end
71
72     def test_update_lon_out_of_range
73       user = create(:user)
74       session_for(user)
75
76       put profile_location_path, :params => { :user => { :home_lat => 60, :home_lon => 181, :home_location_name => "Лисий Нос" } }
77
78       assert_response :success
79       assert_template :show
80       assert_dom ".alert-danger", :text => "Couldn't update profile location."
81
82       user.reload
83       assert_nil user.home_lat
84       assert_nil user.home_lon
85       assert_nil user.home_location_name
86       assert_nil user.home_tile
87     end
88   end
89 end