2017/11/14分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
update_all
will now pass its values toType#cast
before passing them toType#serialize
. This means thatupdate_all(foo: 'true')
will properly persist a boolean.- Require raw SQL fragments to be explicitly marked when used in relation query methods
Use .tt extension to all the template files
railtiesの修正です。
generatorで使用するtemplates filesの拡張子をまとめてtt
に更新しています。
元はtt
だったりrb
だったりjs
だったり色々混ざっていたのですが、rb
やjs
だとエディタで開いた時や静的解析のときに困る(拡張子的には正しいRubyやJSのファイルのように思えるが、実際の中身は違う為)ので、すべてThorのtemplateである事を表すtt
を使用するようにしています。
Merge pull request #30980 from sobrinho/sobrinho/arel-star-ignored-columns
activerecord/lib/active_record/relation/query_methods.rb
の修正です。
ignored_columns
に指定したcolumnに対するattribute methodsが、modelのreload後に定義されてしまうバグがあったのを修正しています。
Properly cast input in update_all
activerecord/lib/active_record/sanitization.rb
の修正です。
update_all
の引数に指定された値をType#serialize
に渡す前にcastするよう修正しています。
これにより、update_all(foo: 'true')
のようにStringの"true"を渡した際にb、ooleanのtrue
として評価されるようになります。
Merge pull request #31117 from renuo/fix_errors_added
activemodel/lib/active_model/errors.rb
の修正です。
ActiveModel::Errors#added?
メソッドが、message
引数にSymbolを指定した、かつ、既に同じattribute
で別のエラーメッセージが格納されている場合にtrue
を返してしまうバグがあったのを修正しています。
Preserve existing metadata when analyzing a blob
activestorage/app/models/active_storage/blob.rb
の修正です。
blobのanalyze処理を行った際に、元々保持していたmetadataが失われしまった(analyze処理で設定されたmetadataで上書きされてしまっていた)のを、元のmetadataも保持するよう修正しています。
actionmailer/lib/action_mailer/preview.rb
の修正です。
mailer preivewを表示する際に、アルファベット順にソートした値を表示するよう修正しています。
Merge pull request #30782 from NickLaMuro/improve_performance_of_inflections
Active Supportの修正です。
ActiveSupport::Inflector.inflections
で使用する正規表現を、メソッド呼び出しごとに毎回生成していたのを、変数で保持して値をキャッシュするよう修正しています。
合わせて、不要なActiveSupport::Inflector.inflections.acronym_regex
attributeをdeprecateにしています。内部でだけで使用している想定のattributeだったのですが、どうにも誤ってdocに乗ってしまった為、削除前にdeprecateにしています。
Active Supportの修正です。
Railsがデフォルトでサポートするcache storeに、Redis cache storeを追加しています。
他のcache store同様に、:namespace、:compress、:compress_threshold, :expires_in, :race_condition_tool等のオプションが指定出来るようになっています。
また、driverが指定出来るようになっており、redis-rbだけでなく、hiredis, Redis::Distributedが指定出来るようになっています。
config.cache_store = :redis_cache_store, driver: :hiredis, namespace: 'myapp-cache', compress: true, timeout: 1, url: "redis://:#{cache_password}@myapp-cache-1:6379/0"
rails guideのCaching with Rails: An Overview
に説明が追加されているので、詳細はそちらを参照。Caching with Rails: An Overview
Add environment
as dependency of load_config
(#31135)
activerecord/lib/active_record/railties/databases.rake
の修正です。
load_config
taskのdependency にenvironment
taskを追加しています。
元々一部taskではenvironment
taskが実行されていなかった(environmentファイルがロードされてなかった)のですが、それだと、例えばdatabase.yml
にencrypted secretsを使用している場合に問題になる(environmentファイルがロードされない、という事はread_encrypted_secrets
がtrueになる事が無い)為、一通りのtaskでenvironmentファイルのロード処理が行われるようにする為に、load_config
taskのdependency にenvironment
taskを追加しています。
Cache: Enable compression by default for values > 1kB.
activesupport/lib/active_support/cache.rb
の修正です。
cache storeで、cacheされる値が1kb以上の場合デフォルトでcompress処理を行うよう修正しています。
元々はCPUコストを気にしてデフォルトはdisableになっていたのですが、今はそこのコストが低くなったのを、よくcacheに入れるHTMLやJSONは圧縮率が良い為、デフォルトでenableにした、との事です。
Merge pull request #27947 from mastahyeti/unsafe_raw_sql
Active Recordの修正です。
order
とpluck
の引数に生SQLをそのまま渡すのがdeprecateになりました。
User.order("LENGTH(name)") # => DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "LENGTH(name)". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql().
上記のような事をやりたい場合、Arel.sql
メソッドでラップしてあげる必要があります。
User.order(Arel.sql("LENGTH(name)"))
Article.order(params[:my_order])
のような形でquery methodを使用した場合に、SQL injectionが起こるのを防ぐ為、との事です。
5.2時点ではdeprecateメッセージが表示されるだけですが、6.0ではUnknownAttributeReference
がraiseされるようになります。引続き生SQLを渡すようにしたい場合、ActiveRecord::Base.allow_unsafe_raw_sql
に:disabled
を指定すればOKになっています。
Update layouts_and_rendering.md [ci skip]
rails guideのLayouts and Rendering in Rails
の修正です。
Local Variables
の項のcounter変数についての説明の言い回しを修正しています。
activerecord/lib/active_record/relation/finder_methods.rb
のdocの修正です。
exists?
メソッドのdocにrelationとチェインして使用した場合のexample(Person.where(name: 'Spartacus', rating: 4).exists?
)を追加しています。