]> git.openstreetmap.org Git - rails.git/blob - test/functional/site_controller_test.rb
Test user#set_status
[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 => "/welcome", :method => :get },
39       { :controller => "site", :action => "welcome" }
40     )
41     assert_routing(
42       { :path => "/export", :method => :get },
43       { :controller => "site", :action => "index", :export => true }
44     )
45     assert_recognizes(
46       { :controller => "site", :action => "index", :export => true, :format => "html" },
47       { :path => "/export.html", :method => :get }
48     )
49     assert_routing(
50       { :path => "/offline", :method => :get },
51       { :controller => "site", :action => "offline" }
52     )
53     assert_routing(
54       { :path => "/key", :method => :get },
55       { :controller => "site", :action => "key" }
56     )
57     assert_routing(
58       { :path => "/go/shortcode", :method => :get },
59       { :controller => "site", :action => "permalink", :code => "shortcode" }
60     )
61     assert_routing(
62       { :path => "/preview/formatname", :method => :post },
63       { :controller => "site", :action => "preview", :format => "formatname" }
64     )
65     assert_routing(
66       { :path => "/id", :method => :get },
67       { :controller => "site", :action => "id" }
68     )
69   end
70
71   ## Lets check that we can get all the pages without any errors  
72   # Get the index
73   def test_index
74     get :index
75     assert_response :success
76     assert_template 'index'
77     assert_site_partials
78   end
79
80   def test_index_redirect
81     get :index, :lat => 4, :lon => 5
82     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=5/4/5'
83
84     get :index, :lat => 4, :lon => 5, :zoom => 3
85     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4/5'
86
87     get :index, :layers => 'T'
88     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=T'
89
90     get :index, :notes => 'yes'
91     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=N'
92
93     get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => 'T'
94     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4/5&layers=T'
95   end
96
97   def test_edit_redirect
98     get :edit, :lat => 4, :lon => 5
99     assert_redirected_to :controller => :site, :action => 'edit', :anchor => 'map=5/4/5'
100
101     get :edit, :lat => 4, :lon => 5, :zoom => 3
102     assert_redirected_to :controller => :site, :action => 'edit', :anchor => 'map=3/4/5'
103
104     get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => 'id'
105     assert_redirected_to :controller => :site, :action => 'edit', :editor => 'id', :anchor => 'map=3/4/5'
106   end
107
108   def test_permalink
109     get :permalink, :code => 'wBz3--'
110     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4.8779296875/3.955078125'
111   end
112
113   # Get the edit page
114   def test_edit
115     get :edit
116     # Should be redirected
117     assert_redirected_to :controller => :user, :action => 'login', :referer => "/edit"
118   end
119   
120   # Offline page
121   def test_offline
122     get :offline
123     assert_response :success
124     assert_template 'offline'
125     assert_site_partials 0
126   end
127   
128   def assert_site_partials(count = 1)
129     assert_template :partial => '_search', :count => count
130     assert_template :partial => '_sidebar', :count => count
131   end
132
133   # test the right editor gets used when the user hasn't set a preference
134   def test_edit_without_preference
135     @request.cookies["_osm_username"] = users(:public_user).display_name
136
137     get(:edit, nil, { 'user' => users(:public_user).id })
138     assert_response :success
139     assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
140   end
141
142   # and when they have...
143   def test_edit_with_preference
144     @request.cookies["_osm_username"] = users(:public_user).display_name
145
146     user = users(:public_user)
147     user.preferred_editor = "potlatch"
148     user.save!
149
150     get(:edit, nil, { 'user' => user.id })
151     assert_response :success
152     assert_template :partial => "_potlatch", :count => 1
153
154     user = users(:public_user)
155     user.preferred_editor = "remote"
156     user.save!
157
158     get(:edit, nil, { 'user' => user.id })
159     assert_response :success
160     assert_template "index"
161   end
162
163   def test_edit_with_node
164     @request.cookies["_osm_username"] = users(:public_user).display_name
165
166     user = users(:public_user)
167     node = current_nodes(:visible_node)
168
169     get :edit, { :node => node.id }, { 'user' => user.id }
170     assert_equal 1.0, assigns(:lat)
171     assert_equal 1.0, assigns(:lon)
172   end
173
174   def test_edit_with_way
175     @request.cookies["_osm_username"] = users(:public_user).display_name
176
177     user = users(:public_user)
178     way  = current_ways(:visible_way)
179
180     get :edit, { :way => way.id }, { 'user' => user.id }
181     assert_equal 3.0, assigns(:lat)
182     assert_equal 3.0, assigns(:lon)
183   end
184
185   def test_edit_with_gpx
186     @request.cookies["_osm_username"] = users(:public_user).display_name
187
188     user = users(:public_user)
189     gpx  = gpx_files(:public_trace_file)
190
191     get :edit, { :gpx => gpx.id }, { 'user' => user.id }
192     assert_equal 1.0, assigns(:lat)
193     assert_equal 1.0, assigns(:lon)
194   end
195 end