FIX: issue 1538. After upgrading and before a new version check request has been made, dashboard might still say that an update is available.

This commit is contained in:
Neil Lalonde
2013-11-04 12:51:01 -05:00
parent 5e69b277ea
commit ede59a4386
10 changed files with 133 additions and 75 deletions

View File

@ -16,75 +16,103 @@ describe DiscourseUpdates do
subject { DiscourseUpdates.check_version.as_json }
context 'a good version check request happened recently' do
context 'and server is up-to-date' do
before { stub_data(Discourse::VERSION::STRING, 0, false, 12.hours.ago) }
context 'version check was done at the current installed version' do
before do
DiscourseUpdates.stubs(:last_installed_version).returns(Discourse::VERSION::STRING)
end
it 'returns all the version fields' do
subject['latest_version'].should == Discourse::VERSION::STRING
subject['missing_versions_count'].should == 0
subject['critical_updates'].should == false
context 'a good version check request happened recently' do
context 'and server is up-to-date' do
before { stub_data(Discourse::VERSION::STRING, 0, false, 12.hours.ago) }
it 'returns all the version fields' do
subject['latest_version'].should == Discourse::VERSION::STRING
subject['missing_versions_count'].should == 0
subject['critical_updates'].should == false
subject['installed_version'].should == Discourse::VERSION::STRING
end
it 'returns the timestamp of the last version check' do
subject['updated_at'].should be_within_one_second_of(12.hours.ago)
end
end
context 'and server is not up-to-date' do
before { stub_data('0.9.0', 2, false, 12.hours.ago) }
it 'returns all the version fields' do
subject['latest_version'].should == '0.9.0'
subject['missing_versions_count'].should == 2
subject['critical_updates'].should == false
subject['installed_version'].should == Discourse::VERSION::STRING
end
it 'returns the timestamp of the last version check' do
subject['updated_at'].should be_within_one_second_of(12.hours.ago)
end
end
end
context 'a version check has never been performed' do
before { stub_data(nil, nil, false, nil) }
it 'returns the installed version' do
subject['installed_version'].should == Discourse::VERSION::STRING
end
it 'returns the timestamp of the last version check' do
subject['updated_at'].should be_within_one_second_of(12.hours.ago)
it 'indicates that version check has not been performed' do
subject.should have_key('updated_at')
subject['updated_at'].should == nil
end
it 'does not return latest version info' do
subject.should_not have_key('latest_version')
subject.should_not have_key('missing_versions_count')
subject.should_not have_key('critical_updates')
end
it 'queues a version check' do
Jobs.expects(:enqueue).with(:version_check, anything)
subject
end
end
context 'and server is not up-to-date' do
before { stub_data('0.9.0', 2, false, 12.hours.ago) }
# These cases should never happen anymore, but keep the specs to be sure
# they're handled in a sane way.
context 'old version check data' do
shared_examples "queue version check and report that version is ok" do
it 'queues a version check' do
Jobs.expects(:enqueue).with(:version_check, anything)
subject
end
it 'returns all the version fields' do
subject['latest_version'].should == '0.9.0'
subject['missing_versions_count'].should == 2
subject['critical_updates'].should == false
subject['installed_version'].should == Discourse::VERSION::STRING
it 'reports 0 missing versions' do
subject['missing_versions_count'].should == 0
end
it 'reports that a version check will be run soon' do
subject['version_check_pending'].should == true
end
end
it 'returns the timestamp of the last version check' do
subject['updated_at'].should be_within_one_second_of(12.hours.ago)
context 'installed is latest' do
before { stub_data(Discourse::VERSION::STRING, 1, false, 8.hours.ago) }
include_examples "queue version check and report that version is ok"
end
context 'installed does not match latest version, but missing_versions_count is 0' do
before { stub_data('0.10.10.123', 0, false, 8.hours.ago) }
include_examples "queue version check and report that version is ok"
end
end
end
context 'a version check has never been performed' do
before { stub_data(nil, nil, false, nil) }
it 'returns the installed version' do
subject['installed_version'].should == Discourse::VERSION::STRING
context 'version check was done at a different installed version' do
before do
DiscourseUpdates.stubs(:last_installed_version).returns('0.9.1')
end
it 'indicates that version check has not been performed' do
subject.should have_key('updated_at')
subject['updated_at'].should == nil
end
it 'does not return latest version info' do
subject.should_not have_key('latest_version')
subject.should_not have_key('missing_versions_count')
subject.should_not have_key('critical_updates')
end
it 'queues a version check' do
Jobs.expects(:enqueue).with(:version_check, anything)
subject
end
end
context 'installed version is newer' do
before { stub_data('0.9.3', 0, false, 28.hours.ago) }
it 'queues a version check' do
Jobs.expects(:enqueue).with(:version_check, anything)
subject
end
end
context 'old version check data' do
context 'installed is latest' do
before { stub_data(Discourse::VERSION::STRING, 1, false, 8.hours.ago) }
shared_examples "when last_installed_version is old" do
it 'queues a version check' do
Jobs.expects(:enqueue).with(:version_check, anything)
subject
@ -93,16 +121,20 @@ describe DiscourseUpdates do
it 'reports 0 missing versions' do
subject['missing_versions_count'].should == 0
end
end
context 'installed is not latest' do
before { stub_data('0.9.1', 0, false, 8.hours.ago) }
it 'queues a version check' do
Jobs.expects(:enqueue).with(:version_check, anything)
subject
it 'reports that a version check will be run soon' do
subject['version_check_pending'].should == true
end
end
end
context 'missing_versions_count is 0' do
before { stub_data('0.9.7', 0, false, 8.hours.ago) }
include_examples "when last_installed_version is old"
end
context 'missing_versions_count is not 0' do
before { stub_data('0.9.7', 1, false, 8.hours.ago) }
include_examples "when last_installed_version is old"
end
end
end