Remove all use of the :text option to render

It doesn't actually do what it says, as it sets the content type
to text/html not text/plain so is just confusing and as a result
has been deprecated in newer rails versions.
This commit is contained in:
Tom Hughes 2017-06-02 16:24:28 +01:00
parent 9b89d4eefe
commit ff97501ed0
17 changed files with 101 additions and 103 deletions

View file

@ -100,7 +100,7 @@ class ApiController < ApplicationController
response.headers["Content-Disposition"] = "attachment; filename=\"tracks.gpx\""
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
# This is probably the most common call of all. It is used for getting the
@ -198,7 +198,7 @@ class ApiController < ApplicationController
response.headers["Content-Disposition"] = "attachment; filename=\"map.osm\""
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
# Get a list of the tiles that have changed within a specified time
@ -241,9 +241,9 @@ class ApiController < ApplicationController
doc.root << changes
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
else
render :text => "Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", :status => :bad_request
render :plain => "Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", :status => :bad_request
end
end
@ -294,7 +294,7 @@ class ApiController < ApplicationController
policy << blacklist
doc.root << policy
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
# External apps that use the api are able to query which permissions

View file

@ -41,7 +41,7 @@ class ApplicationController < ActionController::Base
if request.get?
redirect_to :controller => "user", :action => "login", :referer => request.fullpath
else
render :text => "", :status => :forbidden
head :forbidden
end
end
end
@ -127,7 +127,7 @@ class ApplicationController < ActionController::Base
flash[:error] = t("application.require_moderator.not_a_moderator")
redirect_to :action => "index"
else
render :text => "", :status => :forbidden
head :forbidden
end
end
end
@ -181,7 +181,7 @@ class ApplicationController < ActionController::Base
unless @user
# no auth, the user does not exist or the password was wrong
response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
render :text => errormessage, :status => :unauthorized
render :plain => errormessage, :status => :unauthorized
return false
end
end
@ -197,7 +197,7 @@ class ApplicationController < ActionController::Base
def authorize_moderator(errormessage = "Access restricted to moderators")
# check user is a moderator
unless @user.moderator?
render :text => errormessage, :status => :forbidden
render :plain => errormessage, :status => :forbidden
false
end
end
@ -288,9 +288,9 @@ class ApplicationController < ActionController::Base
result.root << (XML::Node.new("status") << "#{Rack::Utils.status_code(status)} #{Rack::Utils::HTTP_STATUS_CODES[status]}")
result.root << (XML::Node.new("message") << message)
render :text => result.to_s, :content_type => "text/xml"
render :xml => result.to_s
else
render :text => message, :status => status, :content_type => "text/plain"
render :plain => message, :status => status
end
end
@ -321,7 +321,7 @@ class ApplicationController < ActionController::Base
def api_call_handle_error
yield
rescue ActiveRecord::RecordNotFound => ex
render :text => "", :status => :not_found
head :not_found
rescue LibXML::XML::Error, ArgumentError => ex
report_error ex.message, :bad_request
rescue ActiveRecord::RecordInvalid => ex
@ -391,7 +391,7 @@ class ApplicationController < ActionController::Base
respond_to do |format|
format.html { render :template => "user/no_such_user", :status => :not_found }
format.all { render :text => "", :status => :not_found }
format.all { head :not_found }
end
end

View file

