aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-03-06 09:46:04 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-03-06 09:46:04 +0000
commitdbf42e379becc5612a0efe3476a999a9d6d803f0 (patch)
tree63809e19f53fc202369acae0bd027ba2352b9d2a /actionpack/lib/action_controller
parente0cded2bbfc72ebbdae5b3c5926dc67f8fb59631 (diff)
downloadrails-dbf42e379becc5612a0efe3476a999a9d6d803f0.tar.gz
rails-dbf42e379becc5612a0efe3476a999a9d6d803f0.tar.bz2
rails-dbf42e379becc5612a0efe3476a999a9d6d803f0.zip
Prefer MIME constants to strings. Closes #7707.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6350 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/deprecated_request_methods.rb6
-rw-r--r--actionpack/lib/action_controller/mime_type.rb8
-rwxr-xr-xactionpack/lib/action_controller/request.rb8
-rwxr-xr-xactionpack/lib/action_controller/response.rb2
-rw-r--r--actionpack/lib/action_controller/test_process.rb14
5 files changed, 19 insertions, 19 deletions
diff --git a/actionpack/lib/action_controller/deprecated_request_methods.rb b/actionpack/lib/action_controller/deprecated_request_methods.rb
index a6cf87e358..93663bdda4 100644
--- a/actionpack/lib/action_controller/deprecated_request_methods.rb
+++ b/actionpack/lib/action_controller/deprecated_request_methods.rb
@@ -6,10 +6,10 @@ module ActionController
# For backward compatibility, the post format is extracted from the
# X-Post-Data-Format HTTP header if present.
def post_format
- case content_type.to_s
- when 'application/xml'
+ case content_type
+ when Mime::XML
:xml
- when 'application/x-yaml'
+ when Mime::YAML
:yaml
else
:url_encoded
diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb
index 17b3d861ec..b179fe2f89 100644
--- a/actionpack/lib/action_controller/mime_type.rb
+++ b/actionpack/lib/action_controller/mime_type.rb
@@ -24,7 +24,7 @@ module Mime
def initialize(order, name, q=nil)
@order = order
@name = name.strip
- q ||= 0.0 if @name == "*/*" # default "*/*" to end of list
+ q ||= 0.0 if @name == Mime::ALL # default wilcard match to end of list
@q = ((q || 1.0).to_f * 100).to_i
end
@@ -70,7 +70,7 @@ module Mime
# Take care of the broken text/xml entry by renaming or deleting it
text_xml = list.index("text/xml")
- app_xml = list.index("application/xml")
+ app_xml = list.index(Mime::XML.to_s)
if text_xml && app_xml
# set the q value to the max of the two
@@ -84,9 +84,9 @@ module Mime
# delete text_xml from the list
list.delete_at(text_xml)
-
+
elsif text_xml
- list[text_xml].name = "application/xml"
+ list[text_xml].name = Mime::XML.to_s
end
# Look for more specific xml-based types and sort them ahead of app/xml
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb
index 38584a6481..cd80415f82 100755
--- a/actionpack/lib/action_controller/request.rb
+++ b/actionpack/lib/action_controller/request.rb
@@ -60,16 +60,16 @@ module ActionController
begin
# Receive header sans any charset information.
content_type = @env['CONTENT_TYPE'].to_s.sub(/\s*\;.*$/, '').strip.downcase
-
+
if x_post_format = @env['HTTP_X_POST_DATA_FORMAT']
case x_post_format.to_s.downcase
when 'yaml'
- content_type = 'application/x-yaml'
+ content_type = Mime::YAML.to_s
when 'xml'
- content_type = 'application/xml'
+ content_type = Mime::XML.to_s
end
end
-
+
Mime::Type.lookup(content_type)
end
end
diff --git a/actionpack/lib/action_controller/response.rb b/actionpack/lib/action_controller/response.rb
index 38647670f2..429b3eff32 100755
--- a/actionpack/lib/action_controller/response.rb
+++ b/actionpack/lib/action_controller/response.rb
@@ -20,7 +20,7 @@ module ActionController
end
def charset=(encoding)
- self.headers["Content-Type"] = "#{content_type || "text/html"}; charset=#{encoding}"
+ self.headers["Content-Type"] = "#{content_type || Mime::HTML}; charset=#{encoding}"
end
def charset
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb
index beccec6f94..b1eb9e38ef 100644
--- a/actionpack/lib/action_controller/test_process.rb
+++ b/actionpack/lib/action_controller/test_process.rb
@@ -325,29 +325,29 @@ module ActionController #:nodoc:
class TestUploadedFile
# The filename, *not* including the path, of the "uploaded" file
attr_reader :original_filename
-
+
# The content type of the "uploaded" file
attr_reader :content_type
-
- def initialize(path, content_type = 'text/plain')
+
+ def initialize(path, content_type = Mime::TEXT)
raise "#{path} file does not exist" unless File.exist?(path)
@content_type = content_type
@original_filename = path.sub(/^.*#{File::SEPARATOR}([^#{File::SEPARATOR}]+)$/) { $1 }
@tempfile = Tempfile.new(@original_filename)
FileUtils.copy_file(path, @tempfile.path)
end
-
+
def path #:nodoc:
@tempfile.path
end
-
+
alias local_path path
-
+
def method_missing(method_name, *args, &block) #:nodoc:
@tempfile.send(method_name, *args, &block)
end
end
-
+
module TestProcess
def self.included(base)
# execute the request simulating a specific http method and set/volley the response