なるようになるブログ

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

rails commit log流し読み(2019/01/14)

2019/01/14分のコミットです。

CHANGELOGへの追加はありませんでした。


Merge pull request #34845 from palkan/feature/action-cable-connection-testing

actioncable/lib/action_cable/connection.rbactioncable/lib/action_cable/connection/test_case.rbの修正です。

ActionCableのconnectionのテストの為のActionCable::Connection::TestCaseクラスを追加しています。

使用例。

class ApplicationCable::Connection < ActionCable::Connection::Base
  identified_by :user_id

  def connect
    self.user_id = request.params[:user_id] || cookies.signed[:user_id]
    reject_unauthorized_connection if user_id.nil?
  end

  def disconnect
    ActionCable.server.broadcast "users_presence", { id: user_id, event: "left" }
  end
end

class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
  def test_connects_with_params
    # Simulate a connection opening
    connect params: { user_id: 42 }

    assert_equal connection.user_id, "42"
  end

  def test_connects_with_cookies
    # the same API as for integrations tests
    cookies.signed[:user_id] = 42

    # just call connect without any arguments
    connect

    assert_equal connection.user_id, "42"
  end

  def test_reject_connection
    assert_reject_connection { connect }
  end
end

Merge actioncable/README.md to the Action Cable Overview guide [ci skip]

actioncable/README.mdrails guideのAction Cable Overviewの修正です。

READMEにのみあったコンテンツをguideに移行、及び、重複している内容の削除を行い、READMEにはguideへのリンクをおくよう修正しています。

内容の重複があったのと、コンテンツの更新漏れ(guideは更新したがREADMEの更新が行われなかった)等があった為。


Fix "Action Cable Overview" guide [ci skip]

rails guideのAction Cable Overviewの修正です。

channel generatorが生成するファイルのパス名に誤りがあったのを修正しています。


Update Action Cable connection testing.

actioncable/lib/action_cable/connection/test_case.rbactioncable/test/connection/test_case_test.rbの修正です。

Action Cable connection testingのリファクタリングとして、不要な処理を削除、docのフォーマット・言い回しを修正、不足していたテストの追加、等を行っています。