@ -34,7 +34,7 @@ class ChangesetController < ApplicationController
# Subscribe user to changeset comments
cs.subscribers << @user
render :text => cs.id.to_s, :content_type => "text/plain"
render :plain => cs.id.to_s
end
##
@ -43,7 +43,7 @@ class ChangesetController < ApplicationController
def read
changeset = Changeset.find(params[:id])
render :text => changeset.to_xml(params[:include_discussion].presence).to_s, :content_type => "text/xml"
render :xml => changeset.to_xml(params[:include_discussion].presence).to_s
end
##
@ -61,7 +61,7 @@ class ChangesetController < ApplicationController
changeset.set_closed_time_now
changeset.save!
render :text => ""
render :nothing => true
end
##
@ -104,7 +104,7 @@ class ChangesetController < ApplicationController
# save the larger bounding box and return the changeset, which
# will include the bigger bounding box.
cs.save!
render :text => cs.to_xml.to_s, :content_type => "text/xml"
render :xml => cs.to_xml.to_s
end
##
@ -132,7 +132,7 @@ class ChangesetController < ApplicationController
diff_reader = DiffReader.new(request.raw_post, changeset)
Changeset.transaction do
result = diff_reader.commit
render :text => result.to_s, :content_type => "text/xml"
render :xml => result.to_s
end
end
@ -197,7 +197,7 @@ class ChangesetController < ApplicationController
end
end
render :text => result.to_s, :content_type => "text/xml"
render :xml => result.to_s
end
##
@ -224,7 +224,7 @@ class ChangesetController < ApplicationController
results.root << cs.to_xml_node
end
render :text => results.to_s, :content_type => "text/xml"
render :xml => results.to_s
end
##
@ -244,7 +244,7 @@ class ChangesetController < ApplicationController
check_changeset_consistency(changeset, @user)
changeset.update_from(new_changeset, @user)
render :text => changeset.to_xml, :mime_type => "text/xml"
render :xml => changeset.to_xml
end
##
@ -335,7 +335,7 @@ class ChangesetController < ApplicationController
changeset.subscribers << @user unless changeset.subscribers.exists?(@user.id)
# Return a copy of the updated changeset
render :text => changeset.to_xml.to_s, :content_type => "text/xml"
render :xml => changeset.to_xml.to_s
end
##
@ -356,7 +356,7 @@ class ChangesetController < ApplicationController
changeset.subscribers << @user
# Return a copy of the updated changeset
render :text => changeset.to_xml.to_s, :content_type => "text/xml"
render :xml => changeset.to_xml.to_s
end
##
@ -377,7 +377,7 @@ class ChangesetController < ApplicationController
changeset.subscribers.delete(@user)
# Return a copy of the updated changeset
render :text => changeset.to_xml.to_s, :content_type => "text/xml"
render :xml => changeset.to_xml.to_s
end
##
@ -396,7 +396,7 @@ class ChangesetController < ApplicationController
comment.update(:visible => false)
# Return a copy of the updated changeset
render :text => comment.changeset.to_xml.to_s, :content_type => "text/xml"
render :xml => comment.changeset.to_xml.to_s
end
##
@ -415,7 +415,7 @@ class ChangesetController < ApplicationController
comment.update(:visible => true)
# Return a copy of the updated changeset
render :text => comment.changeset.to_xml.to_s, :content_type => "text/xml"
render :xml => comment.changeset.to_xml.to_s
end
##
@ -440,7 +440,7 @@ class ChangesetController < ApplicationController
format.rss
end
rescue OSM::APIBadUserInput
render :text => "", :status => :bad_request
head :bad_request
end
private

View file

@ -158,7 +158,7 @@ class DiaryEntryController < ApplicationController
@description = I18n.t("diary_entry.feed.user.description", :user => user.display_name)
@link = "http://#{SERVER_URL}/user/#{user.display_name}/diary"
else
render :text => "", :status => :not_found
head :not_found
return
end
else

View file

@ -35,7 +35,7 @@ class GeocoderController < ApplicationController
end
if @sources.empty?
render :text => "", :status => :bad_request
head :bad_request
else
render :layout => map_layout
end

View file

@ -19,7 +19,7 @@ class NodeController < ApplicationController
# Assume that Node.from_xml has thrown an exception if there is an error parsing the xml
node.create_with_history @user
render :text => node.id.to_s, :content_type => "text/plain"
render :plain => node.id.to_s
end
# Dump the details on a node given in params[:id]
@ -29,9 +29,9 @@ class NodeController < ApplicationController
response.last_modified = node.timestamp
if node.visible
render :text => node.to_xml.to_s, :content_type => "text/xml"
render :xml => node.to_xml.to_s
else
render :text => "", :status => :gone
head :gone
end
end
@ -45,7 +45,7 @@ class NodeController < ApplicationController
end
node.update_from(new_node, @user)
render :text => node.version.to_s, :content_type => "text/plain"
render :plain => node.version.to_s
end
# Delete a node. Doesn't actually delete it, but retains its history
@ -59,7 +59,7 @@ class NodeController < ApplicationController
raise OSM::APIBadUserInput.new("The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})")
end
node.delete_with_history!(new_node, @user)
render :text => node.version.to_s, :content_type => "text/plain"
render :plain => node.version.to_s
end
# Dump the details on many nodes whose ids are given in the "nodes" parameter.
@ -79,6 +79,6 @@ class NodeController < ApplicationController
doc.root << node.to_xml_node
end
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
end

