aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-06-16 06:14:12 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-07-27 00:44:16 +0900
commita3a6d74c7774fc9f5df4f171bf6e7926c77fbe64 (patch)
tree3572af614ed5082dad2081ecab3d5f05b4f4e353 /activerecord/test
parent245c64d428279122c5ae2ddfdc4d420a87a88f9a (diff)
downloadrails-a3a6d74c7774fc9f5df4f171bf6e7926c77fbe64.tar.gz
rails-a3a6d74c7774fc9f5df4f171bf6e7926c77fbe64.tar.bz2
rails-a3a6d74c7774fc9f5df4f171bf6e7926c77fbe64.zip
Quoting booleans should return a frozen string
If reuse `QUOTED_TRUE` and `QUOTED_FALSE` without frozen, causing the following issue. ``` Loading development environment (Rails 5.1.0.alpha) irb(main):001:0> ActiveRecord::Base.connection.quote(true) << ' foo' => "1 foo" irb(main):002:0> ActiveRecord::Base.connection.quote(true) << ' foo' => "1 foo foo" irb(main):003:0> type = ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlString.new => #<ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlString:0x007fd40c15e018 @precision=nil, @scale=nil, @limit=nil> irb(main):004:0> type.serialize(true) << ' bar' => "1 foo foo bar" irb(main):005:0> type.cast(true) << ' bar' => "1 foo foo bar bar" ```
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/quoting_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb
index c01c82f4f5..225e23bc83 100644
--- a/activerecord/test/cases/quoting_test.rb
+++ b/activerecord/test/cases/quoting_test.rb
@@ -149,5 +149,21 @@ module ActiveRecord
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