]> git.openstreetmap.org Git - rails.git/blob - test/functional/site_controller_test.rb
Add missing translation for new community submenu
[rails.git] / test / functional / site_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class SiteControllerTest < ActionController::TestCase
4   fixtures :users
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 => "export" }
40     )
41     assert_recognizes(
42       { :controller => "site", :action => "export", :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 => :post },
51       { :controller => "site", :action => "key" }
52     )
53     assert_routing(
54       { :path => "/go/shortcode", :method => :get },
55       { :controller => "site", :action => "permalink", :code => "shortcode" }
56     )
57   end
58
59   ## Lets check that we can get all the pages without any errors  
60   # Get the index
61   def test_index
62     get :index
63     assert_response :success
64     assert_template 'index'
65     assert_site_partials
66   end
67   
68   # Get the edit page
69   def test_edit
70     get :edit
71     # Should be redirected
72     assert_redirected_to :controller => :user, :action => 'login', :referer => "/edit"
73   end
74   
75   # Get the export page
76   def test_export
77     get :export
78     assert_response :success
79     assert_template 'index'
80     assert_site_partials
81   end
82   
83   # Offline page
84   def test_offline
85     get :offline
86     assert_response :success
87     assert_template 'offline'
88     assert_site_partials 0
89   end
90   
91   def assert_site_partials(count = 1)
92     assert_template :partial => '_search', :count => count
93     assert_template :partial => '_key', :count => count
94     assert_template :partial => '_sidebar', :count => count
95   end
96
97   # test the right editor gets used when the user hasn't set a preference
98   def test_edit_without_preference
99     @request.cookies["_osm_username"] = users(:public_user).display_name
100
101     get(:edit, nil, { 'user' => users(:public_user).id })
102     assert_response :success
103     assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
104   end
105
106   # and when they have...
107   def test_edit_with_preference
108     @request.cookies["_osm_username"] = users(:public_user).display_name
109
110     user = users(:public_user)
111     user.preferred_editor = "potlatch"
112     user.save!
113
114     get(:edit, nil, { 'user' => user.id })
115     assert_response :success
116     assert_template :partial => "_potlatch", :count => 1
117
118     user = users(:public_user)
119     user.preferred_editor = "remote"
120     user.save!
121
122     get(:edit, nil, { 'user' => user.id })
123     assert_response :success
124     assert_template "index"
125   end    
126 end