なるようになるブログ

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

rails commit log流し読み(2015/08/11)

2015/08/11分のコミットです。

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

activejob/CHANGELOG.md

activesupport/CHANGELOG.md

activerecord/CHANGELOG.md


we have the resource on the stack, so just use it

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

resource_scopeメソッドで、controller_scopeメソッドを呼び出す際の引数のresourceを取得するのに、parent_resourceメソッドで取得していたのを、自身のメソッドの引数に指定されたresourceを使用するよう修正しています。


pass shallow in to the resource constructor

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

Resourceクラスのコンストラクタshallow変数を追加しています。セッターメソッドを削除&Resourceオブジェクトをread onlyにするためとの事です。


remove @nesting ivar

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

Mapperクラスからnesting変数を削除しています。 @scopeのlinked listから同じ情報を取得出来、そちらから取得する為不要との事です。


add a null node at the top of the stack

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

@scope stackの先頭にnull nodeを追加しています。stack のイテレーションをしやすくする為、との事なのですが、よくわからなかった…。


Update info on browser connection limits [ci skip]

actionview/lib/action_view/helpers/asset_url_helper.rbのdocの修正です。

ブラウザの同時接続数についての説明を修正しています。


[ci skip] Fix simultaneous spelling

actionview/lib/action_view/helpers/asset_url_helper.rbのdocの修正です。

simulataneous -> simultaneousにタイポを修正しています。


reuse the same frame so we don't need a singleton hash

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

Scope#new_levelメソッドで、新規にscope作成する際に、空のHashではなく、定義済みのframeを使いまわすよう修正しています。


push with_scope_level up so resource_scope doesn't know

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

with_scope_levelの呼び出しをresource_scopeより先に行うよう修正しています。

resource_scopeはresource scopesをstackに追加しているだけで、scope_levelについての情報は保持していない為、との事です。


avoid another call to scope

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

rootメソッドの中でscopeメソッドを直接呼び出していたのを、path_scopeメソッドを使用するよう修正しています。

scopeメソッドの呼び出し処理はコストが高いので、極力使わないよう修正しているようです。


avoid is_a? calls

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

Mapper#shallow?メソッドでresource objectがシングルトンかどうかinstance_of?メソッドを使っていたのを、各resource classにsingleton?メソッドを追加し、そちらのメソッド経由で確認するよう修正しています。


remove dead code

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

使用しなくなったwith_exclusive_scopeメソッドを削除しています。


remove another call to scope

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

controllerメソッドの中でscopeメソッドを直接呼び出していたのを、controller_scopeメソッドを使用するよう修正しています。


let the controller method push / pop the stack

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

controllerメソッドcontroller_scopeメソッドを呼び出すだけしかしていなかったので、controllerメソッドcontroller_scopeメソッドの処理を移動し、controller_scopeメソッドは削除しています。


avoid calling scope on defaults methods

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

defaultsメソッドscopeメソッドを呼びださないず、Scopeクラスを使用し処理を行うよう修正しています。


pull defaults extraction up the stack.

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

Mapping.buildで行っていたdefaultsオプションに関する処理を、map_methodメソッドで行うよう修正しています。コミットログにup the stackとなっているので、早めに処理を行う為、ですかねえ。


Make assert_enqueued_with and assert_performed_with returns the matched job

activejob/lib/active_job/test_helper.rbの修正です。

assert_enqueued_withassert_performed_withメソッドが、引数に指定した情報とマッチするjobのインスタンスを返すよう修正しています。

実行したjobのインスタンスに対して、テストを行いたい事がある為とのことです。例。

job = assert_enqueued_with(job: SomeJob) do
  some_business_logic
end

assert_in_delta 5.minutes.from_now, job.scheduled_at, 1
assert_equal 5, job.arguments.second

Merge pull request #21184 from brooksreese/touch_on_unit_testing

rails guideのThe Rails Command Lineの修正です。

rails generateの項、unit testについて説明している箇所に、testing guideへのリンクを追加しています。


pull path conditional up

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

path_for_actionメソッドaction_pathメソッドそれぞれでpathのチェックを行っていたのを、path_for_actionメソッドだけで行うよう修正しています。


always cast name to a symbol, and never to_s it

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

action_pathメソッドname引数の不要なStringへの変換処理を削除しています。 action_pathに値が渡る際は、必ずStringになっている為、との事。


try to pass fewer options to scope

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

namespaceメソッドscopeを呼び出す際、optionsをまるまる渡していたのを、先にpath_scopeメソッドを呼び出してpathに関する処理はそちらで行うようにし、scopeメソッドにはpathについての情報を渡さずに済むよう修正しています。


Only use path if the key is not present

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

namespaceメソッドで、明示的にpathオプションにnilが指定されていた場合に、設定されてないとみなすようになってしまっていたのを、nilが指定された場合にnilのまま扱うよう修正しています。


Merge pull request #21191 from byroot/deprecate-si-prefix

activesupport/lib/active_support/number_helper/number_to_human_size_converter.rbの修正です。

number_to_human_sizeメソッドprefixオプションを使用するのはdeprecateになりました。代わりのオプションも無しです。

prefixオプション、si formatを付与する為のオプションだったのですが、設定した場合の表示がどうなるかわかりずらいし、そもそもそんなに使用するようなものでも無いので、削除する事になったようです。 詳細はAdded :prefix => :iec option by jarl-dk · Pull Request #7835 · rails/rails 参照。


:nodoc: internal class [ci skip]

activesupport/lib/active_support/notifications/fanout.rbの修正です。

内部用クラスであるTimedクラスに:nodoc:オプションを追加しています。


Merge pull request #21138 from dhiachou/patch-2

rails guideのRuby on Rails Security Guideの修正です。

Railsのセキュリティ機構についての説明がRails 2系のころの説明のままになっていたのを、最新のRailsのセキュリティ機構に合わせて内容を更新しています。


Merge pull request #21165 from manlon/master

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

HABTMを使用している、かつ、2つのmodelで違うDBへのコネクションを保持していた場合に、HABTM先のデータにアクセスした際に、ActiveRecord::StatementInvalidがraiseされてしまうバグがあったのを修正しています。

例。

class Secondary < ActiveRecord::Base
  establish_connection :secondary
  self.abstract_class = true
end
class SecondaryModel < Secondary
  has_and_belongs_to_many :secondary_associateds
end

m = SecondaryModel.create!
puts m.secondary_associateds.count # works fine
m.secondary_associateds << something # raises ActiveRecord::StatementInvalid: Could not find table 'secondary_associateds_models'

DBのコネクションを見に行く際、正しくmodelからretrieve_connectionを取得するよう修正しています。こんな使い方される方もいるんですねえ。


Tiny documentation fixes [ci skip]

actionpack/lib/action_dispatch/routing/mapper.rbのdoc、 guides/source/routing.mdguides/source/security.mdの修正です。

タイポの修正、1行80文字に収まるよう適切な位置に改行を追加、等をまとめて行っています。


Merge pull request #17885 from starbelly/patch-1

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

PostgreSQLDatabaseTasksクラスで、pg_dump等のPostgres標準のコマンドを実行しエラーになった場合に、failし、適切なエラーメッセージを表示するよう修正しています。

実行例。

$ bin/rake db:structure:dump
rake aborted!
failed to execute:
pg_dump -i -s -x -O -f /Users/senny/Projects/playground/ruby/rails/rails-master/db/structure.sql my_db

Please check the output above for any errors and make sure that `pg_dump` is installed in your PATH and has proper permissions.

/Users/senny/Projects/rails/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb:99:in `run_cmd'
/Users/senny/Projects/rails/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb:64:in `structure_dump'
/Users/senny/Projects/rails/activerecord/lib/active_record/tasks/database_tasks.rb:182:in `structure_dump'
/Users/senny/Projects/rails/activerecord/lib/active_record/railties/databases.rake:276:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:structure:dump

Merge pull request #21187 from arthurnn/method_missing_routes_av

actionview/lib/action_view/test_case.rbの修正です。

TestController#method_missingメソッドで、_routes呼び出し処理をbegin/rescueで囲んで、エラーが返されないよう修正しています。

-        if @controller.respond_to?(:_routes) &&
-          ( @controller._routes.named_routes.route_defined?(selector) ||
-            @controller._routes.mounted_helpers.method_defined?(selector) )
+        begin
+          routes = @controller.respond_to?(:_routes) && @controller._routes
+        rescue
+          # Dont call routes, if there is an error on _routes call
+        end
+
+        if routes &&
+           ( routes.named_routes.route_defined?(selector) ||
+             routes.mounted_helpers.method_defined?(selector) )

下記のようなテストを実行した場合、 _routesメソッドの呼び出しで、RuntimeError: In order to use #url_for, you must include routing helpers explicitly. For instance, includeRails.application.routes.url_helpersが発生してしまうのですが、url_forメソッドを呼び出してないのに、左記のようなエラーが出るのは良くないだろう、という事で、エラーを潰すようにしたようです。

class BugTest < ActionView::TestCase
  def test_foo
    omg
  end
end