X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/3ec67ea2d395f9ae78f806f8e583e10d691861de..64b3e289ac14533c6fb2b1223b6417ad0446878c:/test/controllers/site_controller_test.rb?ds=sidebyside diff --git a/test/controllers/site_controller_test.rb b/test/controllers/site_controller_test.rb index c4e1a5a66..4dc07f996 100644 --- a/test/controllers/site_controller_test.rb +++ b/test/controllers/site_controller_test.rb @@ -4,17 +4,17 @@ class SiteControllerTest < ActionController::TestCase ## # setup oauth keys def setup - Object.const_set("ID_KEY", create(:client_application).key) - Object.const_set("POTLATCH2_KEY", create(:client_application).key) + super - stub_hostip_requests + Settings.id_key = create(:client_application).key + Settings.potlatch2_key = create(:client_application).key end ## # clear oauth keys def teardown - Object.send("remove_const", "ID_KEY") - Object.send("remove_const", "POTLATCH2_KEY") + Settings.id_key = nil + Settings.potlatch2_key = nil end ## @@ -52,6 +52,18 @@ class SiteControllerTest < ActionController::TestCase { :path => "/fixthemap", :method => :get }, { :controller => "site", :action => "fixthemap" } ) + assert_routing( + { :path => "/help", :method => :get }, + { :controller => "site", :action => "help" } + ) + assert_routing( + { :path => "/about", :method => :get }, + { :controller => "site", :action => "about" } + ) + assert_routing( + { :path => "/about/locale", :method => :get }, + { :controller => "site", :action => "about", :about_locale => "locale" } + ) assert_routing( { :path => "/export", :method => :get }, { :controller => "site", :action => "export" } @@ -168,12 +180,20 @@ class SiteControllerTest < ActionController::TestCase assert_redirected_to :controller => :users, :action => :login, :referer => "/edit" end + # Test the error when trying to edit without public edits + def test_edit_non_public + get :edit, :session => { :user => create(:user, :data_public => false) } + assert_response :success + assert_template "edit" + assert_select "a[href='https://wiki.openstreetmap.org/wiki/Disabling_anonymous_edits']" + end + # Test the right editor gets used when the user hasn't set a preference def test_edit_without_preference get :edit, :session => { :user => create(:user) } assert_response :success assert_template "edit" - assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1 + assert_template :partial => "_#{Settings.default_editor}", :count => 1 end # Test the right editor gets used when the user has set a preference @@ -249,11 +269,31 @@ class SiteControllerTest < ActionController::TestCase assert_equal 18, assigns(:zoom) end + # Test editing inaccessible nodes + def test_edit_with_inaccessible_nodes + user = create(:user) + deleted_node = create(:node, :lat => 1.0, :lon => 1.0, :visible => false) + + get :edit, :params => { :node => 99999 }, :session => { :user => user } + assert_response :success + assert_template "edit" + assert_nil assigns(:lat) + assert_nil assigns(:lon) + assert_nil assigns(:zoom) + + get :edit, :params => { :node => deleted_node.id }, :session => { :user => user } + assert_response :success + assert_template "edit" + assert_nil assigns(:lat) + assert_nil assigns(:lon) + assert_nil assigns(:zoom) + end + # Test editing a specific way def test_edit_with_way user = create(:user) node = create(:node, :lat => 3, :lon => 3) - way = create(:way) + way = create(:way) create(:way_node, :node => node, :way => way) get :edit, :params => { :way => way.id }, :session => { :user => user } @@ -264,6 +304,26 @@ class SiteControllerTest < ActionController::TestCase assert_equal 17, assigns(:zoom) end + # Test editing inaccessible ways + def test_edit_with_inaccessible_ways + user = create(:user) + deleted_way = create(:way, :visible => false) + + get :edit, :params => { :way => 99999 }, :session => { :user => user } + assert_response :success + assert_template "edit" + assert_nil assigns(:lat) + assert_nil assigns(:lon) + assert_nil assigns(:zoom) + + get :edit, :params => { :way => deleted_way.id }, :session => { :user => user } + assert_response :success + assert_template "edit" + assert_nil assigns(:lat) + assert_nil assigns(:lon) + assert_nil assigns(:zoom) + end + # Test editing a specific note def test_edit_with_note user = create(:user) @@ -279,10 +339,32 @@ class SiteControllerTest < ActionController::TestCase assert_equal 17, assigns(:zoom) end + # Test editing inaccessible notes + def test_edit_with_inaccessible_notes + user = create(:user) + deleted_note = create(:note, :status => "hidden") do |n| + n.comments.create(:author_id => user.id) + end + + get :edit, :params => { :note => 99999 }, :session => { :user => user } + assert_response :success + assert_template "edit" + assert_nil assigns(:lat) + assert_nil assigns(:lon) + assert_nil assigns(:zoom) + + get :edit, :params => { :note => deleted_note.id }, :session => { :user => user } + assert_response :success + assert_template "edit" + assert_nil assigns(:lat) + assert_nil assigns(:lon) + assert_nil assigns(:zoom) + end + # Test editing a specific GPX trace def test_edit_with_gpx user = create(:user) - gpx = create(:trace, :latitude => 1, :longitude => 1) + gpx = create(:trace, :latitude => 1, :longitude => 1) get :edit, :params => { :gpx => gpx.id }, :session => { :user => user } assert_response :success @@ -292,6 +374,34 @@ class SiteControllerTest < ActionController::TestCase assert_equal 16, assigns(:zoom) end + # Test editing inaccessible GPX traces + def test_edit_with_inaccessible_gpxes + user = create(:user) + deleted_gpx = create(:trace, :deleted, :latitude => 1, :longitude => 1) + private_gpx = create(:trace, :latitude => 1, :longitude => 1, :visibility => "private") + + get :edit, :params => { :gpx => 99999 }, :session => { :user => user } + assert_response :success + assert_template "edit" + assert_nil assigns(:lat) + assert_nil assigns(:lon) + assert_nil assigns(:zoom) + + get :edit, :params => { :gpx => deleted_gpx.id }, :session => { :user => user } + assert_response :success + assert_template "edit" + assert_nil assigns(:lat) + assert_nil assigns(:lon) + assert_nil assigns(:zoom) + + get :edit, :params => { :gpx => private_gpx.id }, :session => { :user => user } + assert_response :success + assert_template "edit" + assert_nil assigns(:lat) + assert_nil assigns(:lon) + assert_nil assigns(:zoom) + end + # Test the edit page redirects def test_edit_redirect get :edit, :params => { :lat => 4, :lon => 5 } @@ -309,6 +419,17 @@ class SiteControllerTest < ActionController::TestCase get :copyright assert_response :success assert_template "copyright" + assert_select "div[lang='en'][dir='ltr']" + + get :copyright, :params => { :copyright_locale => "fr" } + assert_response :success + assert_template "copyright" + assert_select "div[lang='fr'][dir='ltr']" + + get :copyright, :params => { :copyright_locale => "ar" } + assert_response :success + assert_template "copyright" + assert_select "div[lang='ar'][dir='rtl']" end # Test the welcome page @@ -341,6 +462,17 @@ class SiteControllerTest < ActionController::TestCase get :about assert_response :success assert_template "about" + assert_select "div[lang='en'][dir='ltr']" + + get :about, :params => { :about_locale => "fr" } + assert_response :success + assert_template "about" + assert_select "div[lang='fr'][dir='ltr']" + + get :about, :params => { :about_locale => "ar" } + assert_response :success + assert_template "about" + assert_select "div[lang='ar'][dir='rtl']" end # Test the export page