]> git.openstreetmap.org Git - rails.git/blob - test/functional/site_controller_test.rb
4f41858e86b2d17ccc4ae6ca2bafd461a75ffb6d
[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 => :get },
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_permalink
98     get :permalink, :code => 'wBz3--'
99     assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4.8779296875/3.955078125'
100   end
101
102   # Get the edit page
103   def test_edit
104     get :edit
105     # Should be redirected
106     assert_redirected_to :controller => :user, :action => 'login', :referer => "/edit"
107   end
108   
109   # Offline page
110   def test_offline
111     get :offline
112     assert_response :success
113     assert_template 'offline'
114     assert_site_partials 0
115   end
116   
117   def assert_site_partials(count = 1)
118     assert_template :partial => '_search', :count => count
119     assert_template :partial => '_sidebar', :count => count
120   end
121
122   # test the right editor gets used when the user hasn't set a preference
123   def test_edit_without_preference
124     @request.cookies["_osm_username"] = users(:public_user).display_name
125
126     get(:edit, nil, { 'user' => users(:public_user).id })
127     assert_response :success
128     assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
129   end
130
131   # and when they have...
132   def test_edit_with_preference
133     @request.cookies["_osm_username"] = users(:public_user).display_name
134
135     user = users(:public_user)
136     user.preferred_editor = "potlatch"
137     user.save!
138
139     get(:edit, nil, { 'user' => user.id })
140     assert_response :success
141     assert_template :partial => "_potlatch", :count => 1
142
143     user = users(:public_user)
144     user.preferred_editor = "remote"
145     user.save!
146
147     get(:edit, nil, { 'user' => user.id })
148     assert_response :success
149     assert_template "index"
150   end
151
152   def test_edit_with_node
153     @request.cookies["_osm_username"] = users(:public_user).display_name
154
155     user = users(:public_user)
156     node = current_nodes(:visible_node)
157
158     get :edit, { :node => node.id }, { 'user' => user.id }
159     assert_equal 1.0, assigns(:lat)
160     assert_equal 1.0, assigns(:lon)
161   end
162
163   def test_edit_with_way
164     @request.cookies["_osm_username"] = users(:public_user).display_name
165
166     user = users(:public_user)
167     way  = current_ways(:visible_way)
168
169     get :edit, { :way => way.id }, { 'user' => user.id }
170     assert_equal 3.0, assigns(:lat)
171     assert_equal 3.0, assigns(:lon)
172   end
173
174   def test_edit_with_gpx
175     @request.cookies["_osm_username"] = users(:public_user).display_name
176
177     user = users(:public_user)
178     gpx  = gpx_files(:public_trace_file)
179
180     get :edit, { :gpx => gpx.id }, { 'user' => user.id }
181     assert_equal 1.0, assigns(:lat)
182     assert_equal 1.0, assigns(:lon)
183   end
184 end