diff options
author | Annie-Claude Côté <hello@annie.codes> | 2018-08-08 13:28:37 -0400 |
---|---|---|
committer | Annie-Claude Côté <hello@annie.codes> | 2018-08-13 11:27:01 -0400 |
commit | 3e6d03d99e47e3b567e7409d8def3feea36a0c47 (patch) | |
tree | 390be79a750d985d68cca4343940a750199bad62 | |
parent | 7db360acb2efa64af5fbfb82036588cf7a0f20fa (diff) | |
download | rails-3e6d03d99e47e3b567e7409d8def3feea36a0c47.tar.gz rails-3e6d03d99e47e3b567e7409d8def3feea36a0c47.tar.bz2 rails-3e6d03d99e47e3b567e7409d8def3feea36a0c47.zip |
Adds Rails:Command for `dev:cache` that has the same behaviour as the rake task
-rw-r--r-- | railties/lib/rails/commands/dev/dev_command.rb | 14 | ||||
-rw-r--r-- | railties/test/commands/dev_test.rb | 65 |
2 files changed, 79 insertions, 0 deletions
diff --git a/railties/lib/rails/commands/dev/dev_command.rb b/railties/lib/rails/commands/dev/dev_command.rb new file mode 100644 index 0000000000..820dc4db9e --- /dev/null +++ b/railties/lib/rails/commands/dev/dev_command.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require "rails/dev_caching" + +module Rails + module Command + class DevCommand < Base # :nodoc: + desc "Toggle development mode caching on/off" + def cache + Rails::DevCaching.enable_by_file + end + end + end +end diff --git a/railties/test/commands/dev_test.rb b/railties/test/commands/dev_test.rb new file mode 100644 index 0000000000..ae8516fe9a --- /dev/null +++ b/railties/test/commands/dev_test.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require "isolation/abstract_unit" +require "rails/command" + +class Rails::Command::DevTest < ActiveSupport::TestCase + setup :build_app + teardown :teardown_app + + test "`rails dev:cache` creates both caching and restart file when restart file doesn't exist and dev caching is currently off" do + Dir.chdir(app_path) do + assert_not File.exist?("tmp/caching-dev.txt") + assert_not File.exist?("tmp/restart.txt") + + assert_equal <<~OUTPUT, run_dev_cache_command + Development mode is now being cached. + OUTPUT + + assert File.exist?("tmp/caching-dev.txt") + assert File.exist?("tmp/restart.txt") + end + end + + test "`rails dev:cache` creates caching file and touches restart file when dev caching is currently off" do + Dir.chdir(app_path) do + app_file("tmp/restart.txt", "") + + assert_not File.exist?("tmp/caching-dev.txt") + assert File.exist?("tmp/restart.txt") + restart_file_time_before = File.mtime("tmp/restart.txt") + + assert_equal <<~OUTPUT, run_dev_cache_command + Development mode is now being cached. + OUTPUT + + assert File.exist?("tmp/caching-dev.txt") + restart_file_time_after = File.mtime("tmp/restart.txt") + assert_operator restart_file_time_before, :<, restart_file_time_after + end + end + + test "`rails dev:cache` removes caching file and touches restart file when dev caching is currently on" do + Dir.chdir(app_path) do + app_file("tmp/caching-dev.txt", "") + app_file("tmp/restart.txt", "") + + assert File.exist?("tmp/caching-dev.txt") + assert File.exist?("tmp/restart.txt") + restart_file_time_before = File.mtime("tmp/restart.txt") + + assert_equal <<~OUTPUT, run_dev_cache_command + Development mode is no longer being cached. + OUTPUT + + assert_not File.exist?("tmp/caching-dev.txt") + restart_file_time_after = File.mtime("tmp/restart.txt") + assert_operator restart_file_time_before, :<, restart_file_time_after + end + end + + private + def run_dev_cache_command + rails "dev:cache" + end +end |