##
# 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
##
{ :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" }
def test_edit
get :edit
assert_response :redirect
- assert_redirected_to :controller => :user, :action => :login, :referer => "/edit"
+ 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
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
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 }
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)
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
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 }
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
def test_welcome
get :welcome
assert_response :redirect
- assert_redirected_to :controller => :user, :action => :login, :referer => "/welcome"
+ assert_redirected_to :controller => :users, :action => :login, :referer => "/welcome"
get :welcome, :session => { :user => create(:user) }
assert_response :success
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