[rubygems/rubygems] Store last check even when upgrade is not available and fix test.
https://github.com/rubygems/rubygems/commit/bcffc2b0a5
This commit is contained in:
parent
7ce0f81fbb
commit
de159c5a85
Notes:
git
2022-11-11 08:24:28 +00:00
@ -392,7 +392,7 @@ if you believe they were disclosed to a third party.
|
|||||||
|
|
||||||
# The name of the state file.
|
# The name of the state file.
|
||||||
def state_file_name
|
def state_file_name
|
||||||
@state_file_name || Gem.state_file
|
Gem.state_file
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reads time of last update check from state file
|
# Reads time of last update check from state file
|
||||||
|
@ -53,10 +53,11 @@ Run `gem update --system #{Gem.latest_rubygems_version}` to update your installa
|
|||||||
|
|
||||||
# compare current and latest version, this is the part where
|
# compare current and latest version, this is the part where
|
||||||
# latest rubygems spec is fetched from remote
|
# latest rubygems spec is fetched from remote
|
||||||
if (Gem.rubygems_version < Gem.latest_rubygems_version)
|
(Gem.rubygems_version < Gem.latest_rubygems_version).tap do |eglible|
|
||||||
# store the time of last successful check into state file
|
# store the time of last successful check into state file
|
||||||
Gem.configuration.last_update_check = check_time
|
Gem.configuration.last_update_check = check_time
|
||||||
return true
|
|
||||||
|
return eglible
|
||||||
end
|
end
|
||||||
rescue # don't block install command on any problem
|
rescue # don't block install command on any problem
|
||||||
false
|
false
|
||||||
|
@ -9,6 +9,9 @@ class TestUpdateSuggestion < Gem::TestCase
|
|||||||
|
|
||||||
@cmd = Gem::Command.new "dummy", "dummy"
|
@cmd = Gem::Command.new "dummy", "dummy"
|
||||||
@cmd.extend Gem::UpdateSuggestion
|
@cmd.extend Gem::UpdateSuggestion
|
||||||
|
@start_time = 1_000_000
|
||||||
|
@minute = 60 * 60
|
||||||
|
@week = 7 * 24 * @minute
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_eglible_environment(**params)
|
def with_eglible_environment(**params)
|
||||||
@ -22,12 +25,13 @@ class TestUpdateSuggestion < Gem::TestCase
|
|||||||
rubygems_version: Gem::Version.new("1.2.3"),
|
rubygems_version: Gem::Version.new("1.2.3"),
|
||||||
latest_rubygems_version: Gem::Version.new("2.0.0"),
|
latest_rubygems_version: Gem::Version.new("2.0.0"),
|
||||||
ci: false,
|
ci: false,
|
||||||
|
reset_last_update_check: true,
|
||||||
cmd:
|
cmd:
|
||||||
)
|
)
|
||||||
original_config, Gem.configuration[:prevent_update_suggestion] = Gem.configuration[:prevent_update_suggestion], nil
|
original_config, Gem.configuration[:prevent_update_suggestion] = Gem.configuration[:prevent_update_suggestion], nil
|
||||||
original_env, ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] = ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"], nil
|
original_env, ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] = ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"], nil
|
||||||
original_disable, Gem.disable_system_update_message = Gem.disable_system_update_message, nil
|
original_disable, Gem.disable_system_update_message = Gem.disable_system_update_message, nil
|
||||||
Gem.configuration.last_update_check = 0
|
Gem.configuration.last_update_check = 0 if reset_last_update_check
|
||||||
|
|
||||||
Gem.ui.stub :tty?, tty do
|
Gem.ui.stub :tty?, tty do
|
||||||
Gem.stub :rubygems_version, rubygems_version do
|
Gem.stub :rubygems_version, rubygems_version do
|
||||||
@ -69,6 +73,73 @@ class TestUpdateSuggestion < Gem::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_eglible_for_update_is_not_annoying_when_new_version_is_released
|
||||||
|
current_version = Gem::Version.new("1.2.0")
|
||||||
|
latest_version = current_version
|
||||||
|
|
||||||
|
# checking for first time, it is not eglible since new version
|
||||||
|
# is not released yet and stored
|
||||||
|
with_eglible_environment(cmd: @cmd, rubygems_version: current_version, latest_rubygems_version: latest_version) do
|
||||||
|
Time.stub :now, @start_time do
|
||||||
|
refute @cmd.eglible_for_update?
|
||||||
|
assert_equal Gem.configuration.last_update_check, @start_time
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# checking next week, it is not eglible since new version
|
||||||
|
# is not released yet and timestamp is stored
|
||||||
|
with_eglible_environment(
|
||||||
|
cmd: @cmd,
|
||||||
|
rubygems_version: current_version,
|
||||||
|
latest_rubygems_version: latest_version,
|
||||||
|
reset_last_update_check: false
|
||||||
|
) do
|
||||||
|
Time.stub :now, @start_time + @week do
|
||||||
|
refute @cmd.eglible_for_update?
|
||||||
|
assert_equal Gem.configuration.last_update_check, @start_time + @week
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# pretend new version is released
|
||||||
|
latest_version = Gem::Version.new("1.3.0")
|
||||||
|
|
||||||
|
# checking later same next week, it is not eglible even new version
|
||||||
|
# is released and timestamp is not stored
|
||||||
|
with_eglible_environment(
|
||||||
|
cmd: @cmd,
|
||||||
|
rubygems_version: current_version,
|
||||||
|
latest_rubygems_version: latest_version,
|
||||||
|
reset_last_update_check: false
|
||||||
|
) do
|
||||||
|
Time.stub :now, @start_time + @week + @minute do
|
||||||
|
refute @cmd.eglible_for_update?
|
||||||
|
assert_equal Gem.configuration.last_update_check, @start_time + @week
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_eglible_for_update_is_not_annoying_when_not_upgraded
|
||||||
|
with_eglible_environment(cmd: @cmd) do
|
||||||
|
# checking for first time, it is eglible and stored
|
||||||
|
Time.stub :now, @start_time do
|
||||||
|
assert @cmd.eglible_for_update?
|
||||||
|
assert_equal Gem.configuration.last_update_check, @start_time
|
||||||
|
end
|
||||||
|
|
||||||
|
# checking minute later is not eglible and not stored
|
||||||
|
Time.stub :now, @start_time + @minute do
|
||||||
|
refute @cmd.eglible_for_update?
|
||||||
|
assert_equal Gem.configuration.last_update_check, @start_time
|
||||||
|
end
|
||||||
|
|
||||||
|
# checking week later is eglible again and stored
|
||||||
|
Time.stub :now, @start_time + @week do
|
||||||
|
assert @cmd.eglible_for_update?
|
||||||
|
assert_equal Gem.configuration.last_update_check, @start_time + @week
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_eglible_for_update_prevent_config
|
def test_eglible_for_update_prevent_config
|
||||||
with_eglible_environment(cmd: @cmd) do
|
with_eglible_environment(cmd: @cmd) do
|
||||||
begin
|
begin
|
||||||
@ -121,7 +192,7 @@ class TestUpdateSuggestion < Gem::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_eglible_for_update_unwrittable_config
|
def test_eglible_for_update_unwrittable_config
|
||||||
with_eglible_environment(ci: true, cmd: @cmd) do
|
with_eglible_environment(cmd: @cmd) do
|
||||||
Gem.configuration.stub :state_file_writable?, false do
|
Gem.configuration.stub :state_file_writable?, false do
|
||||||
refute @cmd.eglible_for_update?
|
refute @cmd.eglible_for_update?
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user