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