]> git.openstreetmap.org Git - rails.git/blob - test/functional/site_controller_test.rb
Update short link test results
[rails.git] / test / functional / site_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class SiteControllerTest < ActionController::TestCase
4   api_fixtures
5
6   ##
7   # test all routes which lead to this controller
8   def test_routes
9     assert_routing(
10       { :path => "/", :method => :get },
11       { :controller => "site", :action => "index" }
12     )
13     assert_routing(
14       { :path => "/", :method => :post },
15       { :controller => "site", :action => "index" }
16     )
17     assert_recognizes(
18       { :controller => "site", :action => "index" },
19       { :path => "/index.html", :method => :get }
20     )
21     assert_routing(
22       { :path => "/edit", :method => :get },
23       { :controller => "site", :action => "edit" }
24     )
25     assert_recognizes(
26       { :controller => "site", :action => "edit", :format => "html" },
27       { :path => "/edit.html", :method => :get }
28     )
29     assert_routing(
30       { :path => "/copyright", :method => :get },
31       { :controller => "site", :action => "copyright" }
32     )
33     assert_routing(
34       { :path => "/copyright/locale", :method => :get },
35       { :controller => "site", :action => "copyright", :copyright_locale => "locale" }
36     )
37     assert_routing(
38       { :path => "/export", :method => :get },
39       { :controller => "site", :action => "index", :export => true }
40     )
41     assert_recognizes(
42       { :controller => "site", :action => "index", :export => true, :format => "html" },
43       { :path => "/export.html", :method => :get }
44     )
45     assert_routing(
46       { :path => "/offline", :method => :get },
47       { :controller => "site", :action => "offline" }
48     )
49     assert_routing(
50       { :path => "/key", :method => :get },
51       { :controller => "site", :action => "key" }
52     )
53     assert_routing(
54       { :path => "/go/shortcode", :method => :get },
55       { :controller => "site", :action => "permalink", :code => "shortcode" }
56     )
57     assert_routing(
58       { :path => "/preview/formatname", :method => :get },
59       { :controller => "site", :action => "preview", :format => "formatname" }
60     )
61     assert_routing(
62       { :path => "/id", :method => :get },
63       { :controller => "site", :action => "id" }
64     )
65   end
66
67   ## Lets check that we can get all the pages without any errors  
68   # Get the index
69   def test_index
70     get :index
71     assert_response :success
72     assert_template 'index'
73     assert_site_partials
74   end
75
76   def test_index_redirect
77     get :index, :lat => 4, :lon => 5
78     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=5/4/5'
79
80     get :index, :lat => 4, :lon => 5, :zoom => 3
81     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4/5'
82
83     get :index, :layers => 'T'
84     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=T'
85
86     get :index, :notes => 'yes'
87     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=N'
88
89     get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => 'T'
90     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4/5&layers=T'
91   end
92
93   def test_permalink
94     get :permalink, :code => 'wBz3--'
95     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4.8779296875/3.955078125'
96   end
97
98   # Get the edit page
99   def test_edit
100     get :edit
101     # Should be redirected
102     assert_redirected_to :controller => :user, :action => 'login', :referer => "/edit"
103   end
104   
105   # Offline page
106   def test_offline
107     get :offline
108     assert_response :success
109     assert_template 'offline'
110     assert_site_partials 0
111   end
112   
113   def assert_site_partials(count = 1)
114     assert_template :partial => '_search', :count => count
115     assert_template :partial => '_sidebar', :count => count
116   end
117
118   # test the right editor gets used when the user hasn't set a preference
119   def test_edit_without_preference
120     @request.cookies["_osm_username"] = users(:public_user).display_name
121
122     get(:edit, nil, { 'user' => users(:public_user).id })
123     assert_response :success
124     assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
125   end
126
127   # and when they have...
128   def test_edit_with_preference
129     @request.cookies["_osm_username"] = users(:public_user).display_name
130
131     user = users(:public_user)
132     user.preferred_editor = "potlatch"
133     user.save!
134
135     get(:edit, nil, { 'user' => user.id })
136     assert_response :success
137     assert_template :partial => "_potlatch", :count => 1
138
139     user = users(:public_user)
140     user.preferred_editor = "remote"
141     user.save!
142
143     get(:edit, nil, { 'user' => user.id })
144     assert_response :success
145     assert_template "index"
146   end
147
148   def test_edit_with_node
149     @request.cookies["_osm_username"] = users(:public_user).display_name
150
151     user = users(:public_user)
152     node = current_nodes(:visible_node)
153
154     get :edit, { :node => node.id }, { 'user' => user.id }
155     assert_equal 1.0, assigns(:lat)
156     assert_equal 1.0, assigns(:lon)
157   end
158
159   def test_edit_with_way
160     @request.cookies["_osm_username"] = users(:public_user).display_name
161
162     user = users(:public_user)
163     way  = current_ways(:visible_way)
164
165     get :edit, { :way => way.id }, { 'user' => user.id }
166     assert_equal 3.0, assigns(:lat)
167     assert_equal 3.0, assigns(:lon)
168   end
169
170   def test_edit_with_gpx
171     @request.cookies["_osm_username"] = users(:public_user).display_name
172
173     user = users(:public_user)
174     gpx  = gpx_files(:public_trace_file)
175
176     get :edit, { :gpx => gpx.id }, { 'user' => user.id }
177     assert_equal 1.0, assigns(:lat)
178     assert_equal 1.0, assigns(:lon)
179   end
180 end