mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Generate cable.js
file if does not exist when generating channel
- Before this, while generating a channel, we were not creating
`cable.js` if it does not already exist.
- We have similar code for application mailer here -
0b3ae023d2
.
- Based on the comment -
https://github.com/rails/rails/issues/24418#issuecomment-205421995.
This commit is contained in:
parent
db9bc80973
commit
d0023deb74
3 changed files with 22 additions and 0 deletions
|
@ -13,6 +13,7 @@ module Rails
|
|||
template "channel.rb", File.join('app/channels', class_path, "#{file_name}_channel.rb")
|
||||
|
||||
if options[:assets]
|
||||
template "assets/cable.js", "app/assets/javascripts/cable.js"
|
||||
template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee")
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// Action Cable provides the framework to deal with WebSockets in Rails.
|
||||
// You can generate new channels where WebSocket features live using the rails generate channel command.
|
||||
//
|
||||
//= require action_cable
|
||||
//= require_self
|
||||
//= require_tree ./channels
|
||||
|
||||
(function() {
|
||||
this.App || (this.App = {});
|
||||
|
||||
App.cable = ActionCable.createConsumer();
|
||||
|
||||
}).call(this);
|
|
@ -38,4 +38,12 @@ class ChannelGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
assert_no_file "app/assets/javascripts/channels/chat.coffee"
|
||||
end
|
||||
|
||||
def test_cable_js_is_created_if_not_present_already
|
||||
run_generator ['chat']
|
||||
FileUtils.rm("#{destination_root}/app/assets/javascripts/cable.js")
|
||||
run_generator ['camp']
|
||||
|
||||
assert_file "app/assets/javascripts/cable.js"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue