2015/02/12分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
current_scope
shouldn't pollute sibling STI classes- Refactor enum to be defined in terms of the attributes API
Remove most PG specific type subclasses
PostgreSQLのConnectionAdaptersの修正です。
元々、各種型用のサブクラス(OID::Integer
、OID::Time
等)をActiveRecordで定義していたのですが、最新のpg
gemでは、gemの方で変換用クラスがあり、Cで書かれている為、そちらの方が高速に動作すると思われるので、使用出来るものについてはpg
で定義されているクラス(PG::TextDecoder::Integer
、PG::TextDecoder::Boolean
)を使用するよう修正しています。
Remove an unused option that I didn't mean to commit [ci skip]
activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb
の修正です。
先のコミットで誤って追加してしまったTypeMapInitializer
のコンストラクタのrun_complex_types
オプションを削除しています。
Reduce object allocations in ActiveSupport::Subscriber
activesupport/lib/active_support/subscriber.rb
の修正です。
finish
メソッドで引数のname
を分割する際に使用する区切り文字を、freeze
しています。 オブジェクト生成数の軽減の為との事。
Remove the SQLite3 Binary subclass
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
の修正です。
ConnectionAdapters::SQLite3Binary
クラスを削除しています。値のエンコーディングがEncoding::ASCII_8BIT
以外だった場合に、強制的にEncoding::ASCII_8BIT
に変換する処理が行われていたのですが、他の場所で既に行われており、ここでの処理は不要な為、削除したようです。多分。
Fixes wording of test description
activesupport/test/xml_mini_test.rb
の修正です。
テスト名が実際の内容と異なっていたので、適切な内容にテスト名を修正しています。
Revert 88d08f2ec9f89ba431cba8d0c06ac9ebc204bbbb
activesupport/lib/active_support/core_ext/module/delegation.rb
の修正です。
Fix confusing exception in ActiveSupport delegationをrevertしています。
Module#delegate
を使用している時に、delegate
先のメソッドでNoMethodError
が起きた際に、NoMethodError
ではなくRuntimeError
が発生してしまう問題があったのを直したコミットだったのですが、integration testの性能劣化の原因になってしまっていたらしく、revertされています。
Merge pull request #18374 from claudiob/add-collection-to-fresh-when
actionpack/lib/action_controller/metal/conditional_get.rb
の修正です。
ActionController::ConditionalGet#fresh_when
、stale?
メソッドにrecordのcollectionを渡せるよう対応しています。collectionを渡した場合は、collection内の最大のupdated_at
の値をlast_modified
に設定してくれます。
# Before def index @articles = Article.all fresh_when(etag: @articles, last_modified: @articles.maximum(:updated_at)) end # After def index @articles = Article.all fresh_when(@articles) end
これは便利。
Merge pull request #18888 from kamipo/refactor_quote_default_expression
ActiveRecordの修正です。
quote_default_expression
メソッドのリファクタリング(Quoting#quote_default_value
-> Quoting#quote_default_expression
にメソッド名の変更、及び重複コードの削除)を行っています。
current_scope
shouldn't pollute sibling STI classes
activerecord/lib/active_record/scoping.rb
、
activerecord/lib/active_record/scoping/named.rb
の修正です。
STIを使用している際、同じ親クラスを持つ全てのクラスのscope
が参照されてしまっていたバグがあったのを修正しています。
PRから。
# schema create_table :sti_roots, force: true do |t| t.string :type t.belongs_to :owner end create_table :owners, force: true do |t| end
class StiRoot < ActiveRecord::Base belongs_to :owner scope :of_type, ->(cls) do all.merge cls.all end end class StiLeaf1 < StiRoot end class StiAbstract < StiRoot end class StiLeaf2 < StiAbstract end class StiLeaf3 < StiAbstract end class Owner < ActiveRecord::Base has_many :sti_roots end class BugTest < Minitest::Test def test_association_stuff owner = Owner.create! owner.sti_roots << StiLeaf1.create! owner.sti_roots << StiLeaf2.create! owner.sti_roots << StiLeaf3.create! assert_equal 2, owner.sti_roots.of_type(StiAbstract).count # => Expected: 2 Actual: 3 end end
親であるStiRoot
のof_type
scopeでは、本来は引数に指定したStiAbstract
クラスの値のみ取得出来なければなけないのですが、current_scope
メソッドでScopeRegistry.value_for
の引数にbase classの値を指定していたので、同じ親を持つStiLeaf1
クラスの値も取得されてしまった、値がおかしくなっていた、というバグとの事です。…合ってるかなあ。
Refactor enum to be defined in terms of the attributes API
activerecord/lib/active_record/enum.rb
の修正です。
attributes APIの規約にしたがって、enumに関する処理をリファクタしています。
合わせて、where
に直接enumの値を指定出来るよう対応しています。
class Thing < ActiveRecord::Base enum state: [:working, :broken] end
Thing.create!(state: :broken) Thing.where(state: Thing.states[:broken]) # => #<Thing id: 1, state: "broken", created_at: "2015-02-12 07:43:12", updated_at: "2015-02-12 07:43:12"> Thing.where(state: 'broken') # => #<Thing id: 1, state: "broken", created_at: "2015-02-12 07:43:12", updated_at: "2015-02-12 07:43:12">
直接値を指定出来るのは便利ですねえ。
activerecord/lib/active_record/enum.rb
の修正です。
Enum#type_cast_from_database
メソッドでIntegerへの変換処理が不足していたのを修正しています。
Properly dump primitive-like AS::SafeBuffer strings as YAML
activesupport/lib/active_support/core_ext/string/output_safety.rb
の修正です。
ActiveSupport::SafeBuffer#to_yaml
を呼び出した際、primitiveな値についても、String
の値を返すよう修正しています。
# Before: YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello" YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => true YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => false YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => 1 YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => 1.1 # After: YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello" YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => "true" YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => "false" YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => "1" YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => "1.1"
PHPやJavaScriptの振る舞いに合わせた、との事。
fix typo in fresh_when example [ci skip]
actionpack/CHANGELOG.md
の修正です。
先にコミットされたfresh_when
の対応で記載されたexampleにタイポがあったのを修正しています。
tests, remove unused requires.
activerecord/test/cases/migration/foreign_key_test.rb
、
activerecord/test/cases/migration_test.rb
の修正です。
不要なactive_support/testing/stream
のrequireを削除しています。
pg tests, be clear about the missing type that causes a test skip.
activerecord/test/cases/adapters/postgresql/json_test.rb
、
activerecord/test/cases/migration_test.rb
の修正です。
json型のテストをskipする際、表示されるメッセージをより分かりやすい内容に修正、及びテスト用のtableをdropする際、if_exists
オプションでチェックするよう修正しています。
get rid of transaction warning when running PG tests.
activerecord/test/cases/helper.rb
の修正です。
"WARNING: there is no transaction in progress"が出力されてしまっていたので、トランザクション実行中のみコミットするよう修正しています。