Skip to content

Commit

Permalink
Fix crash when displaying prerelease → final version change
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbrictson committed Aug 10, 2024
1 parent 373374c commit 831bd37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/bundle_update_interactive/semver_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ def initialize(old_version, new_version)

@same_segments = new_segments.take_while.with_index { |seg, i| seg == old_segments[i] }
@diff_segments = new_segments[same_segments.length..]

@changed = diff_segments.any? || old_segments.length != new_segments.length
end

def severity
return nil if diff_segments.empty?
return nil unless @changed

SEVERITIES[same_segments.length] || :patch
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "test_helper"

module BundleUpdateInteractive
class SemverTest < Minitest::Test
class SemverChangeTest < Minitest::Test
def test_prerelease_is_considered_patch
change = SemverChange.new("7.2.0.beta2", "7.2.0.beta3")

Expand All @@ -14,6 +14,16 @@ def test_prerelease_is_considered_patch
refute_predicate change, :major?
end

def test_prerelease_to_final_is_considered_patch
change = SemverChange.new("7.2.0.rc1", "7.2.0")

assert_equal :patch, change.severity
assert_predicate change, :patch?

refute_predicate change, :minor?
refute_predicate change, :major?
end

def test_change_in_fourth_segment_is_considered_patch
change = SemverChange.new("7.1.3.3", "7.1.3.4")

Expand Down Expand Up @@ -63,6 +73,12 @@ def test_format_applies_to_all_segments_starting_with_changed_one
assert_equal "2.1.6.<1>", SemverChange.new("2.1.6", "2.1.6.1").format(&formatter)
end

def test_format_doesnt_apply_to_final_release
formatter = ->(str) { "<#{str}>" }

assert_equal "7.2.0", SemverChange.new("7.2.0.rc1", "7.2.0").format(&formatter)
end

def test_none_is_true_when_versions_are_identical
change = SemverChange.new("1.0.3", "1.0.3")

Expand Down

0 comments on commit 831bd37

Please sign in to comment.