Skip to content

Commit

Permalink
Merge pull request #25408 from kamipo/should_not_reuse_quoted_true
Browse files Browse the repository at this point in the history
Quoting booleans should return a frozen string
  • Loading branch information
senny committed Jul 27, 2016
1 parent 6da5186 commit b68f6f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Expand Up @@ -112,19 +112,19 @@ def quote_default_expression(value, column) # :nodoc:
end

def quoted_true
"'t'"
"'t'".freeze
end

def unquoted_true
't'
't'.freeze
end

def quoted_false
"'f'"
"'f'".freeze
end

def unquoted_false
'f'
'f'.freeze
end

# Quote date/time values for use in SQL input. Includes microseconds
Expand Down
Expand Up @@ -2,7 +2,7 @@ module ActiveRecord
module ConnectionAdapters
module MySQL
module Quoting # :nodoc:
QUOTED_TRUE, QUOTED_FALSE = '1', '0'
QUOTED_TRUE, QUOTED_FALSE = '1'.freeze, '0'.freeze

def quote_column_name(name)
@quoted_column_names[name] ||= "`#{super.gsub('`', '``')}`"
Expand Down
16 changes: 16 additions & 0 deletions activerecord/test/cases/quoting_test.rb
Expand Up @@ -149,5 +149,21 @@ def test_quote_duration
assert_equal "1800", @quoter.quote(30.minutes)
end
end

class QuoteBooleanTest < ActiveRecord::TestCase
def setup
@connection = ActiveRecord::Base.connection
end

def test_quote_returns_frozen_string
assert_predicate @connection.quote(true), :frozen?
assert_predicate @connection.quote(false), :frozen?
end

def test_type_cast_returns_frozen_value
assert_predicate @connection.type_cast(true), :frozen?
assert_predicate @connection.type_cast(false), :frozen?
end
end
end
end

0 comments on commit b68f6f1

Please sign in to comment.