Skip to content

Commit 0e97aa2

Browse files
committed
Merge pull request rails#6705 from ganeshkumar/string_method_changes
both string and symbol will be interpolated as string no need to convert to_s
2 parents 5304ae1 + c74662a commit 0e97aa2

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

actionpack/lib/action_dispatch/http/mime_type.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ def register_alias(string, symbol, extension_synonyms = [])
9999
end
100100

101101
def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], skip_lookup = false)
102-
Mime.const_set(symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms))
102+
Mime.const_set(symbol.upcase, Type.new(string, symbol, mime_type_synonyms))
103103

104-
SET << Mime.const_get(symbol.to_s.upcase)
104+
SET << Mime.const_get(symbol.upcase)
105105

106106
([string] + mime_type_synonyms).each { |str| LOOKUP[str] = SET.last } unless skip_lookup
107107
([symbol] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext.to_s] = SET.last }
@@ -194,7 +194,7 @@ def parse_data_with_trailing_star(input)
194194
#
195195
# Mime::Type.unregister(:mobile)
196196
def unregister(symbol)
197-
symbol = symbol.to_s.upcase
197+
symbol = symbol.upcase
198198
mime = Mime.const_get(symbol)
199199
Mime.instance_eval { remove_const(symbol) }
200200

actionpack/test/dispatch/mime_type_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ class MimeTypeTest < ActiveSupport::TestCase
148148
types = Mime::SET.symbols.uniq - [:all, :iphone]
149149

150150
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
151-
types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
151+
types.delete_if { |type| !Mime.const_defined?(type.upcase) }
152152

153153

154154
types.each do |type|
155-
mime = Mime.const_get(type.to_s.upcase)
155+
mime = Mime.const_get(type.upcase)
156156
assert mime.respond_to?("#{type}?"), "#{mime.inspect} does not respond to #{type}?"
157157
assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
158158
invalid_types = types - [type]
@@ -170,10 +170,10 @@ class MimeTypeTest < ActiveSupport::TestCase
170170
all_types = Mime::SET.symbols
171171
all_types.uniq!
172172
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
173-
all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
173+
all_types.delete_if { |type| !Mime.const_defined?(type.upcase) }
174174
verified, unverified = all_types.partition { |type| Mime::Type.browser_generated_types.include? type }
175-
assert verified.each { |type| assert Mime.const_get(type.to_s.upcase).verify_request?, "Verifiable Mime Type is not verified: #{type.inspect}" }
176-
assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" }
175+
assert verified.each { |type| assert Mime.const_get(type.upcase).verify_request?, "Verifiable Mime Type is not verified: #{type.inspect}" }
176+
assert unverified.each { |type| assert !Mime.const_get(type.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" }
177177
end
178178

179179
test "references gives preference to symbols before strings" do

0 commit comments

Comments
 (0)