mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #33559 from anniecodes/dev-task
Move `dev:cache` rake task to use Rails::Command
This commit is contained in:
commit
efaa7191f2
5 changed files with 114 additions and 16 deletions
|
@ -1,3 +1,7 @@
|
|||
* Deprecate `rake dev:cache` in favor of `rails dev:cache`.
|
||||
|
||||
*Annie-Claude Côté*
|
||||
|
||||
* Deprecate `rails notes` subcommands in favor of passing an `annotations` argument to `rails notes`.
|
||||
|
||||
The following subcommands are replaced by passing `--annotations` or `-a` to `rails notes`:
|
||||
|
|
14
railties/lib/rails/commands/dev/dev_command.rb
Normal file
14
railties/lib/rails/commands/dev/dev_command.rb
Normal file
|
@ -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
|
|
@ -1,10 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails/dev_caching"
|
||||
require "rails/command"
|
||||
require "active_support/deprecation"
|
||||
|
||||
namespace :dev do
|
||||
desc "Toggle development mode caching on/off"
|
||||
task :cache do
|
||||
Rails::DevCaching.enable_by_file
|
||||
ActiveSupport::Deprecation.warn("Using `bin/rake dev:cache` is deprecated and will be removed in Rails 6.1. Use `bin/rails dev:cache` instead.\n")
|
||||
Rails::Command.invoke "dev:cache"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,32 +17,45 @@ module ApplicationTests
|
|||
|
||||
test "dev:cache creates file and outputs message" do
|
||||
Dir.chdir(app_path) do
|
||||
output = rails("dev:cache")
|
||||
stderr = capture(:stderr) do
|
||||
output = run_rake_dev_cache
|
||||
assert File.exist?("tmp/caching-dev.txt")
|
||||
assert_match(/Development mode is now being cached/, output)
|
||||
end
|
||||
assert_match(/DEPRECATION WARNING: Using `bin\/rake dev:cache` is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
end
|
||||
end
|
||||
|
||||
test "dev:cache deletes file and outputs message" do
|
||||
Dir.chdir(app_path) do
|
||||
rails "dev:cache" # Create caching file.
|
||||
output = rails("dev:cache") # Delete caching file.
|
||||
stderr = capture(:stderr) do
|
||||
run_rake_dev_cache # Create caching file.
|
||||
output = run_rake_dev_cache # Delete caching file.
|
||||
assert_not File.exist?("tmp/caching-dev.txt")
|
||||
assert_match(/Development mode is no longer being cached/, output)
|
||||
end
|
||||
assert_match(/DEPRECATION WARNING: Using `bin\/rake dev:cache` is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
end
|
||||
end
|
||||
|
||||
test "dev:cache touches tmp/restart.txt" do
|
||||
Dir.chdir(app_path) do
|
||||
rails "dev:cache"
|
||||
stderr = capture(:stderr) do
|
||||
run_rake_dev_cache
|
||||
assert File.exist?("tmp/restart.txt")
|
||||
|
||||
prev_mtime = File.mtime("tmp/restart.txt")
|
||||
sleep(1)
|
||||
rails "dev:cache"
|
||||
run_rake_dev_cache
|
||||
curr_mtime = File.mtime("tmp/restart.txt")
|
||||
assert_not_equal prev_mtime, curr_mtime
|
||||
end
|
||||
assert_match(/DEPRECATION WARNING: Using `bin\/rake dev:cache` is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def run_rake_dev_cache
|
||||
`bin/rake dev:cache`
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
65
railties/test/commands/dev_test.rb
Normal file
65
railties/test/commands/dev_test.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue