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 { :path => "/edit", :method => :get },
19 { :controller => "site", :action => "edit" }
22 { :controller => "site", :action => "edit", :format => "html" },
23 { :path => "/edit.html", :method => :get }
26 { :path => "/copyright", :method => :get },
27 { :controller => "site", :action => "copyright" }
30 { :path => "/copyright/locale", :method => :get },
31 { :controller => "site", :action => "copyright", :copyright_locale => "locale" }
34 { :path => "/welcome", :method => :get },
35 { :controller => "site", :action => "welcome" }
38 { :path => "/export", :method => :get },
39 { :controller => "site", :action => "export" }
42 { :controller => "site", :action => "export", :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 => :post },
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'
75 def test_index_redirect
76 get :index, :lat => 4, :lon => 5
77 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=5/4/5'
79 get :index, :lat => 4, :lon => 5, :zoom => 3
80 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4/5'
82 get :index, :layers => 'T'
83 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=T'
85 get :index, :notes => 'yes'
86 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=N'
88 get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => 'T'
89 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4/5&layers=T'
92 def test_edit_redirect
93 get :edit, :lat => 4, :lon => 5
94 assert_redirected_to :controller => :site, :action => 'edit', :anchor => 'map=5/4/5'
96 get :edit, :lat => 4, :lon => 5, :zoom => 3
97 assert_redirected_to :controller => :site, :action => 'edit', :anchor => 'map=3/4/5'
99 get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => 'id'
100 assert_redirected_to :controller => :site, :action => 'edit', :editor => 'id', :anchor => 'map=3/4/5'
104 get :permalink, :code => 'wBz3--'
105 assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4.8779296875/3.955078125'
111 # Should be redirected
112 assert_redirected_to :controller => :user, :action => 'login', :referer => "/edit"
118 assert_response :success
119 assert_template 'offline'
122 # test the right editor gets used when the user hasn't set a preference
123 def test_edit_without_preference
124 get(:edit, nil, { 'user' => users(:public_user).id })
125 assert_response :success
126 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
129 # and when they have...
130 def test_edit_with_preference
131 user = users(:public_user)
132 user.preferred_editor = "potlatch"
135 get(:edit, nil, { 'user' => user.id })
136 assert_response :success
137 assert_template :partial => "_potlatch", :count => 1
139 user = users(:public_user)
140 user.preferred_editor = "remote"
143 get(:edit, nil, { 'user' => user.id })
144 assert_response :success
145 assert_template "index"
148 def test_edit_with_node
149 user = users(:public_user)
150 node = current_nodes(:visible_node)
152 get :edit, { :node => node.id }, { 'user' => user.id }
153 assert_equal 1.0, assigns(:lat)
154 assert_equal 1.0, assigns(:lon)
157 def test_edit_with_way
158 user = users(:public_user)
159 way = current_ways(:visible_way)
161 get :edit, { :way => way.id }, { 'user' => user.id }
162 assert_equal 3.0, assigns(:lat)
163 assert_equal 3.0, assigns(:lon)
166 def test_edit_with_gpx
167 user = users(:public_user)
168 gpx = gpx_files(:public_trace_file)
170 get :edit, { :gpx => gpx.id }, { 'user' => user.id }
171 assert_equal 1.0, assigns(:lat)
172 assert_equal 1.0, assigns(:lon)