Use class methods for VersionCheck
All of these methods are stateless, there was no point to have them as instance methods. Mostly this allows us to remove an `allow_any_instance_of` usage.
This commit is contained in:
parent
eafc8e2f48
commit
04a3e48c2a
|
@ -6,8 +6,7 @@ module VersionCheckHelper
|
|||
return unless Gitlab::CurrentSettings.version_check_enabled
|
||||
return if User.single_user&.requires_usage_stats_consent?
|
||||
|
||||
image_url = VersionCheck.new.url
|
||||
image_tag image_url, class: 'js-version-status-badge'
|
||||
image_tag VersionCheck.url, class: 'js-version-status-badge'
|
||||
end
|
||||
|
||||
def link_to_version
|
||||
|
|
|
@ -5,16 +5,17 @@ require "base64"
|
|||
# This class is used to build image URL to
|
||||
# check if it is a new version for update
|
||||
class VersionCheck
|
||||
def data
|
||||
def self.data
|
||||
{ version: Gitlab::VERSION }
|
||||
end
|
||||
|
||||
def url
|
||||
def self.url
|
||||
encoded_data = Base64.urlsafe_encode64(data.to_json)
|
||||
|
||||
"#{host}?gitlab_info=#{encoded_data}"
|
||||
end
|
||||
|
||||
def host
|
||||
def self.host
|
||||
'https://version.gitlab.com/check.svg'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,9 +54,10 @@ describe 'Help Pages' do
|
|||
|
||||
context 'in a production environment with version check enabled', :js do
|
||||
before do
|
||||
allow(Rails.env).to receive(:production?) { true }
|
||||
stub_application_setting(version_check_enabled: true)
|
||||
allow_any_instance_of(VersionCheck).to receive(:url) { '/version-check-url' }
|
||||
|
||||
allow(Rails.env).to receive(:production?).and_return(true)
|
||||
allow(VersionCheck).to receive(:url).and_return('/version-check-url')
|
||||
|
||||
sign_in(create(:user))
|
||||
visit help_path
|
||||
|
|
|
@ -13,21 +13,21 @@ describe VersionCheckHelper do
|
|||
before do
|
||||
allow(Rails.env).to receive(:production?) { true }
|
||||
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:version_check_enabled) { true }
|
||||
allow_any_instance_of(VersionCheck).to receive(:url) { 'https://version.host.com/check.svg?gitlab_info=xxx' }
|
||||
|
||||
@image_tag = helper.version_status_badge
|
||||
allow(VersionCheck).to receive(:url) { 'https://version.host.com/check.svg?gitlab_info=xxx' }
|
||||
end
|
||||
|
||||
it 'should return an image tag' do
|
||||
expect(@image_tag).to match(/^<img/)
|
||||
expect(helper.version_status_badge).to start_with('<img')
|
||||
end
|
||||
|
||||
it 'should have a js prefixed css class' do
|
||||
expect(@image_tag).to match(/class="js-version-status-badge lazy"/)
|
||||
expect(helper.version_status_badge)
|
||||
.to match(/class="js-version-status-badge lazy"/)
|
||||
end
|
||||
|
||||
it 'should have a VersionCheck url as the src' do
|
||||
expect(@image_tag).to match(%r{src="https://version\.host\.com/check\.svg\?gitlab_info=xxx"})
|
||||
expect(helper.version_status_badge)
|
||||
.to include(%{src="https://version.host.com/check.svg?gitlab_info=xxx"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue