diff options
author | Matthew Draper <matthew@trebex.net> | 2016-01-20 16:03:13 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-01-20 16:09:20 +1030 |
commit | 56a9341689942146d350ff931497956a15152bdb (patch) | |
tree | b667657e63aed80d1c04b8fd08223812c5e870e7 /railties | |
parent | 8f208e0f90cafda767005bc1fce63709414e84dd (diff) | |
parent | ae31da20cd250154c951b67d5625fc71ac27e2f1 (diff) | |
download | rails-56a9341689942146d350ff931497956a15152bdb.tar.gz rails-56a9341689942146d350ff931497956a15152bdb.tar.bz2 rails-56a9341689942146d350ff931497956a15152bdb.zip |
Merge pull request #22950 from maclover7/adapterize-storage-actioncable
Adapterize storage for ActionCable
Diffstat (limited to 'railties')
5 files changed, 35 insertions, 12 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 297ccb1dbf..c629459d95 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -117,6 +117,7 @@ module Rails javascript_gemfile_entry, jbuilder_gemfile_entry, psych_gemfile_entry, + cable_gemfile_entry, @extra_entries].flatten.find_all(&@gem_filter) end @@ -339,6 +340,15 @@ module Rails GemfileEntry.new('psych', '~> 2.0', comment, platforms: :rbx) end + def cable_gemfile_entry + return [] if options[:skip_action_cable] + comment = 'Action Cable dependencies for the Redis adapter' + gems = [] + gems << GemfileEntry.new("em-hiredis", '~> 0.3.0', comment) + gems << GemfileEntry.new("redis", '~> 3.0', comment) + gems + end + def bundle_command(command) say_status :run, "bundle #{command}" diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index f4deec7135..7ec4d3bbd3 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -78,11 +78,11 @@ module Rails template "application.rb" template "environment.rb" template "secrets.yml" + template "cable.yml" unless options[:skip_action_cable] directory "environments" directory "initializers" directory "locales" - directory "redis" unless options[:skip_action_cable] end end @@ -315,7 +315,7 @@ module Rails def delete_action_cable_files_skipping_action_cable if options[:skip_action_cable] - remove_file 'config/redis/cable.yml' + remove_file 'config/cable.yml' remove_file 'app/assets/javascripts/cable.coffee' remove_dir 'app/channels' end diff --git a/railties/lib/rails/generators/rails/app/templates/config/cable.yml b/railties/lib/rails/generators/rails/app/templates/config/cable.yml new file mode 100644 index 0000000000..004adb7b3c --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/cable.yml @@ -0,0 +1,12 @@ +# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket. +production: + adapter: redis + url: redis://localhost:6379/1 + +development: + adapter: redis + url: redis://localhost:6379/2 + +test: + adapter: redis + url: redis://localhost:6379/3 diff --git a/railties/lib/rails/generators/rails/app/templates/config/redis/cable.yml b/railties/lib/rails/generators/rails/app/templates/config/redis/cable.yml deleted file mode 100644 index 0176be24f9..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/config/redis/cable.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Action Cable uses Redis to administer connections, channels, and sending/receiving messages over the WebSocket. -production: - url: redis://localhost:6379/1 - -development: - url: redis://localhost:6379/2 - -test: - url: redis://localhost:6379/3 diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index e5480180ce..c0f7e58b59 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -392,9 +392,19 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_skip_action_cable_is_given run_generator [destination_root, "--skip-action-cable"] assert_file "config/application.rb", /#\s+require\s+["']action_cable\/engine["']/ - assert_no_file "config/redis/cable.yml" + assert_no_file "config/cable.yml" assert_no_file "app/assets/javascripts/cable.coffee" assert_no_file "app/channels" + assert_file "Gemfile" do |content| + assert_no_match(/em-hiredis/, content) + assert_no_match(/redis/, content) + end + end + + def test_action_cable_redis_gems + run_generator + assert_gem 'em-hiredis' + assert_gem 'redis' end def test_inclusion_of_javascript_runtime |