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 => "/export", :method => :get },
39 { :controller => "site", :action => "index", :export => true }
42 { :controller => "site", :action => "index", :export => true, :format => "html" },
43 { :path => "/export.html", :method => :get }
46 { :path => "/offline", :method => :get },
47 { :controller => "site", :action => "offline" }
50 { :path => "/key", :method => :get },
51 { :controller => "site", :action => "key" }
54 { :path => "/go/shortcode", :method => :get },
55 { :controller => "site", :action => "permalink", :code => "shortcode" }
58 { :path => "/preview/formatname", :method => :get },
59 { :controller => "site", :action => "preview", :format => "formatname" }
62 { :path => "/id", :method => :get },
63 { :controller => "site", :action => "id" }
67 ## Lets check that we can get all the pages without any errors
71 assert_response :success
72 assert_template 'index'
76 def test_index_redirect
77 get :index, :lat => 4, :lon => 5
78 assert_redirected_to :controller => :site, :action => 'index', :anchor => '5/4/5'
80 get :index, :lat => 4, :lon => 5, :zoom => 3
81 assert_redirected_to :controller => :site, :action => 'index', :anchor => '3/4/5'
85 get :permalink, :code => 'wBz3--'
86 assert_redirected_to :controller => :site, :action => 'index', :anchor => '3/4.8779296875/3.955078125'
92 # Should be redirected
93 assert_redirected_to :controller => :user, :action => 'login', :referer => "/edit"
99 assert_response :success
100 assert_template 'offline'
101 assert_site_partials 0
104 def assert_site_partials(count = 1)
105 assert_template :partial => '_search', :count => count
106 assert_template :partial => '_sidebar', :count => count
109 # test the right editor gets used when the user hasn't set a preference
110 def test_edit_without_preference
111 @request.cookies["_osm_username"] = users(:public_user).display_name
113 get(:edit, nil, { 'user' => users(:public_user).id })
114 assert_response :success
115 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
118 # and when they have...
119 def test_edit_with_preference
120 @request.cookies["_osm_username"] = users(:public_user).display_name
122 user = users(:public_user)
123 user.preferred_editor = "potlatch"
126 get(:edit, nil, { 'user' => user.id })
127 assert_response :success
128 assert_template :partial => "_potlatch", :count => 1
130 user = users(:public_user)
131 user.preferred_editor = "remote"
134 get(:edit, nil, { 'user' => user.id })
135 assert_response :success
136 assert_template "index"
139 def test_edit_with_node
140 @request.cookies["_osm_username"] = users(:public_user).display_name
142 user = users(:public_user)
143 node = current_nodes(:visible_node)
145 get :edit, { :node => node.id }, { 'user' => user.id }
146 assert_equal 1.0, assigns(:lat)
147 assert_equal 1.0, assigns(:lon)
150 def test_edit_with_way
151 @request.cookies["_osm_username"] = users(:public_user).display_name
153 user = users(:public_user)
154 way = current_ways(:visible_way)
156 get :edit, { :way => way.id }, { 'user' => user.id }
157 assert_equal 3.0, assigns(:lat)
158 assert_equal 3.0, assigns(:lon)
161 def test_edit_with_gpx
162 @request.cookies["_osm_username"] = users(:public_user).display_name
164 user = users(:public_user)
165 gpx = gpx_files(:public_trace_file)
167 get :edit, { :gpx => gpx.id }, { 'user' => user.id }
168 assert_equal 1.0, assigns(:lat)
169 assert_equal 1.0, assigns(:lon)