File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
lib/rails/generators/rails/authentication
templates/app/channels/application_cable Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ def create_authentication_files
19
19
template "app/controllers/concerns/authentication.rb"
20
20
template "app/controllers/passwords_controller.rb"
21
21
22
+ template "app/channels/application_cable/connection.rb" unless options . skip_action_cable?
23
+
22
24
template "app/mailers/passwords_mailer.rb"
23
25
24
26
template "app/views/passwords_mailer/reset.html.erb"
Original file line number Diff line number Diff line change
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ identified_by :current_user
4
+
5
+ def connect
6
+ set_current_user || reject_unauthorized_connection
7
+ end
8
+
9
+ private
10
+ def set_current_user
11
+ if session = Session.find_by(id: cookies.signed[:session_id])
12
+ self.current_user = session.user
13
+ end
14
+ end
15
+ end
16
+ end
17
+
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ def test_authentication_generator
30
30
assert_file "app/controllers/sessions_controller.rb"
31
31
assert_file "app/controllers/concerns/authentication.rb"
32
32
assert_file "app/views/sessions/new.html.erb"
33
+ assert_file "app/channels/application_cable/connection.rb"
33
34
34
35
assert_file "app/controllers/application_controller.rb" do |content |
35
36
class_line , includes_line = content . lines . first ( 2 )
@@ -106,6 +107,14 @@ def test_model_test_is_skipped_if_test_framework_is_given
106
107
assert_no_file "test/models/user_test.rb"
107
108
end
108
109
110
+ def test_connection_class_skipped_without_action_cable
111
+ generator ( [ destination_root ] , skip_action_cable : true )
112
+
113
+ run_generator_instance
114
+
115
+ assert_no_file "app/channels/application_cable/connection.rb"
116
+ end
117
+
109
118
private
110
119
def run_generator_instance
111
120
commands = [ ]
You can’t perform that action at this time.
0 commit comments