なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2014/07/16)

2014/07/16分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

activerecord/CHANGELOG.md

railties/CHANGELOG.md

activemodel/CHANGELOG.md

activesupport/CHANGELOG.md


Merge pull request #15266 from dv/use_counter_cache_for_empty_call

activerecord/lib/active_record/associations/has_many_association.rbの修正です。

HasManyAssociation#empty?メソッドを追加して、counter cacheを使用している場合、counter cacheの値を使用するよう修正しています。


Add CHANGELOG entry for #15266

activerecord/CHANGELOG.mdの修正です。

上記empty?メソッドの対応についてCHANGELOGに追記しています。


Fix version detection for RENAME INDEX support. Fixes #15931.

MySQLのConnectionAdapterの修正です。

MySQLの5.7からALTER TABLEにRENAME INDEXという書式が追加されたのですが、MariaDBでは対応していないので、MariaDBの場合RENAME INDEXを使用しないよう修正しています。

MariaDBだと使用出来ないんですねえ。何でだろう。


Revert "Revert "Merge pull request #16059 from jenncoop/json-serialized-attr""

revertのrevertで少しややこしいのですが、ActiveRecordの修正です。

serializeにJSONを指定した際の振る舞いを4.0系と同じ振る舞いに戻しています。

class Post < ActiveRecord::Base
  serialize :comment, JSON
end

class Comment
  include ActiveModel::Model
  attr_accessor :category, :text
end

post = Post.create!
post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
post.save!
# 4.0
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}

# 4.1 before
post.comment # => "#<Comment:0x007f80ab48ff98>"

# 4.1 after
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}

"4.1 before"同等の動作が必要な場合、こちらを参考に対応してとの事。


Predicate methods don't need to return true / false

MariaDBの判定処理を修正しています。

-        !!(full_version =~ /mariadb/i)
+        full_version =~ /mariadb/i

不要なboolへの変換処理を削除しています。


Merge pull request #16162 from chancancode/fix_json_coder

activerecord/lib/active_record/coders/json.rbの修正です。

self.loadメソッドで引数のjsonnilチェックを追加しています。

DBのデータnilだった場合にExceptionが発生してしまうので対応しています。

Topic.serialize :content, JSON

# Force a row to have a database NULL instead of a JSON "null"
id = Topic.connection.insert "INSERT INTO topics (content) VALUES(NULL)"
t = Topic.find(id)

assert_nil t.content

t.save!

# On 4.0, re-saving a row with a database NULL will turn that into a JSON
# "null"
assert_equal 1, Topic.where('content = "null"').count

databaseのNULLとJSONの"null"が混ざってちょとややこしい…。


Fixed SQL syntax for postgresql

activerecord/test/cases/serialized_attribute_test.rbの修正です。

PostgreSQLSQL syntaxエラーが出ていたのを修正しています。

-    assert_equal 1, Topic.where('content = "null"').count
+    assert_equal 1, Topic.where("content = 'null'").count

シングルクォートじゃないのが問題ですね。


Document the change in nil handling for serialized attributes

ActiveRecordの各doc、testとupgrading_ruby_on_railsの修正です。

serialized attributesにnilを指定した際に、'null'という文字列ではなく、DBのNULLとして値が格納される旨説明とテストを追加しています。


Add Rails::Application#config_for

railties/lib/rails/application.rbの修正です。

設定ファイルロード用のRails::Application.config_forメソッドを追加しています。

# config/exception_notification.yml:
production:
  url: http://127.0.0.1:8080
  namespace: my_app_production
development:
  url: http://localhost:3001
  namespace: my_app_development

# config/production.rb
MyApp::Application.configure do
  config.exception_notification = config_for(:exception_notification)
end

Rails.application.config.exception_notification['url']
# => http://127.0.0.1:8080

環境毎に異なる値を別ファイルで管理出来るの便利ですね。SettingsLogic使ってた箇所置き換えられるかも。関係無いですが、CHANGELOGに書いてあるサンプルおかしい気が…。


Deprecate ActiveModel::Dirty#reset_changes in favor of #clear_changes_information

activemodel/lib/active_model/dirty.rbの修正です.

ActiveModel::Dirty#reset_changesメソッドがdeprecateになりました。今後は、代わりにActiveModel::Dirty#clear_changes_informationを使用してとの事。

reset_#{attribute}メソッドと名前がバッティングする為のようです。


Deprecate reporting methods for silencing output as they aren't thread safe

activesupport/lib/active_support/core_ext/kernel/reporting.rbの修正です。

Kernelに追加されてた、silence_stderrcapturequietlyがdeprecateになりました。threa safeじゃない為との事。

captureは使用したので、対応しなきゃ。


Implement required #encode_with

activerecord/lib/active_record/relation/delegation.rbの修正です。

