File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ * Add ` Rails.env.local? ` shorthand for ` Rails.env.development? || Rails.env.test? ` .
2
+
3
+ * DHH*
4
+
1
5
* ` ActiveSupport::Testing::TimeHelpers ` now accepts named ` with_usec ` argument
2
6
to ` freeze_time ` , ` travel ` , and ` travel_to ` methods. Passing true prevents
3
7
truncating the destination time with ` change(usec: 0) ` .
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require "active_support/string_inquirer"
4
+ require "active_support/core_ext/object/inclusion"
4
5
5
6
module ActiveSupport
6
7
class EnvironmentInquirer < StringInquirer # :nodoc:
7
8
# Optimization for the three default environments, so this inquirer doesn't need to rely on
8
9
# the slower delegation through method_missing that StringInquirer would normally entail.
9
10
DEFAULT_ENVIRONMENTS = %w[ development test production ]
11
+
12
+ # Environments that'll respond true for #local?
13
+ LOCAL_ENVIRONMENTS = %w[ development test ]
14
+
10
15
def initialize ( env )
16
+ raise ( ArgumentError , "'local' is a reserved environment name" ) if env == "local"
17
+
11
18
super ( env )
12
19
13
20
DEFAULT_ENVIRONMENTS . each do |default |
@@ -18,5 +25,10 @@ def initialize(env)
18
25
DEFAULT_ENVIRONMENTS . each do |env |
19
26
class_eval "def #{ env } ?; @#{ env } ; end"
20
27
end
28
+
29
+ # Returns true if we're in the development or test environment.
30
+ def local?
31
+ in? LOCAL_ENVIRONMENTS
32
+ end
21
33
end
22
34
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "abstract_unit"
4
+
5
+ class EnvironmentInquirerTest < ActiveSupport ::TestCase
6
+ test "local predicate" do
7
+ assert ActiveSupport ::EnvironmentInquirer . new ( "development" ) . local?
8
+ assert ActiveSupport ::EnvironmentInquirer . new ( "test" ) . local?
9
+ assert_not ActiveSupport ::EnvironmentInquirer . new ( "production" ) . local?
10
+ end
11
+
12
+ test "prevent local from being used as an actual environment name" do
13
+ assert_raises ( ArgumentError ) do
14
+ ActiveSupport ::EnvironmentInquirer . new ( "local" )
15
+ end
16
+ end
17
+ end
You can’t perform that action at this time.
0 commit comments