]> git.openstreetmap.org Git - rails.git/blob - test/functional/site_controller_test.rb
Add a test for diary entry creation
[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 => "/export", :method => :get },
39       { :controller => "site", :action => "index", :export => true }
40     )
41     assert_recognizes(
42       { :controller => "site", :action => "index", :export => true, :format => "html" },
43       { :path => "/export.html", :method => :get }
44     )
45     assert_routing(
46       { :path => "/offline", :method => :get },
47       { :controller => "site", :action => "offline" }
48     )
49     assert_routing(
50       { :path => "/key", :method => :get },
51       { :controller => "site", :action => "key" }
52     )
53     assert_routing(
54       { :path => "/go/shortcode", :method => :get },
55       { :controller => "site", :action => "permalink", :code => "shortcode" }
56     )
57     assert_routing(
58       { :path => "/preview/formatname", :method => :get },
59       { :controller => "site", :action => "preview", :format => "formatname" }
60     )
61   end
62
63   ## Lets check that we can get all the pages without any errors  
64   # Get the index
65   def test_index
66     get :index
67     assert_response :success
68     assert_template 'index'
69     assert_site_partials
70   end
71   
72   # Get the edit page
73   def test_edit
74     get :edit
75     # Should be redirected
76     assert_redirected_to :controller => :user, :action => 'login', :referer => "/edit"
77   end
78   
79   # Offline page
80   def test_offline
81     get :offline
82     assert_response :success
83     assert_template 'offline'
84     assert_site_partials 0
85   end
86   
87   def assert_site_partials(count = 1)
88     assert_template :partial => '_search', :count => count
89     assert_template :partial => '_sidebar', :count => count
90   end
91
92   # test the right editor gets used when the user hasn't set a preference
93   def test_edit_without_preference
94     @request.cookies["_osm_username"] = users(:public_user).display_name
95
96     get(:edit, nil, { 'user' => users(:public_user).id })
97     assert_response :success
98     assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
99   end
100
101   # and when they have...
102   def test_edit_with_preference
103     @request.cookies["_osm_username"] = users(:public_user).display_name
104
105     user = users(:public_user)
106     user.preferred_editor = "potlatch"
107     user.save!
108
109     get(:edit, nil, { 'user' => user.id })
110     assert_response :success
111     assert_template :partial => "_potlatch", :count => 1
112
113     user = users(:public_user)
114     user.preferred_editor = "remote"
115     user.save!
116
117     get(:edit, nil, { 'user' => user.id })
118     assert_response :success
119     assert_template "index"
120   end
121
122   def test_edit_with_node
123     @request.cookies["_osm_username"] = users(:public_user).display_name
124
125     user = users(:public_user)
126     node = current_nodes(:visible_node)
127
128     get :edit, { :node => node.id }, { 'user' => user.id }
129     assert_equal 1.0, assigns(:lat)
130     assert_equal 1.0, assigns(:lon)
131   end
132
133   def test_edit_with_way
134     @request.cookies["_osm_username"] = users(:public_user).display_name
135
136     user = users(:public_user)
137     way  = current_ways(:visible_way)
138
139     get :edit, { :way => way.id }, { 'user' => user.id }
140     assert_equal 3.0, assigns(:lat)
141     assert_equal 3.0, assigns(:lon)
142   end
143
144   def test_edit_with_gpx
145     @request.cookies["_osm_username"] = users(:public_user).display_name
146
147     user = users(:public_user)
148     gpx  = gpx_files(:public_trace_file)
149
150     get :edit, { :gpx => gpx.id }, { 'user' => user.id }
151     assert_equal 1.0, assigns(:lat)
152     assert_equal 1.0, assigns(:lon)
153   end
154 end