View file

@ -33,12 +33,12 @@ class OldController < ApplicationController
doc.root << element.to_xml_node
end
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
def version
if @old_element.redacted? && !show_redactions?
render :text => "", :status => :forbidden
head :forbidden
else
response.last_modified = @old_element.timestamp
@ -46,7 +46,7 @@ class OldController < ApplicationController
doc = OSM::API.new.get_xml_doc
doc.root << @old_element.to_xml_node
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
end
@ -64,7 +64,7 @@ class OldController < ApplicationController
end
# just return an empty 200 OK for success
render :text => ""
render :nothing => true
end
private

View file

@ -16,16 +16,16 @@ class RelationController < ApplicationController
# Assume that Relation.from_xml has thrown an exception if there is an error parsing the xml
relation.create_with_history @user
render :text => relation.id.to_s, :content_type => "text/plain"
render :plain => relation.id.to_s
end
def read
relation = Relation.find(params[:id])
response.last_modified = relation.timestamp
if relation.visible
render :text => relation.to_xml.to_s, :content_type => "text/xml"
render :xml => relation.to_xml.to_s
else
render :text => "", :status => :gone
head :gone
end
end
@ -40,7 +40,7 @@ class RelationController < ApplicationController
end
relation.update_from new_relation, @user
render :text => relation.version.to_s, :content_type => "text/plain"
render :plain => relation.version.to_s
end
def delete
@ -48,9 +48,9 @@ class RelationController < ApplicationController
new_relation = Relation.from_xml(request.raw_post)
if new_relation && new_relation.id == relation.id
relation.delete_with_history!(new_relation, @user)
render :text => relation.version.to_s, :content_type => "text/plain"
render :plain => relation.version.to_s
else
render :text => "", :status => :bad_request
head :bad_request
end
end
@ -119,10 +119,10 @@ class RelationController < ApplicationController
# finally add self and output
doc.root << relation.to_xml_node(visible_members, changeset_cache, user_display_name_cache)
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
else
render :text => "", :status => :gone
head :gone
end
end
@ -143,7 +143,7 @@ class RelationController < ApplicationController
doc.root << relation.to_xml_node
end
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
def relations_for_way
@ -167,6 +167,6 @@ class RelationController < ApplicationController
doc.root << relation.to_xml_node if relation.visible
end
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
end

View file

@ -33,13 +33,13 @@ class SearchController < ApplicationController
if do_nodes
response.headers["Error"] = "Searching of nodes is currently unavailable"
render :text => "", :status => :service_unavailable
head :service_unavailable
return false
end
unless value
response.headers["Error"] = "Searching for a key without value is currently unavailable"
render :text => "", :status => :service_unavailable
head :service_unavailable
return false
end
@ -94,6 +94,6 @@ class SearchController < ApplicationController
doc.root << rel.to_xml_node(nil, changeset_cache, user_display_name_cache)
end
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
end

View file

@ -115,7 +115,7 @@ class SiteController < ApplicationController
def offline; end
def preview
render :text => RichText.new(params[:format], params[:text]).to_html
render :html => RichText.new(params[:format], params[:text]).to_html
end
def id

View file

@ -92,7 +92,7 @@ class SwfController < ApplicationController
m = pack_rect(bounds_left, bounds_right, bounds_bottom, bounds_top) + 0.chr + 12.chr + pack_u16(1) + m
m = "FWS" + 6.chr + pack_u32(m.length + 8) + m
render :text => m, :content_type => "application/x-shockwave-flash"
render :body => m, :content_type => "application/x-shockwave-flash"
end
private

