aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHyonjee Joo <hj2339@columbia.edu>2015-02-17 01:11:16 -0500
committerHyonjee Joo <hj2339@columbia.edu>2015-02-26 15:26:59 -0500
commitb181297ad7f60c6006292ab024ed08a490bdb4f8 (patch)
tree30d6b3622d147ccbaaa2dbf33f04249d73db133e
parent38218929e9b3205a2a731660b3c5527937e1c015 (diff)
downloadrails-b181297ad7f60c6006292ab024ed08a490bdb4f8.tar.gz
rails-b181297ad7f60c6006292ab024ed08a490bdb4f8.tar.bz2
rails-b181297ad7f60c6006292ab024ed08a490bdb4f8.zip
Created rake restart task.
Fixes #18876. Rake restart touches `tmp/restart.txt` to restart application on next request. Updated tests and documentation accordingly.
-rw-r--r--railties/CHANGELOG.md7
-rw-r--r--railties/lib/rails/tasks.rb1
-rw-r--r--railties/lib/rails/tasks/restart.rake4
-rw-r--r--railties/test/application/rake/restart_test.rb31
4 files changed, 43 insertions, 0 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 8306233dcd..8b10144413 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Created rake restart task. Restarts your Rails app by touching the
+ `tmp/restart.txt`.
+
+ Fixes #18876.
+
+ *Hyonjee Joo*
+
* Set Rails console to use log formatter and log level as specified for the
given environment.
diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb
index 945fbdb3e2..a5e4d2935e 100644
--- a/railties/lib/rails/tasks.rb
+++ b/railties/lib/rails/tasks.rb
@@ -7,6 +7,7 @@ require 'rake'
log
middleware
misc
+ restart
routes
statistics
tmp
diff --git a/railties/lib/rails/tasks/restart.rake b/railties/lib/rails/tasks/restart.rake
new file mode 100644
index 0000000000..1af0302824
--- /dev/null
+++ b/railties/lib/rails/tasks/restart.rake
@@ -0,0 +1,4 @@
+desc "Restart app by touching tmp/restart.txt"
+task restart: :environment do
+ FileUtils.touch('tmp/restart.txt')
+end
diff --git a/railties/test/application/rake/restart_test.rb b/railties/test/application/rake/restart_test.rb
new file mode 100644
index 0000000000..35099913fb
--- /dev/null
+++ b/railties/test/application/rake/restart_test.rb
@@ -0,0 +1,31 @@
+require "isolation/abstract_unit"
+
+module ApplicationTests
+ module RakeTests
+ class RakeRestartTest < ActiveSupport::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+ end
+
+ def teardown
+ teardown_app
+ end
+
+ test 'rake restart touches tmp/restart.txt' do
+ Dir.chdir(app_path) do
+ `rake restart`
+ assert File.exist?("tmp/restart.txt")
+
+ prev_mtime = File.mtime("tmp/restart.txt")
+ sleep(1)
+ `rake restart`
+ curr_mtime = File.mtime("tmp/restart.txt")
+ assert_not_equal prev_mtime, curr_mtime
+ end
+ end
+ end
+ end
+end