File tree Expand file tree Collapse file tree 2 files changed +35
-5
lines changed
lib/shopify_ruby_definitions
test/shopify_ruby_definitions Expand file tree Collapse file tree 2 files changed +35
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
module ShopifyRubyDefinitions
4
4
module RubyVersions
5
+ class << self
6
+ def build_version_overrides ( all_versions )
7
+ all_versions . sort_by do |version |
8
+ version . scan ( /\d +/ ) . map ( &:to_i )
9
+ end . to_h do |version |
10
+ [ version . partition ( "-pshopify" ) . first , version ]
11
+ end . freeze
12
+ end
13
+ end
14
+
5
15
VERSIONS_DIRECTORY = File . expand_path ( "../../../rubies" , __FILE__ )
6
16
ALL_VERSIONS = Dir [ "#{ VERSIONS_DIRECTORY } /*" ] . map { |f | File . basename ( f ) }
7
- VERSION_OVERRIDES = ALL_VERSIONS . sort_by do |version |
8
- version . scan ( /\d +/ ) . map ( &:to_i )
9
- end . to_h do |version |
10
- [ version . split ( "-" ) . first , version ]
11
- end . freeze
17
+ VERSION_OVERRIDES = build_version_overrides ( ALL_VERSIONS )
12
18
13
19
def version_overrides
14
20
VERSION_OVERRIDES
Original file line number Diff line number Diff line change @@ -20,5 +20,29 @@ def test_version_overrides
20
20
def test_resolve_version
21
21
assert_equal ( "3.0.2-pshopify3" , ShopifyRubyDefinitions . resolve_version ( "3.0" ) )
22
22
end
23
+
24
+ def test_resolve_preview_version
25
+ with_versions ( [ "3.3.0-preview2-pshopify1" , "3.3.0-pshopify1" ] ) do
26
+ assert_equal ( "3.3.0-preview2-pshopify1" , ShopifyRubyDefinitions . resolve_version ( "3.3.0-preview2" ) )
27
+ assert_equal ( "3.3.0-pshopify1" , ShopifyRubyDefinitions . resolve_version ( "3.3" ) )
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def with_versions ( new_versions )
34
+ old_versions = RubyVersions ::ALL_VERSIONS
35
+ old_version_overrides = RubyVersions ::VERSION_OVERRIDES
36
+ RubyVersions . send ( :remove_const , :ALL_VERSIONS )
37
+ RubyVersions . const_set ( :ALL_VERSIONS , new_versions )
38
+ RubyVersions . send ( :remove_const , :VERSION_OVERRIDES )
39
+ RubyVersions . const_set ( :VERSION_OVERRIDES , RubyVersions . build_version_overrides ( new_versions ) )
40
+ yield
41
+ ensure
42
+ RubyVersions . send ( :remove_const , :ALL_VERSIONS )
43
+ RubyVersions . const_set ( :ALL_VERSIONS , old_versions )
44
+ RubyVersions . send ( :remove_const , :VERSION_OVERRIDES )
45
+ RubyVersions . const_set ( :VERSION_OVERRIDES , old_version_overrides )
46
+ end
23
47
end
24
48
end
You can’t perform that action at this time.
0 commit comments