Skip to content

Commit 4377f08

Browse files
committed
Implement the bin/rails boot command
1 parent 4a45f31 commit 4377f08

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

guides/source/command_line.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ The `tmp:` namespaced commands will help you clear and create the `Rails.root/tm
668668
* `bin/rails stats` is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio.
669669
* `bin/rails secret` will give you a pseudo-random key to use for your session secret.
670670
* `bin/rails time:zones:all` lists all the timezones Rails knows about.
671+
* `bin/rails boot` boots the application and exits.
671672
672673
### Custom Rake Tasks
673674

railties/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* The new `bin/rails boot` command boots the application and exits. Supports the
2+
standard `-e/--environment` options.
3+
4+
*Xavier Noria*
5+
16
* Generate form helpers to use `textarea*` methods instead of `text_area*` methods
27

38
*Sean Doyle*
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "rails/command/environment_argument"
4+
5+
module Rails
6+
module Command
7+
class BootCommand < Base # :nodoc:
8+
include EnvironmentArgument
9+
10+
desc "boot", "Boot the application and exit"
11+
def perform(*) = boot_application!
12+
end
13+
end
14+
end

railties/test/commands/boot_test.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
require "isolation/abstract_unit"
4+
require "rails/command"
5+
require "rails/commands/boot/boot_command"
6+
7+
class Rails::Command::BootTest < ActiveSupport::TestCase
8+
include ActiveSupport::Testing::Isolation
9+
10+
setup :build_app
11+
teardown :teardown_app
12+
13+
test "boots the application" do
14+
test_file = "#{app_path}/tmp/test_file"
15+
16+
app_file "config/initializers/write_test_file.rb", <<-RUBY
17+
File.write(#{test_file.inspect}, Rails.env)
18+
RUBY
19+
20+
rails "boot"
21+
22+
assert_equal "development", File.read(test_file)
23+
end
24+
25+
test "optionally accepts an environment" do
26+
test_file = "#{app_path}/tmp/test_file"
27+
28+
app_file "config/initializers/write_test_file.rb", <<-RUBY
29+
File.write(#{test_file.inspect}, Rails.env)
30+
RUBY
31+
32+
rails "boot", "-e", "test"
33+
34+
assert_equal "test", File.read(test_file)
35+
end
36+
end

0 commit comments

Comments
 (0)