diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/autosave_spec.js | 90 | ||||
-rw-r--r-- | spec/lib/gitlab/static_site_editor/config_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/resource_milestone_event_spec.rb | 17 | ||||
-rw-r--r-- | spec/requests/api/terraform/state_spec.rb | 16 | ||||
-rw-r--r-- | spec/services/issuable/clone/attributes_rewriter_spec.rb | 6 | ||||
-rw-r--r-- | spec/support/unicorn.rb | 27 |
6 files changed, 157 insertions, 11 deletions
diff --git a/spec/frontend/autosave_spec.js b/spec/frontend/autosave_spec.js index 3119477f385..bbdf3c6f91d 100644 --- a/spec/frontend/autosave_spec.js +++ b/spec/frontend/autosave_spec.js @@ -10,6 +10,8 @@ describe('Autosave', () => { const field = $('<textarea></textarea>'); const key = 'key'; const fallbackKey = 'fallbackKey'; + const lockVersionKey = 'lockVersionKey'; + const lockVersion = 1; describe('class constructor', () => { beforeEach(() => { @@ -30,6 +32,13 @@ describe('Autosave', () => { expect(AccessorUtilities.isLocalStorageAccessSafe).toHaveBeenCalled(); expect(autosave.isLocalStorageAvailable).toBe(true); }); + + it('should set .isLocalStorageAvailable if lockVersion is passed', () => { + autosave = new Autosave(field, key, null, lockVersion); + + expect(AccessorUtilities.isLocalStorageAccessSafe).toHaveBeenCalled(); + expect(autosave.isLocalStorageAvailable).toBe(true); + }); }); describe('restore', () => { @@ -96,6 +105,40 @@ describe('Autosave', () => { }); }); + describe('getSavedLockVersion', () => { + beforeEach(() => { + autosave = { + field, + key, + lockVersionKey, + }; + }); + + describe('if .isLocalStorageAvailable is `false`', () => { + beforeEach(() => { + autosave.isLocalStorageAvailable = false; + + Autosave.prototype.getSavedLockVersion.call(autosave); + }); + + it('should not call .getItem', () => { + expect(window.localStorage.getItem).not.toHaveBeenCalled(); + }); + }); + + describe('if .isLocalStorageAvailable is `true`', () => { + beforeEach(() => { + autosave.isLocalStorageAvailable = true; + }); + + it('should call .getItem', () => { + Autosave.prototype.getSavedLockVersion.call(autosave); + + expect(window.localStorage.getItem).toHaveBeenCalledWith(lockVersionKey); + }); + }); + }); + describe('save', () => { beforeEach(() => { autosave = { reset: jest.fn() }; @@ -128,10 +171,51 @@ describe('Autosave', () => { }); }); + describe('save with lockVersion', () => { + beforeEach(() => { + autosave = { + field, + key, + lockVersionKey, + lockVersion, + isLocalStorageAvailable: true, + }; + }); + + describe('lockVersion is valid', () => { + it('should call .setItem', () => { + Autosave.prototype.save.call(autosave); + expect(window.localStorage.setItem).toHaveBeenCalledWith(lockVersionKey, lockVersion); + }); + + it('should call .setItem when version is 0', () => { + autosave.lockVersion = 0; + Autosave.prototype.save.call(autosave); + expect(window.localStorage.setItem).toHaveBeenCalledWith( + lockVersionKey, + autosave.lockVersion, + ); + }); + }); + + describe('lockVersion is invalid', () => { + it('should not call .setItem with lockVersion', () => { + delete autosave.lockVersion; + Autosave.prototype.save.call(autosave); + + expect(window.localStorage.setItem).not.toHaveBeenCalledWith( + lockVersionKey, + autosave.lockVersion, + ); + }); + }); + }); + describe('reset', () => { beforeEach(() => { autosave = { key, + lockVersionKey, }; }); @@ -156,6 +240,7 @@ describe('Autosave', () => { it('should call .removeItem', () => { expect(window.localStorage.removeItem).toHaveBeenCalledWith(key); + expect(window.localStorage.removeItem).toHaveBeenCalledWith(lockVersionKey); }); }); }); @@ -166,8 +251,8 @@ describe('Autosave', () => { field, key, fallbackKey, + isLocalStorageAvailable: true, }; - autosave.isLocalStorageAvailable = true; }); it('should call .getItem', () => { @@ -185,7 +270,8 @@ describe('Autosave', () => { it('should call .removeItem for key and fallbackKey', () => { Autosave.prototype.reset.call(autosave); - expect(window.localStorage.removeItem).toHaveBeenCalledTimes(2); + expect(window.localStorage.removeItem).toHaveBeenCalledWith(fallbackKey); + expect(window.localStorage.removeItem).toHaveBeenCalledWith(key); }); }); }); diff --git a/spec/lib/gitlab/static_site_editor/config_spec.rb b/spec/lib/gitlab/static_site_editor/config_spec.rb index 8f61476722d..b32af912ad9 100644 --- a/spec/lib/gitlab/static_site_editor/config_spec.rb +++ b/spec/lib/gitlab/static_site_editor/config_spec.rb @@ -24,38 +24,38 @@ describe Gitlab::StaticSiteEditor::Config do project: 'project', project_id: project.id, return_url: 'http://example.com', - is_supported_content: true + is_supported_content: 'true' ) end context 'when branch is not master' do let(:ref) { 'my-branch' } - it { is_expected.to include(is_supported_content: false) } + it { is_expected.to include(is_supported_content: 'false') } end context 'when file does not have a markdown extension' do let(:file_path) { 'README.txt' } - it { is_expected.to include(is_supported_content: false) } + it { is_expected.to include(is_supported_content: 'false') } end context 'when file does not have an extension' do let(:file_path) { 'README' } - it { is_expected.to include(is_supported_content: false) } + it { is_expected.to include(is_supported_content: 'false') } end context 'when file does not exist' do let(:file_path) { 'UNKNOWN.md' } - it { is_expected.to include(is_supported_content: false) } + it { is_expected.to include(is_supported_content: 'false') } end context 'when repository is empty' do let(:project) { create(:project_empty_repo) } - it { is_expected.to include(is_supported_content: false) } + it { is_expected.to include(is_supported_content: 'false') } end end end diff --git a/spec/models/resource_milestone_event_spec.rb b/spec/models/resource_milestone_event_spec.rb index bf8672f95c9..3f8d8b4c1df 100644 --- a/spec/models/resource_milestone_event_spec.rb +++ b/spec/models/resource_milestone_event_spec.rb @@ -78,4 +78,21 @@ describe ResourceMilestoneEvent, type: :model do let(:query_method) { :remove? } end end + + describe '#milestone_title' do + let(:milestone) { create(:milestone, title: 'v2.3') } + let(:event) { create(:resource_milestone_event, milestone: milestone) } + + it 'returns the expected title' do + expect(event.milestone_title).to eq('v2.3') + end + + context 'when milestone is nil' do + let(:event) { create(:resource_milestone_event, milestone: nil) } + + it 'returns nil' do + expect(event.milestone_title).to be_nil + end + end + end end diff --git a/spec/requests/api/terraform/state_spec.rb b/spec/requests/api/terraform/state_spec.rb index 88c277f4e08..844cd948411 100644 --- a/spec/requests/api/terraform/state_spec.rb +++ b/spec/requests/api/terraform/state_spec.rb @@ -78,6 +78,14 @@ describe API::Terraform::State do expect(response).to have_gitlab_http_status(:ok) end + + context 'on Unicorn', :unicorn do + it 'updates the state' do + expect { request }.to change { Terraform::State.count }.by(0) + + expect(response).to have_gitlab_http_status(:ok) + end + end end context 'without body' do @@ -112,6 +120,14 @@ describe API::Terraform::State do expect(response).to have_gitlab_http_status(:ok) end + + context 'on Unicorn', :unicorn do + it 'creates a new state' do + expect { request }.to change { Terraform::State.count }.by(1) + + expect(response).to have_gitlab_http_status(:ok) + end + end end context 'without body' do diff --git a/spec/services/issuable/clone/attributes_rewriter_spec.rb b/spec/services/issuable/clone/attributes_rewriter_spec.rb index 9111b19d7b7..8cb37917239 100644 --- a/spec/services/issuable/clone/attributes_rewriter_spec.rb +++ b/spec/services/issuable/clone/attributes_rewriter_spec.rb @@ -89,7 +89,7 @@ describe Issuable::Clone::AttributesRewriter do create_event(milestone1_project1) create_event(milestone2_project1) - create_event(milestone1_project1, 'remove') + create_event(nil, 'remove') create_event(milestone3_project1) end @@ -101,7 +101,7 @@ describe Issuable::Clone::AttributesRewriter do expect_milestone_event(new_issue_milestone_events.first, milestone: milestone1_project2, action: 'add', state: 'opened') expect_milestone_event(new_issue_milestone_events.second, milestone: milestone2_project2, action: 'add', state: 'opened') - expect_milestone_event(new_issue_milestone_events.third, milestone: milestone1_project2, action: 'remove', state: 'opened') + expect_milestone_event(new_issue_milestone_events.third, milestone: nil, action: 'remove', state: 'opened') end def create_event(milestone, action = 'add') @@ -109,7 +109,7 @@ describe Issuable::Clone::AttributesRewriter do end def expect_milestone_event(event, expected_attrs) - expect(event.milestone_id).to eq(expected_attrs[:milestone].id) + expect(event.milestone_id).to eq(expected_attrs[:milestone]&.id) expect(event.action).to eq(expected_attrs[:action]) expect(event.state).to eq(expected_attrs[:state]) end diff --git a/spec/support/unicorn.rb b/spec/support/unicorn.rb new file mode 100644 index 00000000000..0b01fc9e26c --- /dev/null +++ b/spec/support/unicorn.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +REQUEST_CLASSES = [ + ::Grape::Request, + ::Rack::Request +].freeze + +def request_body_class + return ::Unicorn::TeeInput if defined?(::Unicorn) + + Class.new(StringIO) do + def string + raise NotImplementedError, '#string is only valid under Puma which uses StringIO, use #read instead' + end + end +end + +RSpec.configure do |config| + config.before(:each, :unicorn) do + REQUEST_CLASSES.each do |request_class| + allow_any_instance_of(request_class) + .to receive(:body).and_wrap_original do |m, *args| + request_body_class.new(m.call(*args).read) + end + end + end +end |