View file

@ -145,7 +145,7 @@ class TraceController < ApplicationController
if trace.visible? && (trace.public? || (@user && @user == trace.user))
if Acl.no_trace_download(request.remote_ip)
render :text => "", :status => :forbidden
head :forbidden
elsif request.format == Mime::XML
send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => "attachment")
elsif request.format == Mime::GPX
@ -154,19 +154,19 @@ class TraceController < ApplicationController
send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
end
else
render :text => "", :status => :not_found
head :not_found
end
rescue ActiveRecord::RecordNotFound
render :text => "", :status => :not_found
head :not_found
end
def edit
@trace = Trace.find(params[:id])
if !@trace.visible?
render :text => "", :status => :not_found
head :not_found
elsif @user.nil? || @trace.user != @user
render :text => "", :status => :forbidden
head :forbidden
else
@title = t "trace.edit.title", :name => @trace.name
@ -180,16 +180,16 @@ class TraceController < ApplicationController
end
end
rescue ActiveRecord::RecordNotFound
render :text => "", :status => :not_found
head :not_found
end
def delete
trace = Trace.find(params[:id])
if !trace.visible?
render :text => "", :status => :not_found
head :not_found
elsif @user.nil? || trace.user != @user
render :text => "", :status => :forbidden
head :forbidden
else
trace.visible = false
trace.save
@ -197,7 +197,7 @@ class TraceController < ApplicationController
redirect_to :action => :list, :display_name => @user.display_name
end
rescue ActiveRecord::RecordNotFound
render :text => "", :status => :not_found
head :not_found
end
def georss
@ -221,13 +221,13 @@ class TraceController < ApplicationController
expires_in 7.days, :private => !trace.public?, :public => trace.public?
send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => "image/gif", :disposition => "inline")
else
render :text => "", :status => :forbidden
head :forbidden
end
else
render :text => "", :status => :not_found
head :not_found
end
rescue ActiveRecord::RecordNotFound
render :text => "", :status => :not_found
head :not_found
end
def icon
@ -238,22 +238,22 @@ class TraceController < ApplicationController
expires_in 7.days, :private => !trace.public?, :public => trace.public?
send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => "image/gif", :disposition => "inline")
else
render :text => "", :status => :forbidden
head :forbidden
end
else
render :text => "", :status => :not_found
head :not_found
end
rescue ActiveRecord::RecordNotFound
render :text => "", :status => :not_found
head :not_found
end
def api_read
trace = Trace.visible.find(params[:id])
if trace.public? || trace.user == @user
render :text => trace.to_xml.to_s, :content_type => "text/xml"
render :xml => trace.to_xml.to_s
else
render :text => "", :status => :forbidden
head :forbidden
end
end
@ -272,9 +272,9 @@ class TraceController < ApplicationController
trace.visibility = new_trace.visibility
trace.save!
render :text => "", :status => :ok
head :ok
else
render :text => "", :status => :forbidden
head :forbidden
end
end
@ -285,9 +285,9 @@ class TraceController < ApplicationController
trace.visible = false
trace.save!
render :text => "", :status => :ok
head :ok
else
render :text => "", :status => :forbidden
head :forbidden
end
end
@ -303,7 +303,7 @@ class TraceController < ApplicationController
send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
end
else
render :text => "", :status => :forbidden
head :forbidden
end
end
@ -324,14 +324,14 @@ class TraceController < ApplicationController
do_create(params[:file], tags, description, visibility)
if @trace.id
render :text => @trace.id.to_s, :content_type => "text/plain"
render :plain => @trace.id.to_s
elsif @trace.valid?
render :text => "", :status => :internal_server_error
head :internal_server_error
else
render :text => "", :status => :bad_request
head :bad_request
end
else
render :text => "", :status => :bad_request
head :bad_request
end
end

View file

