なるようになるブログ

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

rails commit log流し読み(2014/05/08)

2014/05/08分のコミットです。

has_and_belongs_to_manyを使用している際にsizeが誤っていたバグの修正が行われています。


test, persist inherited class with different table name. Refs #14971.

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

テーブル名と違うクラスでの永続化の振る舞いの確認のテストです。

inimalistic_aircrafts = Class.new(Minimalistic) do
  self.table_name = "aircraft"
end

assert_difference "Aircraft.count", 1 do
  aircraft = minimalistic_aircrafts.create(name: "Wright Flyer")
  aircraft.name = "Wright Glider"
  aircraft.save
end

assert_equal "Wright Glider", Aircraft.last.name

Aircraft.countが1にならないのはちょっと違和感が。


add tests for symbols passed to polymorphic_url

actionview/test/activerecord/polymorphic_routes_test.rbの修正です。

polymorphic_urlメソッドのテストを追加しています。


HTTP::Headers#key? correctly converts

HTTP::Headers#key?メソッドの修正です。

keyのチェック処理が誤っていたのを修正しています。

env     = { "CONTENT_TYPE" => "text/plain" }
headers = ActionDispatch::Http::Headers.new(env)
headers["Content-Type"]
# => "text/plain"

headers.key?("Content-Type")
# => false

上記の実行結果がtrueになるように修正されています。


test for inconsistency between String and Symbol url_for handling

actionview/test/activerecord/polymorphic_routes_test.rbの修正です。url_forメソッドのテストケースを追加しています。

assert_equal "http://example.com/projects", polymorphic_url("projects")
assert_equal "projects", url_for("projects")

assert_equal "http://example.com/projects", polymorphic_url(:projects)
assert_equal "http://example.com/projects", url_for(:projects)

url_forメソッドはString/Symbolで挙動が違うんですね。

Merge pull request #13166 from bogdan/transaction-magic

ActiveRecord::Transactionsの修正です。

ちょっとややこしいのでテストコードから抜粋。

assert !model.approved?
Topic.transaction do
  model.approved = true
  model.save!
  raise ActiveRecord::Rollback
end
model.save!
assert @first.reload.approved

最後のmodel.save!でデータが更新されないというバグがあり、正しく値が更新されるよう修正されています。

一度Rollbackが走っている場合状態なので、ちょっと特殊なケースな気がします。なお、Rails 3.2では元々上記動作でしたので、処理を戻した形ですになります。


Keep track of dirty attrs after after rollback.

上記コミットの追加修正です。

テストメソッドがxxx1、xxx2になっていたのの修正、不要な変数の削除など。


Merge pull request #12746 from coreyward/master

Hash#deep_mergeメソッドのバグの修正及びdocの修正です。

Hashにfalseの値があった時の挙動を修正しています。

# before
  hash_1 = { e: false }
  hash_2 = { e: 'e' }
  hash_1.deep_merge(hash_2) { |k, o, n| [k, o, n] }  # {:e=>"e"}

# after
  hash_1 = { e: false }
  hash_2 = { e: 'e' }
  hash_1.deep_merge(hash_2) { |k, o, n| [k, o, n] }  # {:e=>[:e, false, "e"]}

Return a non zero code when db has never been setup on status

activerecord/lib/active_record/railties/databases.rakeの修正です。

db:migrate:statusで、dbのセットアップがされていない場合、abortメソッドで処理を終了するようにしています。

元々はputsでメッセージ表示するだけだったので、終了ステータスみても0で、正常/異常が分からなかったんですねえ。


Add CHANGELOG entry for #14989

上記修正について、CHANGELOに追加しています。


Use Rails::Paths::Path#existent in database_configuration

Rails::Application::Rails::Engine::Configuration::Configuration#database_configurationメソッドの修正です。

"config/database"に存在しないファイルのパスが設定されていた場合に、エラーになってしまっていたのですが、existentメソッドを挟むようにして、ファイルの存在チェックをいれるようにしてます。

application.rbにconfig.paths.add 'config/database, with: xxx'を設定する事でdatabases.yml以外のファイルを使うことが出来るんですね。知らなかった。


Dup the changed_attributes otherwise we could lose them

ActiveRecord::Transactionsの修正です。

このコミット以降、テストが壊れてしまったらしく、その対処との事。

-      @_start_transaction_state[:changed_attributes] ||= changed_attributes
+      @_start_transaction_state[:changed_attributes] ||= changed_attributes.dup

元の値を壊さないよう、dupした値を渡すように修正されています。



Branch name should match in text and code example.

rails guideのContributing to Ruby on Railsの修正です。

Older Versions of Ruby on Railsの項のブランチを3.0 -> 4.0に修正しています。


Fixed HABTM's CollectionAssociation size

ActiveRecord::Associations::HasManyAssociation::HasManyThroughAssociation#sizeメソッドの修正です。

has_and_belongs_to_manyを使用している際に、返す値を誤っていたのを修正しています。


pg guide, inet code example. [ci skip]

rails guideのActive Record and PostgreSQLのページの修正です。 inetについてのexampleを追加しています。


test, reset changed state in PG's uuid tests.

activerecord/test/cases/adapters/postgresql/uuid_test.rbの修正です。

カラムが無くてエラーになってしまうケースがあったらしく、UUIDType.reset_column_informationを追加しています。


test, regression test for unparsable PostgreSQL defaults.

activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rbへのテストコードの追加です。

defaultにパース出来ない値が設定された場合のテストケースを追加しています。

現状は動いているのですが、こちらのPRで処理の修正を行っているらしく、そちらがマージされたら壊れる予定。