encode_withメソッドを追加しています。yaml_serialization_test.rbのテスト実行時にwarningが出力されていて、その対応のようです。


Keep quietly and capture undeprecated on your suite

各テストの追加です。

silence_stderrcapturequietlyがdeprecateになったのですが、テストで使用していうる箇所があったので、各テスト中で同名のメソッドを定義しています。

ああ、このやり方良いですねえ。


Add CHANGELOG entry for #13392 [ci skip]

上記メソッドのdeprecateについてCHANGELOGに追記しています。


Deprecate reset_#{attribute} in favor of restore_#{attribute}.

ActiveRecordの修正です。

reset_#{attribute}メソッドがdeprecateになりました。今後は代わりにrestore_#{attribute}を使うようにとの事です。あれ、reset_changesのdeprecateの理由が…。


RouteSet should be in charge of constructing the dispather

Routingの修正です。

Mapper::MappingクラスのコンストラクタRouteSetを追加しています。


remove useless ivar set

actionpack/test/controller/routing_test.rbの修正です。

使用していない変数を削除しています。


set set in the setup method

actionpack/test/controller/routing_test.rbの修正です。

setupメソッドset処理行うよう修正しています。


execute a request and check the path_parameters

actionpack/test/controller/routing_test.rbの修正です。

requestの実行と、path_parametersのチェック処理を追加しています。 実際本番で使われるの近い形でテストする為に、のようです。


stop calling url_for with recall parameters and actually use a request

routingのテストの修正です。

url_forメソッドを使用するのではなう、requestを使用するようテストを修正しています。


fix warnings

actionpack/test/abstract_unit.rbの修正です。

使用してない変数を削除しています。


rack 1.6 encodes the filenames in posts correctly now

actionpack/lib/action_dispatch/http/upload.rbの修正です。

rack1.6ではpost処理でファイルネームが正しくエンコードされるようになったらしく、独自でencodeを行っていた処理を削除しています。


Move uuid_v5 and uuid_v3 to Digest::UUID

Digest::UUIDモジュールの追加です。

uuid_v3uuid_v5メソッドSecureRandomからDigest::UUIDモジュールに移動しています。

Digest::UUID配下にあるのが適切だろう、という事で移動しています。


stop passing recall to url_for

actionpack/test/controller/url_for_integration_test.rbの修正です。

テスト内でurl_forメソッドrecallオプションを渡すのを止めています。むう、これは何でだろう。


Move #encode_with to Relation

activerecord/lib/active_record/relation.rbの修正です。

Delegation配下にあった#encode_withメソッドRelationに移動しています。


routed applications will respond to these methods

actionpack/lib/action_dispatch/routing/mapper.rbの修正です。

define_generate_prefixの中で、行っていたrespond_to?(:define_mounted_helper)を削除しています。

routed applicationでは定義されているから、とコミットログにはあるのですが、いや、エラーになるケースがあるよーとコメントされているので、戻されるかもですね。


fix for 1.9 kwargs syntax

actionpack/test/abstract_unit.rbの修正です。

request_path_paramsメソッドでキーワード引数を使用しているのですが、当然1.9系では動かないので修正しています。が、修正ミスが。


Fix 1.9. uggghhhhhh get it together @tenderlove :bomb:

再度actionpack/test/abstract_unit.rbの修正です。

修正ミスの対応です。というか、間違ってコミットしたのかなあと。


Merge pull request #16138 from sgrif/sg-attribute-set-key

activerecord/lib/active_record/attribute_set.rbの修正です。

AttributeSet#include?-> AttributeSet#key?に名前を変更しています。

より適切な名前に修正、ということのようです。


use foreign key DSL in our tests.

activerecord/test/cases/adapters/mysql2/schema_migrations_test.rbの修正です。

生のSQLで外部キー設定していた箇所を、add_foreign_keyメソッドを使うよう修正しています。


document assert[not]empty, assert[not]includes, assert[not]predicate in testing guide.

rails guideのA Guide to Testing Rails Applicationsの修正です。

assert_empty、assert_not_empty、assert_includes、assert_not_includes、assert_predicate、assert_not_predicateメソッドについて追記しています。


link minitest assertions documentation.

rails guideのA Guide to Testing Rails Applicationsの修正です。

minitest assertions へのリンクを追加しています。


Active Record tests still depend on capture. Let's keep it for now.

activerecord/test/cases/test_case.rbの修正です。

UndeprecateCaptureモジュールを作成して、captureメソッドUndeprecateCaptureモジュール配下に移動しています。

captureメソッドに依存しているテストが多かったらしく、test_caseのでメソッド読み込むように対応しています。


we intend to keep the capture helper for Active Record tests.

activerecord/test/cases/test_case.rbの修正です。

UndeprecateCaptureモジュールは止めて、TestCaseクラスの下にcaptureメソッドを追加するよう修正しています。