@ -194,7 +194,7 @@ class UserController < ApplicationController
redirect_to :action => "lost_password"
end
else
render :text => "", :status => :bad_request
head :bad_request
end
end
@ -375,7 +375,7 @@ class UserController < ApplicationController
if @this_user.visible?
render :action => :api_read, :content_type => "text/xml"
else
render :text => "", :status => :gone
head :gone
end
end
@ -389,7 +389,7 @@ class UserController < ApplicationController
@user.traces.reload.each do |trace|
doc.root << trace.to_xml_node
end
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
def view
@ -752,9 +752,7 @@ class UserController < ApplicationController
##
# require that the user in the URL is the logged in user
def require_self
if params[:display_name] != @user.display_name
render :text => "", :status => :forbidden
end
head :forbidden if params[:display_name] != @user.display_name
end
##

View file

@ -20,7 +20,7 @@ class UserPreferenceController < ApplicationController
end
doc.root << el1
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
##
@ -28,7 +28,7 @@ class UserPreferenceController < ApplicationController
def read_one
pref = UserPreference.find([@user.id, params[:preference_key]])
render :text => pref.v.to_s, :content_type => "text/plain"
render :plain => pref.v.to_s
end
# update the entire set of preferences
@ -57,7 +57,7 @@ class UserPreferenceController < ApplicationController
new_preferences.each_value(&:save!)
render :text => "", :content_type => "text/plain"
render :nothing => true, :content_type => "text/plain"
end
##
@ -74,7 +74,7 @@ class UserPreferenceController < ApplicationController
pref.v = request.raw_post.chomp
pref.save!
render :text => "", :content_type => "text/plain"
render :nothing => true, :content_type => "text/plain"
end
##
@ -82,6 +82,6 @@ class UserPreferenceController < ApplicationController
def delete_one
UserPreference.find([@user.id, params[:preference_key]]).delete
render :text => "", :content_type => "text/plain"
render :nothing => true, :content_type => "text/plain"
end
end

View file

@ -16,7 +16,7 @@ class WayController < ApplicationController
# Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
way.create_with_history @user
render :text => way.id.to_s, :content_type => "text/plain"
render :plain => way.id.to_s
end
def read
@ -25,9 +25,9 @@ class WayController < ApplicationController
response.last_modified = way.timestamp
if way.visible
render :text => way.to_xml.to_s, :content_type => "text/xml"
render :xml => way.to_xml.to_s
else
render :text => "", :status => :gone
head :gone
end
end
@ -40,7 +40,7 @@ class WayController < ApplicationController
end
way.update_from(new_way, @user)
render :text => way.version.to_s, :content_type => "text/plain"
render :plain => way.version.to_s
end
# This is the API call to delete a way
@ -50,9 +50,9 @@ class WayController < ApplicationController
if new_way && new_way.id == way.id
way.delete_with_history!(new_way, @user)
render :text => way.version.to_s, :content_type => "text/plain"
render :plain => way.version.to_s
else
render :text => "", :status => :bad_request
head :bad_request
end
end
@ -73,9 +73,9 @@ class WayController < ApplicationController
end
doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
else
render :text => "", :status => :gone
head :gone
end
end
@ -96,7 +96,7 @@ class WayController < ApplicationController
doc.root << way.to_xml_node
end
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
##
@ -112,6 +112,6 @@ class WayController < ApplicationController
doc.root << way.to_xml_node if way.visible
end
render :text => doc.to_s, :content_type => "text/xml"
render :xml => doc.to_s
end
end

View file

@ -1122,7 +1122,7 @@ class UserControllerTest < ActionController::TestCase
basic_authorization(user.email, "test")
get :api_gpx_files
assert_response :success
assert_equal "text/xml", response.content_type
assert_equal "application/xml", response.content_type
# check the data that is returned
assert_select "gpx_file[id='#{trace1.id}']", 1 do

View file

@ -53,7 +53,7 @@ class UserPreferenceControllerTest < ActionController::TestCase
# try the read again
get :read
assert_response :success
assert_equal "text/xml", @response.content_type
assert_equal "application/xml", @response.content_type
assert_select "osm" do
assert_select "preferences", :count => 1 do
assert_select "preference", :count => 2