1 require File.dirname(__FILE__) + '/../test_helper'
3 class SiteControllerTest < ActionController::TestCase
7 # test all routes which lead to this controller
10 { :path => "/", :method => :get },
11 { :controller => "site", :action => "index" }
14 { :path => "/", :method => :post },
15 { :controller => "site", :action => "index" }
18 { :controller => "site", :action => "index" },
19 { :path => "/index.html", :method => :get }
22 { :path => "/edit", :method => :get },
23 { :controller => "site", :action => "edit" }
26 { :controller => "site", :action => "edit", :format => "html" },
27 { :path => "/edit.html", :method => :get }
30 { :path => "/copyright", :method => :get },
31 { :controller => "site", :action => "copyright" }
34 { :path => "/copyright/locale", :method => :get },
35 { :controller => "site", :action => "copyright", :copyright_locale => "locale" }
38 { :path => "/welcome", :method => :get },
39 { :controller => "site", :action => "welcome" }
42 { :path => "/export", :method => :get },
43 { :controller => "site", :action => "index", :export => true }
46 { :controller => "site", :action => "index", :export => true, :format => "html" },
47 { :path => "/export.html", :method => :get }
50 { :path => "/offline", :method => :get },
51 { :controller => "site", :action => "offline" }
54 { :path => "/key", :method => :get },
55 { :controller => "site", :action => "key" }
58 { :path => "/go/shortcode", :method => :get },
59 { :controller => "site", :action => "permalink", :code => "shortcode" }
62 { :path => "/preview/formatname", :method => :post },
63 { :controller => "site", :action => "preview", :format => "formatname" }
66 { :path => "/id", :method => :get },
67 { :controller => "site", :action => "id" }
71 ## Lets check that we can get all the pages without any errors
75 assert_response :success
76 assert_template 'index'
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'
84 get :index, :lat => 4, :lon => 5, :zoom => 3
85 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4/5'
87 get :index, :layers => 'T'
88 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=T'
90 get :index, :notes => 'yes'
91 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=N'
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'
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'
101 get :edit, :lat => 4, :lon => 5, :zoom => 3
102 assert_redirected_to :controller => :site, :action => 'edit', :anchor => 'map=3/4/5'
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'
109 get :permalink, :code => 'wBz3--'
110 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4.8779296875/3.955078125'
116 # Should be redirected
117 assert_redirected_to :controller => :user, :action => 'login', :referer => "/edit"
123 assert_response :success
124 assert_template 'offline'
125 assert_site_partials 0
128 def assert_site_partials(count = 1)
129 assert_template :partial => '_search', :count => count
130 assert_template :partial => '_sidebar', :count => count
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
137 get(:edit, nil, { 'user' => users(:public_user).id })
138 assert_response :success
139 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
142 # and when they have...
143 def test_edit_with_preference
144 @request.cookies["_osm_username"] = users(:public_user).display_name
146 user = users(:public_user)
147 user.preferred_editor = "potlatch"
150 get(:edit, nil, { 'user' => user.id })
151 assert_response :success
152 assert_template :partial => "_potlatch", :count => 1
154 user = users(:public_user)
155 user.preferred_editor = "remote"
158 get(:edit, nil, { 'user' => user.id })
159 assert_response :success
160 assert_template "index"
163 def test_edit_with_node
164 @request.cookies["_osm_username"] = users(:public_user).display_name
166 user = users(:public_user)
167 node = current_nodes(:visible_node)
169 get :edit, { :node => node.id }, { 'user' => user.id }
170 assert_equal 1.0, assigns(:lat)
171 assert_equal 1.0, assigns(:lon)
174 def test_edit_with_way
175 @request.cookies["_osm_username"] = users(:public_user).display_name
177 user = users(:public_user)
178 way = current_ways(:visible_way)
180 get :edit, { :way => way.id }, { 'user' => user.id }
181 assert_equal 3.0, assigns(:lat)
182 assert_equal 3.0, assigns(:lon)
185 def test_edit_with_gpx
186 @request.cookies["_osm_username"] = users(:public_user).display_name
188 user = users(:public_user)
189 gpx = gpx_files(:public_trace_file)
191 get :edit, { :gpx => gpx.id }, { 'user' => user.id }
192 assert_equal 1.0, assigns(:lat)
193 assert_equal 1.0, assigns(:lon)