This is the modern way of writing controller tests, since it uses the
rails middleware (among other things) and leads to more realistic tests.
Refs #2563
match "/auth/:provider" => "users#auth", :via => [:get, :post], :as => :auth
# permalink
match "/auth/:provider" => "users#auth", :via => [:get, :post], :as => :auth
# permalink
- get "/go/:code" => "site#permalink", :code => /[a-zA-Z0-9_@~]+[=-]*/
+ get "/go/:code" => "site#permalink", :code => /[a-zA-Z0-9_@~]+[=-]*/, :as => :permalink
# rich text preview
post "/preview/:type" => "site#preview", :as => :preview
# rich text preview
post "/preview/:type" => "site#preview", :as => :preview
-class SiteControllerTest < ActionController::TestCase
+class SiteControllerTest < ActionDispatch::IntegrationTest
##
# setup oauth keys
def setup
##
# setup oauth keys
def setup
# Test the index page
def test_index
# Test the index page
def test_index
assert_response :success
assert_template "index"
end
# Test the index page redirects
def test_index_redirect
assert_response :success
assert_template "index"
end
# Test the index page redirects
def test_index_redirect
- get :index, :params => { :node => 123 }
+ get root_path(:node => 123)
assert_redirected_to :controller => :browse, :action => :node, :id => 123
assert_redirected_to :controller => :browse, :action => :node, :id => 123
- get :index, :params => { :way => 123 }
+ get root_path(:way => 123)
assert_redirected_to :controller => :browse, :action => :way, :id => 123
assert_redirected_to :controller => :browse, :action => :way, :id => 123
- get :index, :params => { :relation => 123 }
+ get root_path(:relation => 123)
assert_redirected_to :controller => :browse, :action => :relation, :id => 123
assert_redirected_to :controller => :browse, :action => :relation, :id => 123
- get :index, :params => { :note => 123 }
+ get root_path(:note => 123)
assert_redirected_to :controller => :browse, :action => :note, :id => 123
assert_redirected_to :controller => :browse, :action => :note, :id => 123
- get :index, :params => { :query => "test" }
+ get root_path(:query => "test")
assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
- get :index, :params => { :lat => 4, :lon => 5 }
+ get root_path(:lat => 4, :lon => 5)
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
- get :index, :params => { :lat => 4, :lon => 5, :zoom => 3 }
+ get root_path(:lat => 4, :lon => 5, :zoom => 3)
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
- get :index, :params => { :layers => "T" }
+ get root_path(:layers => "T")
assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
- get :index, :params => { :notes => "yes" }
+ get root_path(:notes => "yes")
assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
- get :index, :params => { :lat => 4, :lon => 5, :zoom => 3, :layers => "T" }
+ get root_path(:lat => 4, :lon => 5, :zoom => 3, :layers => "T")
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
end
# Test the permalink redirect
def test_permalink
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
end
# Test the permalink redirect
def test_permalink
- get :permalink, :params => { :code => "wBz3--" }
+ get permalink_path(:code => "wBz3--")
assert_response :redirect
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
assert_response :redirect
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :params => { :code => "wBz3--", :m => "" }
+ get permalink_path(:code => "wBz3--", :m => "")
assert_response :redirect
assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
assert_response :redirect
assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :params => { :code => "wBz3--", :layers => "T" }
+ get permalink_path(:code => "wBz3--", :layers => "T")
assert_response :redirect
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
assert_response :redirect
assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
- get :permalink, :params => { :code => "wBz3--", :node => 1 }
+ get permalink_path(:code => "wBz3--", :node => 1)
assert_response :redirect
assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
assert_response :redirect
assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :params => { :code => "wBz3--", :way => 2 }
+ get permalink_path(:code => "wBz3--", :way => 2)
assert_response :redirect
assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
assert_response :redirect
assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :params => { :code => "wBz3--", :relation => 3 }
+ get permalink_path(:code => "wBz3--", :relation => 3)
assert_response :redirect
assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
assert_response :redirect
assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
- get :permalink, :params => { :code => "wBz3--", :changeset => 4 }
+ get permalink_path(:code => "wBz3--", :changeset => 4)
assert_response :redirect
assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => "map=3/4.8779296875/3.955078125"
end
# Test the key page
def test_key
assert_response :redirect
assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => "map=3/4.8779296875/3.955078125"
end
# Test the key page
def test_key
+ get key_path, :xhr => true
+
assert_response :success
assert_template "key"
assert_template :layout => false
assert_response :success
assert_template "key"
assert_template :layout => false
# Test the edit page redirects when you aren't logged in
def test_edit
# Test the edit page redirects when you aren't logged in
def test_edit
assert_response :redirect
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
assert_response :redirect
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) }
+ session_for(create(:user, :data_public => false))
+
+ get edit_path
+
assert_response :success
assert_template "edit"
assert_select "a[href='https://wiki.openstreetmap.org/wiki/Disabling_anonymous_edits']"
assert_response :success
assert_template "edit"
assert_select "a[href='https://wiki.openstreetmap.org/wiki/Disabling_anonymous_edits']"
# Test the right editor gets used when the user hasn't set a preference
def test_edit_without_preference
# 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) }
+ session_for(create(:user))
+
+ get edit_path
+
assert_response :success
assert_template "edit"
assert_template :partial => "_#{Settings.default_editor}", :count => 1
assert_response :success
assert_template "edit"
assert_template :partial => "_#{Settings.default_editor}", :count => 1
user = create(:user)
user.preferred_editor = "id"
user.save!
user = create(:user)
user.preferred_editor = "id"
user.save!
- get :edit, :session => { :user => user }
assert_response :success
assert_template "edit"
assert_template :partial => "_id", :count => 1
assert_response :success
assert_template "edit"
assert_template :partial => "_id", :count => 1
user.preferred_editor = "potlatch2"
user.save!
user.preferred_editor = "potlatch2"
user.save!
- get :edit, :session => { :user => user }
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch2", :count => 1
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch2", :count => 1
user.preferred_editor = "potlatch"
user.save!
user.preferred_editor = "potlatch"
user.save!
- get :edit, :session => { :user => user }
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch", :count => 1
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch", :count => 1
user.preferred_editor = "remote"
user.save!
user.preferred_editor = "remote"
user.save!
- get :edit, :session => { :user => user }
assert_response :success
assert_template "index"
end
# Test the right editor gets used when the URL has an override
def test_edit_with_override
assert_response :success
assert_template "index"
end
# Test the right editor gets used when the URL has an override
def test_edit_with_override
- get :edit, :params => { :editor => "id" }, :session => { :user => create(:user) }
+ session_for(create(:user))
+
+ get edit_path(:editor => "id")
assert_response :success
assert_template "edit"
assert_template :partial => "_id", :count => 1
assert_response :success
assert_template "edit"
assert_template :partial => "_id", :count => 1
- get :edit, :params => { :editor => "potlatch2" }, :session => { :user => create(:user) }
+ get edit_path(:editor => "potlatch2")
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch2", :count => 1
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch2", :count => 1
- get :edit, :params => { :editor => "potlatch" }, :session => { :user => create(:user) }
+ get edit_path(:editor => "potlatch")
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch", :count => 1
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch", :count => 1
- get :edit, :params => { :editor => "remote" }, :session => { :user => create(:user) }
+ get edit_path(:editor => "remote")
assert_response :success
assert_template "index"
end
assert_response :success
assert_template "index"
end
def test_edit_with_node
user = create(:user)
node = create(:node, :lat => 1.0, :lon => 1.0)
def test_edit_with_node
user = create(:user)
node = create(:node, :lat => 1.0, :lon => 1.0)
+ session_for(user)
+
+ get edit_path(:node => node.id)
- get :edit, :params => { :node => node.id }, :session => { :user => user }
assert_response :success
assert_template "edit"
assert_equal 1.0, assigns(:lat)
assert_response :success
assert_template "edit"
assert_equal 1.0, assigns(:lat)
def test_edit_with_inaccessible_nodes
user = create(:user)
deleted_node = create(:node, :lat => 1.0, :lon => 1.0, :visible => false)
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 }
+ get edit_path(:node => 99999)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
assert_nil assigns(:lon)
assert_nil assigns(:zoom)
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 }
+ get edit_path(:node => deleted_node.id)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
node = create(:node, :lat => 3, :lon => 3)
way = create(:way)
create(:way_node, :node => node, :way => way)
node = create(:node, :lat => 3, :lon => 3)
way = create(:way)
create(:way_node, :node => node, :way => way)
- get :edit, :params => { :way => way.id }, :session => { :user => user }
+ get edit_path(:way => way.id)
assert_response :success
assert_template "edit"
assert_equal 3.0, assigns(:lat)
assert_response :success
assert_template "edit"
assert_equal 3.0, assigns(:lat)
def test_edit_with_inaccessible_ways
user = create(:user)
deleted_way = create(:way, :visible => false)
def test_edit_with_inaccessible_ways
user = create(:user)
deleted_way = create(:way, :visible => false)
- get :edit, :params => { :way => 99999 }, :session => { :user => user }
+ get edit_path(:way => 99999)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
assert_nil assigns(:lon)
assert_nil assigns(:zoom)
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 }
+ get edit_path(:way => deleted_way.id)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
note = create(:note) do |n|
n.comments.create(:author_id => user.id)
end
note = create(:note) do |n|
n.comments.create(:author_id => user.id)
end
- get :edit, :params => { :note => note.id }, :session => { :user => user }
+ get edit_path(:note => note.id)
assert_response :success
assert_template "edit"
assert_equal 1.0, assigns(:lat)
assert_response :success
assert_template "edit"
assert_equal 1.0, assigns(:lat)
deleted_note = create(:note, :status => "hidden") do |n|
n.comments.create(:author_id => user.id)
end
deleted_note = create(:note, :status => "hidden") do |n|
n.comments.create(:author_id => user.id)
end
- get :edit, :params => { :note => 99999 }, :session => { :user => user }
+ get edit_path(:note => 99999)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
assert_nil assigns(:lon)
assert_nil assigns(:zoom)
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 }
+ get edit_path(:note => deleted_note.id)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
def test_edit_with_gpx
user = create(:user)
gpx = create(:trace, :latitude => 1, :longitude => 1)
def test_edit_with_gpx
user = create(:user)
gpx = create(:trace, :latitude => 1, :longitude => 1)
- get :edit, :params => { :gpx => gpx.id }, :session => { :user => user }
+ get edit_path(:gpx => gpx.id)
assert_response :success
assert_template "edit"
assert_equal 1.0, assigns(:lat)
assert_response :success
assert_template "edit"
assert_equal 1.0, assigns(:lat)
user = create(:user)
deleted_gpx = create(:trace, :deleted, :latitude => 1, :longitude => 1)
private_gpx = create(:trace, :latitude => 1, :longitude => 1, :visibility => "private")
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 }
+ get edit_path(:gpx => 99999)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
assert_nil assigns(:lon)
assert_nil assigns(:zoom)
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 }
+ get edit_path(:gpx => deleted_gpx.id)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
assert_nil assigns(:lon)
assert_nil assigns(:zoom)
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 }
+ get edit_path(:gpx => private_gpx.id)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
assert_response :success
assert_template "edit"
assert_nil assigns(:lat)
# Test the edit page redirects
def test_edit_redirect
# Test the edit page redirects
def test_edit_redirect
- get :edit, :params => { :lat => 4, :lon => 5 }
+ get edit_path(:lat => 4, :lon => 5)
assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
- get :edit, :params => { :lat => 4, :lon => 5, :zoom => 3 }
+ get edit_path(:lat => 4, :lon => 5, :zoom => 3)
assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
- get :edit, :params => { :lat => 4, :lon => 5, :zoom => 3, :editor => "id" }
+ get edit_path(:lat => 4, :lon => 5, :zoom => 3, :editor => "id")
assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
end
# Test the copyright page
def test_copyright
assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
end
# Test the copyright page
def test_copyright
assert_response :success
assert_template "copyright"
assert_select "div[lang='en'][dir='ltr']"
assert_response :success
assert_template "copyright"
assert_select "div[lang='en'][dir='ltr']"
- get :copyright, :params => { :copyright_locale => "fr" }
+ get copyright_path(:copyright_locale => "fr")
assert_response :success
assert_template "copyright"
assert_select "div[lang='fr'][dir='ltr']"
assert_response :success
assert_template "copyright"
assert_select "div[lang='fr'][dir='ltr']"
- get :copyright, :params => { :copyright_locale => "ar" }
+ get copyright_path(:copyright_locale => "ar")
assert_response :success
assert_template "copyright"
assert_select "div[lang='ar'][dir='rtl']"
assert_response :success
assert_template "copyright"
assert_select "div[lang='ar'][dir='rtl']"
# Test the welcome page
def test_welcome
# Test the welcome page
def test_welcome
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login, :referer => "/welcome"
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login, :referer => "/welcome"
- get :welcome, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get welcome_path
assert_response :success
assert_template "welcome"
end
# Test the fixthemap page
def test_fixthemap
assert_response :success
assert_template "welcome"
end
# Test the fixthemap page
def test_fixthemap
assert_response :success
assert_template "fixthemap"
end
# Test the help page
def test_help
assert_response :success
assert_template "fixthemap"
end
# Test the help page
def test_help
assert_response :success
assert_template "help"
end
# Test the about page
def test_about
assert_response :success
assert_template "help"
end
# Test the about page
def test_about
assert_response :success
assert_template "about"
assert_select "div[lang='en'][dir='ltr']"
assert_response :success
assert_template "about"
assert_select "div[lang='en'][dir='ltr']"
- get :about, :params => { :about_locale => "fr" }
+ get about_path(:about_locale => "fr")
assert_response :success
assert_template "about"
assert_select "div[lang='fr'][dir='ltr']"
assert_response :success
assert_template "about"
assert_select "div[lang='fr'][dir='ltr']"
- get :about, :params => { :about_locale => "ar" }
+ get about_path(:about_locale => "ar")
assert_response :success
assert_template "about"
assert_select "div[lang='ar'][dir='rtl']"
assert_response :success
assert_template "about"
assert_select "div[lang='ar'][dir='rtl']"
# Test the export page
def test_export
# Test the export page
def test_export
assert_response :success
assert_template "export"
assert_template :layout => "map"
assert_response :success
assert_template "export"
assert_template :layout => "map"
- get :export, :xhr => true
+ get export_path, :xhr => true
assert_response :success
assert_template "export"
assert_template :layout => "xhr"
assert_response :success
assert_template "export"
assert_template :layout => "xhr"
# Test the offline page
def test_offline
# Test the offline page
def test_offline
assert_response :success
assert_template "offline"
end
# Test the rich text preview
def test_preview
assert_response :success
assert_template "offline"
end
# Test the rich text preview
def test_preview
- post :preview, :xhr => true, :params => { :type => "html" }
+ post preview_path(:type => "html"), :xhr => true
- post :preview, :xhr => true, :params => { :type => "markdown" }
+ post preview_path(:type => "markdown"), :xhr => true
- post :preview, :xhr => true, :params => { :type => "text" }
+ post preview_path(:type => "text"), :xhr => true
assert_response :success
end
# Test the id frame
def test_id
assert_response :success
end
# Test the id frame
def test_id
- get :id, :session => { :user => create(:user) }
+ session_for(create(:user))
+
+ get id_path
+
assert_response :success
assert_template "id"
assert_template :layout => false
assert_response :success
assert_template "id"
assert_template :layout => false
click_on "Login", :match => :first
end
click_on "Login", :match => :first
end
+ def session_for(user)
+ post login_path, :params => { :username => user.display_name, :password => "test" }
+ follow_redirect!
+ end
+
def xml_for_node(node)
doc = OSM::API.new.get_xml_doc
doc.root << xml_node_for_node(node)
def xml_for_node(node)
doc = OSM::API.new.get_xml_doc
doc.root << xml_node_for_node(node)