Notifier.message_notification(@message).deliver_later
redirect_to :action => :inbox
else
+ @title = t "messages.new.title"
render :action => "new"
end
end
require "test_helper"
-class ExportControllerTest < ActionController::TestCase
+class ExportControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
###
# test the finish action for raw OSM data
def test_finish_osm
- get :finish, :params => { :minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "osm" }
+ post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "osm")
assert_response :redirect
assert_redirected_to "controller" => "api/map", "action" => "index", "bbox" => "0.0,50.0,1.0,51.0"
end
###
# test the finish action for mapnik images
def test_finish_mapnik
- get :finish, :params => { :minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "mapnik", :mapnik_format => "test", :mapnik_scale => "12" }
+ post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "mapnik", :mapnik_format => "test", :mapnik_scale => "12")
assert_response :redirect
assert_redirected_to "https://render.openstreetmap.org/cgi-bin/export?bbox=0.0,50.0,1.0,51.0&scale=12&format=test"
end
##
# test the embed action
def test_embed
- get :embed
+ get export_embed_path
assert_response :success
assert_template "export/embed"
end
require "test_helper"
-class GeocoderControllerTest < ActionController::TestCase
+class GeocoderControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
##
# Test identification with no arguments
def test_identify_error
- get :search
+ get search_path
assert_response :bad_request
- get :search, :xhr => true
+ get search_path, :xhr => true
assert_response :bad_request
end
12345
12345-6789
].each do |code|
- post :search, :params => { :query => code }
- assert_response :success
- assert_equal %w[osm_nominatim], assigns(:sources)
+ search_check code, %w[osm_nominatim]
end
end
##
# Test the builtin latitude+longitude search
def test_search_latlon
- get :search_latlon, :params => { :lat => 1.23, :lon => 4.56, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => 4.56, :zoom => 16), :xhr => true
results_check :name => "1.23, 4.56", :lat => 1.23, :lon => 4.56, :zoom => 16
- get :search_latlon, :params => { :lat => -91.23, :lon => 4.56, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => -91.23, :lon => 4.56, :zoom => 16), :xhr => true
results_check_error "Latitude -91.23 out of range"
- get :search_latlon, :params => { :lat => 91.23, :lon => 4.56, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 91.23, :lon => 4.56, :zoom => 16), :xhr => true
results_check_error "Latitude 91.23 out of range"
- get :search_latlon, :params => { :lat => 1.23, :lon => -180.23, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => -180.23, :zoom => 16), :xhr => true
results_check_error "Longitude -180.23 out of range"
- get :search_latlon, :params => { :lat => 1.23, :lon => 180.23, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => 180.23, :zoom => 16), :xhr => true
results_check_error "Longitude 180.23 out of range"
end
def test_search_latlon_digits
- get :search_latlon, :params => { :lat => 1.23, :lon => 4.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => 4.56, :zoom => 16, :latlon_digits => true), :xhr => true
results_check({ :name => "1.23, 4.56", :lat => 1.23, :lon => 4.56, :zoom => 16 },
{ :name => "4.56, 1.23", :lat => 4.56, :lon => 1.23, :zoom => 16 })
- get :search_latlon, :params => { :lat => -91.23, :lon => 4.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => -91.23, :lon => 4.56, :zoom => 16, :latlon_digits => true), :xhr => true
results_check :name => "4.56, -91.23", :lat => 4.56, :lon => -91.23, :zoom => 16
- get :search_latlon, :params => { :lat => -1.23, :lon => 170.23, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => -1.23, :lon => 170.23, :zoom => 16, :latlon_digits => true), :xhr => true
results_check :name => "-1.23, 170.23", :lat => -1.23, :lon => 170.23, :zoom => 16
- get :search_latlon, :params => { :lat => 91.23, :lon => 94.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 91.23, :lon => 94.56, :zoom => 16, :latlon_digits => true), :xhr => true
results_check_error "Latitude or longitude are out of range"
- get :search_latlon, :params => { :lat => -91.23, :lon => -94.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => -91.23, :lon => -94.56, :zoom => 16, :latlon_digits => true), :xhr => true
results_check_error "Latitude or longitude are out of range"
- get :search_latlon, :params => { :lat => 1.23, :lon => -180.23, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => -180.23, :zoom => 16, :latlon_digits => true), :xhr => true
results_check_error "Latitude or longitude are out of range"
- get :search_latlon, :params => { :lat => 1.23, :lon => 180.23, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => 180.23, :zoom => 16, :latlon_digits => true), :xhr => true
results_check_error "Latitude or longitude are out of range"
end
# Test the Canadian postcode search
def test_search_ca_postcode
with_http_stubs "geocoder_ca" do
- get :search_ca_postcode, :xhr => true,
- :params => { :query => "A1B 2C3", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_ca_postcode_path(:query => "A1B 2C3", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
+
results_check :name => "A1B 2C3", :lat => "47.172520", :lon => "-55.440515"
- get :search_ca_postcode, :xhr => true,
- :params => { :query => "k1a 0b1", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_ca_postcode_path(:query => "k1a 0b1", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check :name => "K1A 0B1", :lat => "45.375437", :lon => "-75.691041"
- get :search_ca_postcode, :xhr => true,
- :params => { :query => "Q0Q 0Q0", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_ca_postcode_path(:query => "Q0Q 0Q0", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check
end
end
# Test the nominatim forward search
def test_search_osm_nominatim
with_http_stubs "nominatim" do
- get :search_osm_nominatim, :xhr => true,
- :params => { :query => "Hoddesdon", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_osm_nominatim_path(:query => "Hoddesdon", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check "name" => "Hoddesdon, Hertfordshire, East of England, England, United Kingdom",
"min-lat" => 51.7216709, "max-lat" => 51.8016709,
"min-lon" => -0.0512898, "max-lon" => 0.0287102,
"type" => "node", "id" => 18007599
- get :search_osm_nominatim, :xhr => true,
- :params => { :query => "Broxbourne", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_osm_nominatim_path(:query => "Broxbourne", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check({ "prefix" => "Suburb",
"name" => "Broxbourne, Hertfordshire, East of England, England, United Kingdom",
"min-lat" => 51.7265723, "max-lat" => 51.7665723,
# Test the geonames forward search
def test_search_geonames
with_http_stubs "geonames" do
- get :search_geonames, :xhr => true,
- :params => { :query => "Hoddesdon", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_geonames_path(:query => "Hoddesdon", :zoom => 10, :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check :name => "Hoddesdon", :lat => 51.76148, :lon => -0.01144
- get :search_geonames, :xhr => true,
- :params => { :query => "Broxbourne", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_geonames_path(:query => "Broxbourne", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check({ :name => "Broxbourne", :lat => 51.74712, :lon => -0.01923 },
{ :name => "Broxbourne District", :lat => 51.73026, :lon => -0.04821 },
{ :name => "Cheshunt", :lat => 51.70791, :lon => -0.03739 },
# Test the nominatim reverse search
def test_search_osm_nominatim_reverse
with_http_stubs "nominatim" do
- get :search_osm_nominatim_reverse, :xhr => true,
- :params => { :lat => 51.7632, :lon => -0.0076, :zoom => 15 }
+ get geocoder_search_osm_nominatim_reverse_path(:lat => 51.7632, :lon => -0.0076, :zoom => 15), :xhr => true
results_check :name => "Broxbourne, Hertfordshire, East of England, England, United Kingdom",
:lat => 51.7465723, :lon => -0.0190782,
:type => "node", :id => 28825933, :zoom => 15
- get :search_osm_nominatim_reverse, :xhr => true,
- :params => { :lat => 51.7632, :lon => -0.0076, :zoom => 17 }
+ get geocoder_search_osm_nominatim_reverse_path(:lat => 51.7632, :lon => -0.0076, :zoom => 17), :xhr => true
results_check :name => "Dinant Link Road, Broxbourne, Hertfordshire, East of England, England, EN11 8HX, United Kingdom",
:lat => 51.7634883, :lon => -0.0088373,
:type => "way", :id => 3489841, :zoom => 17
- get :search_osm_nominatim_reverse, :xhr => true,
- :params => { :lat => 13.7709, :lon => 100.50507, :zoom => 19 }
+ get geocoder_search_osm_nominatim_reverse_path(:lat => 13.7709, :lon => 100.50507, :zoom => 19), :xhr => true
results_check :name => "MM Steak&Grill, ถนนศรีอยุธยา, บางขุนพรหม, กรุงเทพมหานคร, เขตดุสิต, กรุงเทพมหานคร, 10300, ประเทศไทย",
:lat => 13.7708691, :lon => 100.505073233221,
:type => "way", :id => 542901374, :zoom => 19
# Test the geonames reverse search
def test_search_geonames_reverse
with_http_stubs "geonames" do
- get :search_geonames_reverse, :xhr => true,
- :params => { :lat => 51.7632, :lon => -0.0076, :zoom => 15 }
+ get geocoder_search_geonames_reverse_path(:lat => 51.7632, :lon => -0.0076, :zoom => 15), :xhr => true
results_check :name => "England", :suffix => ", United Kingdom",
:lat => 51.7632, :lon => -0.0076
end
private
def latlon_check(query, lat, lon)
- get :search, :params => { :query => query }
+ get search_path(:query => query)
assert_response :success
assert_template :search
assert_template :layout => "map"
assert_in_delta lat, @controller.params[:lat]
assert_in_delta lon, @controller.params[:lon]
- get :search, :params => { :query => query }, :xhr => true
+ get search_path(:query => query), :xhr => true
assert_response :success
assert_template :search
assert_template :layout => "xhr"
end
def search_check(query, sources)
- get :search, :params => { :query => query }
+ get search_path(:query => query)
assert_response :success
assert_template :search
assert_template :layout => "map"
assert_equal sources, assigns(:sources)
- get :search, :params => { :query => query }, :xhr => true
+ get search_path(:query => query), :xhr => true
assert_response :success
assert_template :search
assert_template :layout => "xhr"
require "test_helper"
-class IssueCommentsControllerTest < ActionController::TestCase
+class IssueCommentsControllerTest < ActionDispatch::IntegrationTest
def test_comment_by_normal_user
issue = create(:issue)
# Login as normal user
- session[:user] = create(:user).id
+ session_for(create(:user))
- post :create, :params => { :issue_id => issue.id }
+ post issue_comments_path(:issue_id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
assert_equal 0, issue.comments.length
issue = create(:issue)
# Login as administrator
- session[:user] = create(:administrator_user).id
+ session_for(create(:administrator_user))
- post :create, :params => { :issue_id => issue.id, :issue_comment => { :body => "test comment" } }
+ post issue_comments_path(:issue_id => issue, :issue_comment => { :body => "test comment" })
assert_response :redirect
assert_redirected_to issue
assert_equal 1, issue.comments.length
require "test_helper"
-class IssuesControllerTest < ActionController::TestCase
+class IssuesControllerTest < ActionDispatch::IntegrationTest
def test_index
# Access issues list without login
- get :index
+ get issues_path
assert_response :redirect
assert_redirected_to login_path(:referer => issues_path)
# Access issues list as normal user
- session[:user] = create(:user).id
- get :index
+ session_for(create(:user))
+ get issues_path
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Access issues list as administrator
- session[:user] = create(:administrator_user).id
- get :index
+ session_for(create(:administrator_user))
+ get issues_path
assert_response :success
# Access issues list as moderator
- session[:user] = create(:moderator_user).id
- get :index
+ session_for(create(:moderator_user))
+ get issues_path
assert_response :success
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
# Access issue without login
- get :show, :params => { :id => issue.id }
+ get issue_path(:id => issue)
assert_response :redirect
assert_redirected_to login_path(:referer => issue_path(issue))
# Access issue as normal user
- session[:user] = create(:user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:user))
+ get issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Access issue as administrator
- session[:user] = create(:administrator_user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ get issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
# Access issue as moderator
- session[:user] = create(:moderator_user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ get issue_path(:id => issue)
assert_response :success
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
# Access issue without login
- get :show, :params => { :id => issue.id }
+ get issue_path(:id => issue)
assert_response :redirect
assert_redirected_to login_path(:referer => issue_path(issue))
# Access issue as normal user
- session[:user] = create(:user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:user))
+ get issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Access issue as moderator
- session[:user] = create(:moderator_user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ get issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
# Access issue as administrator
- session[:user] = create(:administrator_user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ get issue_path(:id => issue)
assert_response :success
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
# Resolve issue without login
- get :resolve, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => resolve_issue_path(issue))
+ post resolve_issue_path(:id => issue)
+ assert_response :forbidden
# Resolve issue as normal user
- session[:user] = create(:user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:user))
+ post resolve_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Resolve issue as administrator
- session[:user] = create(:administrator_user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post resolve_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.resolved?
# Resolve issue as moderator
- session[:user] = create(:moderator_user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post resolve_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.resolved?
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
# Resolve issue without login
- get :resolve, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => resolve_issue_path(issue))
+ post resolve_issue_path(:id => issue)
+ assert_response :forbidden
# Resolve issue as normal user
- session[:user] = create(:user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:user))
+ post resolve_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Resolve issue as moderator
- session[:user] = create(:moderator_user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post resolve_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.resolved?
# Resolve issue as administrator
- session[:user] = create(:administrator_user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post resolve_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.resolved?
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
# Ignore issue without login
- get :ignore, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => ignore_issue_path(issue))
+ post ignore_issue_path(:id => issue)
+ assert_response :forbidden
# Ignore issue as normal user
- session[:user] = create(:user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:user))
+ post ignore_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Ignore issue as administrator
- session[:user] = create(:administrator_user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post ignore_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.ignored?
# Ignore issue as moderator
- session[:user] = create(:moderator_user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post ignore_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.ignored?
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
# Ignore issue without login
- get :ignore, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => ignore_issue_path(issue))
+ post ignore_issue_path(:id => issue)
+ assert_response :forbidden
# Ignore issue as normal user
- session[:user] = create(:user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:user))
+ post ignore_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Ignore issue as moderator
- session[:user] = create(:moderator_user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post ignore_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.ignored?
# Ignore issue as administrator
- session[:user] = create(:administrator_user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post ignore_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.ignored?
end
issue.resolve!
# Reopen issue without login
- get :reopen, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => reopen_issue_path(issue))
+ post reopen_issue_path(:id => issue)
+ assert_response :forbidden
# Reopen issue as normal user
- session[:user] = create(:user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:user))
+ post reopen_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Reopen issue as administrator
- session[:user] = create(:administrator_user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post reopen_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.open?
# Reopen issue as moderator
- session[:user] = create(:moderator_user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post reopen_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.open?
end
issue.resolve!
# Reopen issue without login
- get :reopen, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => reopen_issue_path(issue))
+ post reopen_issue_path(:id => issue)
+ assert_response :forbidden
# Reopen issue as normal user
- session[:user] = create(:user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:user))
+ post reopen_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Reopen issue as moderator
- session[:user] = create(:moderator_user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post reopen_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.open?
# Reopen issue as administrator
- session[:user] = create(:administrator_user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post reopen_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.open?
end
require "test_helper"
-class MessagesControllerTest < ActionController::TestCase
+class MessagesControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
def test_new_no_login
# Check that the new message page requires us to login
user = create(:user)
- get :new, :params => { :display_name => user.display_name }
+ get new_message_path(:display_name => user.display_name)
assert_redirected_to login_path(:referer => new_message_path(:display_name => user.display_name))
end
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that the new message page loads
- get :new, :params => { :display_name => recipient_user.display_name }
+ get new_message_path(:display_name => recipient_user.display_name)
assert_response :success
assert_template "new"
assert_select "title", "Send message | OpenStreetMap"
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that we can't send a message from a GET request
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
perform_enqueued_jobs do
- get :new,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "Test Message", :body => "Test message body" } }
+ get new_message_path(:display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "Test message body" })
end
end
end
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that the subject is preserved over errors
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
perform_enqueued_jobs do
- post :new,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "Test Message", :body => "" } }
+ post messages_path(:display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "" })
end
end
end
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that the body text is preserved over errors
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
perform_enqueued_jobs do
- post :new,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "", :body => "Test message body" } }
+ post messages_path(:display_name => recipient_user.display_name,
+ :message => { :title => "", :body => "Test message body" })
end
end
end
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that sending a message works
assert_difference "ActionMailer::Base.deliveries.size", 1 do
assert_difference "Message.count", 1 do
perform_enqueued_jobs do
- post :create,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "Test Message", :body => "Test message body" } }
+ post messages_path(:display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "Test message body" })
end
end
end
assert_equal "markdown", m.body_format
# Asking to send a message with a bogus user name should fail
- get :new, :params => { :display_name => "non_existent_user" }
+ get new_message_path(:display_name => "non_existent_user")
assert_response :not_found
assert_template "users/no_such_user"
assert_select "h1", "The user non_existent_user does not exist"
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that sending a message fails when the message limit is hit
assert_no_difference "ActionMailer::Base.deliveries.size" do
assert_no_difference "Message.count" do
with_message_limit(0) do
perform_enqueued_jobs do
- post :create,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "Test Message", :body => "Test message body" } }
+ post messages_path(:display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "Test message body" })
assert_response :success
assert_template "new"
assert_select ".error", /wait a while/
unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
# Check that the message reply page requires us to login
- get :reply, :params => { :message_id => unread_message.id }
+ get message_reply_path(:message_id => unread_message)
assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id))
# Login as the wrong user
- session[:user] = other_user.id
+ session_for(other_user)
# Check that we can't reply to somebody else's message
- get :reply, :params => { :message_id => unread_message.id }
+ get message_reply_path(:message_id => unread_message)
assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id))
assert_equal "You are logged in as `#{other_user.display_name}' but the message you have asked to reply to was not sent to that user. Please login as the correct user in order to reply.", flash[:notice]
# Login as the right user
- session[:user] = recipient_user.id
+ session_for(recipient_user)
# Check that the message reply page loads
- get :reply, :params => { :message_id => unread_message.id }
+ get message_reply_path(:message_id => unread_message)
assert_response :success
assert_template "new"
assert_select "title", "Re: #{unread_message.title} | OpenStreetMap"
assert Message.find(unread_message.id).message_read
# Asking to reply to a message with no ID should fail
- assert_raise ActionController::UrlGenerationError do
- get :reply
- end
+ get message_reply_path
+ assert_response :success
# Asking to reply to a message with a bogus ID should fail
- get :reply, :params => { :message_id => 99999 }
+ get message_reply_path(:message_id => 99999)
assert_response :not_found
assert_template "no_such_message"
end
unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
# Check that the show message page requires us to login
- get :show, :params => { :id => unread_message.id }
+ get message_path(:id => unread_message)
assert_redirected_to login_path(:referer => message_path(:id => unread_message.id))
# Login as the wrong user
- session[:user] = other_user.id
+ session_for(other_user)
# Check that we can't read the message
- get :show, :params => { :id => unread_message.id }
+ get message_path(:id => unread_message)
assert_redirected_to login_path(:referer => message_path(:id => unread_message.id))
assert_equal "You are logged in as `#{other_user.display_name}' but the message you have asked to read was not sent by or to that user. Please login as the correct user in order to read it.", flash[:notice]
# Login as the message sender
- session[:user] = user.id
+ session_for(user)
# Check that the message sender can read the message
- get :show, :params => { :id => unread_message.id }
+ get message_path(:id => unread_message)
assert_response :success
assert_template "show"
assert_not Message.find(unread_message.id).message_read
# Login as the message recipient
- session[:user] = recipient_user.id
+ session_for(recipient_user)
# Check that the message recipient can read the message
- get :show, :params => { :id => unread_message.id }
+ get message_path(:id => unread_message)
assert_response :success
assert_template "show"
assert Message.find(unread_message.id).message_read
# Asking to read a message with no ID should fail
- assert_raise ActionController::UrlGenerationError do
- get :show
- end
+ get message_path
+ assert_response :success
# Asking to read a message with a bogus ID should fail
- get :show, :params => { :id => 99999 }
+ get message_path(:id => 99999)
assert_response :not_found
assert_template "no_such_message"
end
user = create(:user)
read_message = create(:message, :read, :recipient => user)
# Check that the inbox page requires us to login
- get :inbox
+ get inbox_messages_path
assert_redirected_to login_path(:referer => inbox_messages_path)
# Login
- session[:user] = user.id
+ session_for(user)
# Check that we can view our inbox when logged in
- get :inbox
+ get inbox_messages_path
assert_response :success
assert_template "inbox"
assert_select ".content-inner > table", :count => 1 do
create(:message, :sender => user)
# Check that the outbox page requires us to login
- get :outbox
+ get outbox_messages_path
assert_redirected_to login_path(:referer => outbox_messages_path)
# Login
- session[:user] = user.id
+ session_for(user)
# Check that we can view our outbox when logged in
- get :outbox
+ get outbox_messages_path
assert_response :success
assert_template "outbox"
assert_select ".content-inner > table", :count => 1 do
unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
# Check that the marking a message requires us to login
- post :mark, :params => { :message_id => unread_message.id }
+ post message_mark_path(:message_id => unread_message)
assert_response :forbidden
# Login as a user with no messages
- session[:user] = other_user.id
+ session_for(other_user)
# Check that marking a message we didn't send or receive fails
- post :mark, :params => { :message_id => unread_message.id }
+ post message_mark_path(:message_id => unread_message)
assert_response :not_found
assert_template "no_such_message"
# Login as the message recipient_user
- session[:user] = recipient_user.id
+ session_for(recipient_user)
# Check that the marking a message read works
- post :mark, :params => { :message_id => unread_message.id, :mark => "read" }
+ post message_mark_path(:message_id => unread_message, :mark => "read")
assert_redirected_to inbox_messages_path
assert Message.find(unread_message.id).message_read
# Check that the marking a message unread works
- post :mark, :params => { :message_id => unread_message.id, :mark => "unread" }
+ post message_mark_path(:message_id => unread_message, :mark => "unread")
assert_redirected_to inbox_messages_path
assert_not Message.find(unread_message.id).message_read
# Check that the marking a message read via XHR works
- post :mark, :xhr => true, :params => { :message_id => unread_message.id, :mark => "read" }
+ post message_mark_path(:message_id => unread_message, :mark => "read"), :xhr => true
assert_response :success
assert_template "mark"
assert Message.find(unread_message.id).message_read
# Check that the marking a message unread via XHR works
- post :mark, :xhr => true, :params => { :message_id => unread_message.id, :mark => "unread" }
+ post message_mark_path(:message_id => unread_message, :mark => "unread"), :xhr => true
assert_response :success
assert_template "mark"
assert_not Message.find(unread_message.id).message_read
# Asking to mark a message with no ID should fail
- assert_raise ActionController::UrlGenerationError do
- post :mark
- end
+ post message_mark_path
+ assert_response :redirect
+ assert_redirected_to inbox_messages_path
# Asking to mark a message with a bogus ID should fail
- post :mark, :params => { :message_id => 99999 }
+ post message_mark_path(:message_id => 99999)
assert_response :not_found
assert_template "no_such_message"
end
sent_message = create(:message, :unread, :recipient => second_user, :sender => user)
# Check that destroying a message requires us to login
- delete :destroy, :params => { :id => read_message.id }
+ delete message_path(:id => read_message)
assert_response :forbidden
# Login as a user with no messages
- session[:user] = other_user.id
+ session_for(other_user)
# Check that destroying a message we didn't send or receive fails
- delete :destroy, :params => { :id => read_message.id }
+ delete message_path(:id => read_message)
assert_response :not_found
assert_template "no_such_message"
# Login as the message recipient_user
- session[:user] = user.id
+ session_for(user)
# Check that the destroy a received message works
- delete :destroy, :params => { :id => read_message.id }
+ delete message_path(:id => read_message)
assert_redirected_to inbox_messages_path
assert_equal "Message deleted", flash[:notice]
m = Message.find(read_message.id)
assert_not m.to_user_visible
# Check that the destroying a sent message works
- delete :destroy, :params => { :id => sent_message.id, :referer => outbox_messages_path }
+ delete message_path(:id => sent_message, :referer => outbox_messages_path)
assert_redirected_to outbox_messages_path
assert_equal "Message deleted", flash[:notice]
m = Message.find(sent_message.id)
assert m.to_user_visible
# Asking to destroy a message with no ID should fail
- assert_raise ActionController::UrlGenerationError do
- post :destroy
- end
+ delete message_path
+ assert_response :redirect
+ assert_redirected_to inbox_messages_path
# Asking to destroy a message with a bogus ID should fail
- delete :destroy, :params => { :id => 99999 }
+ delete message_path(:id => 99999)
assert_response :not_found
assert_template "no_such_message"
end