aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKir Shatrov <shatrov@me.com>2017-06-20 23:26:13 -0400
committerKir Shatrov <shatrov@me.com>2017-06-20 23:29:37 -0400
commitfa14332ad202dcc941a6dc3863d606e3f3f6e851 (patch)
tree086900f5ffeb34f89f8ad97bdb3231b7254060b4
parentab0e4558816b1a69b4e96446ffe2812e21053b42 (diff)
downloadrails-fa14332ad202dcc941a6dc3863d606e3f3f6e851.tar.gz
rails-fa14332ad202dcc941a6dc3863d606e3f3f6e851.tar.bz2
rails-fa14332ad202dcc941a6dc3863d606e3f3f6e851.zip
Avoid begin/rescue in fixture quoting
Scalar values like arrays and hashes can't be inserted directly into table. Previously, the way to determine if the value is scalar was to try quoting it. If `quote` raised with an error than the value has to be converted to YAML. This flow is not very obvious. Ideally we could have a `quotable?` method in the connection, but I think that we can avoid begin/rescue block by simply checking if the value is Array or Hash. https://github.com/rails/rails/commit/aa31d21f5f4fc4d679e74a60f9df9706da7de373
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index dc766ce4fc..af5314c1d6 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -425,12 +425,11 @@ module ActiveRecord
# are not quotable. In this case we want to convert
# the column value to YAML.
def with_yaml_fallback(value)
- begin
- quote(value)
- rescue TypeError
- value = YAML.dump(value)
+ if value.is_a?(Hash) || value.is_a?(Array)
+ YAML.dump(value)
+ else
+ value
end
- value
end
end
end