File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change
1
+ ## Next Version
2
+
3
+ * Accept -e and --environment options for ` rails console ` .
4
+
1
5
## 1.1.3
2
6
3
7
* The ` rails runner ` command no longer passes environment switches to
Original file line number Diff line number Diff line change @@ -13,7 +13,19 @@ def description
13
13
14
14
class RailsConsole < Rails
15
15
def env ( args )
16
- args . first if args . first && !args . first . index ( "-" )
16
+ return args . first if args . first && !args . first . index ( "-" )
17
+
18
+ environment = nil
19
+
20
+ args . each . with_index do |arg , i |
21
+ if arg =~ /--environment=(\w +)/
22
+ environment = $1
23
+ elsif i > 0 && args [ i - 1 ] == "-e"
24
+ environment = arg
25
+ end
26
+ end
27
+
28
+ environment
17
29
end
18
30
19
31
def command_name
Original file line number Diff line number Diff line change @@ -7,7 +7,17 @@ class CommandsTest < ActiveSupport::TestCase
7
7
assert_equal 'test' , command . env ( [ 'test' ] )
8
8
end
9
9
10
- test 'console command ignores first argument if it is a flag' do
10
+ test 'console command sets rails environment from -e option' do
11
+ command = Spring ::Commands ::RailsConsole . new
12
+ assert_equal 'test' , command . env ( [ '-e' , 'test' ] )
13
+ end
14
+
15
+ test 'console command sets rails environment from --environment option' do
16
+ command = Spring ::Commands ::RailsConsole . new
17
+ assert_equal 'test' , command . env ( [ '--environment=test' ] )
18
+ end
19
+
20
+ test 'console command ignores first argument if it is a flag except -e and --environment' do
11
21
command = Spring ::Commands ::RailsConsole . new
12
22
assert_nil command . env ( [ '--sandbox' ] )
13
23
end
You can’t perform that action at this time.
0 commit comments