Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quoting booleans should return a frozen string #25408

Merged
merged 1 commit into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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