diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-03 21:08:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-03 21:08:46 +0300 |
commit | 63a015fd85ae35634eb882d0078e65d80300816c (patch) | |
tree | 317928bc138d54e28980962e813004876398a7ac /spec | |
parent | 55693cc1ec8ac79444bc7214d2812a4ac41bf043 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/ide/components/jobs/__snapshots__/stage_spec.js.snap | 4 | ||||
-rw-r--r-- | spec/frontend/ide/mock_data.js | 6 | ||||
-rw-r--r-- | spec/graphql/types/snippets/blob_type_spec.rb | 3 | ||||
-rw-r--r-- | spec/javascripts/ide/components/new_dropdown/upload_spec.js | 41 | ||||
-rw-r--r-- | spec/javascripts/vue_shared/components/content_viewer/content_viewer_spec.js | 28 | ||||
-rw-r--r-- | spec/lib/gitlab/repository_cache_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 97 | ||||
-rw-r--r-- | spec/requests/api/branches_spec.rb | 2 |
8 files changed, 169 insertions, 24 deletions
diff --git a/spec/frontend/ide/components/jobs/__snapshots__/stage_spec.js.snap b/spec/frontend/ide/components/jobs/__snapshots__/stage_spec.js.snap index 43e606eac6e..db5175c3f7b 100644 --- a/spec/frontend/ide/components/jobs/__snapshots__/stage_spec.js.snap +++ b/spec/frontend/ide/components/jobs/__snapshots__/stage_spec.js.snap @@ -14,7 +14,7 @@ exports[`IDE pipeline stage renders stage details & icon 1`] = ` /> <strong - class="prepend-left-8 ide-stage-title" + class="prepend-left-8 text-truncate" data-container="body" data-original-title="" title="" @@ -42,7 +42,7 @@ exports[`IDE pipeline stage renders stage details & icon 1`] = ` </div> <div - class="card-body" + class="card-body p-0" > <item-stub job="[object Object]" diff --git a/spec/frontend/ide/mock_data.js b/spec/frontend/ide/mock_data.js index 80eb15fe5a6..a1b57dca6bc 100644 --- a/spec/frontend/ide/mock_data.js +++ b/spec/frontend/ide/mock_data.js @@ -165,7 +165,11 @@ export const mergeRequests = [ iid: 1, title: 'Test merge request', project_id: 1, - web_url: `${TEST_HOST}/namespace/project-path/merge_requests/1`, + web_url: `${TEST_HOST}/namespace/project-path/-/merge_requests/1`, + references: { + short: '!1', + full: 'namespace/project-path!1', + }, }, ]; diff --git a/spec/graphql/types/snippets/blob_type_spec.rb b/spec/graphql/types/snippets/blob_type_spec.rb index f1837538b53..e7d4e5dfa2d 100644 --- a/spec/graphql/types/snippets/blob_type_spec.rb +++ b/spec/graphql/types/snippets/blob_type_spec.rb @@ -6,7 +6,8 @@ describe GitlabSchema.types['SnippetBlob'] do it 'has the correct fields' do expected_fields = [:highlighted_data, :raw_path, :size, :binary, :name, :path, - :simple_viewer, :rich_viewer] + :simple_viewer, :rich_viewer, + :mode] is_expected.to have_graphql_fields(*expected_fields) end diff --git a/spec/javascripts/ide/components/new_dropdown/upload_spec.js b/spec/javascripts/ide/components/new_dropdown/upload_spec.js index 4ebd0977832..66ddf6c0ee6 100644 --- a/spec/javascripts/ide/components/new_dropdown/upload_spec.js +++ b/spec/javascripts/ide/components/new_dropdown/upload_spec.js @@ -14,7 +14,7 @@ describe('new dropdown upload', () => { vm.entryName = 'testing'; - spyOn(vm, '$emit'); + spyOn(vm, '$emit').and.callThrough(); }); afterEach(() => { @@ -61,31 +61,44 @@ describe('new dropdown upload', () => { const binaryTarget = { result: 'base64,w4I=', }; - const textFile = { - name: 'textFile', - type: 'text/plain', - }; + const textFile = new File(['plain text'], 'textFile'); + const binaryFile = { name: 'binaryFile', type: 'image/png', }; - it('creates file in plain text (without encoding) if the file content is plain text', () => { + beforeEach(() => { + spyOn(FileReader.prototype, 'readAsText').and.callThrough(); + }); + + it('calls readAsText and creates file in plain text (without encoding) if the file content is plain text', done => { + const waitForCreate = new Promise(resolve => vm.$on('create', resolve)); + vm.createFile(textTarget, textFile); - expect(vm.$emit).toHaveBeenCalledWith('create', { - name: textFile.name, - type: 'blob', - content: 'plain text', - base64: false, - binary: false, - rawPath: '', - }); + expect(FileReader.prototype.readAsText).toHaveBeenCalledWith(textFile); + + waitForCreate + .then(() => { + expect(vm.$emit).toHaveBeenCalledWith('create', { + name: textFile.name, + type: 'blob', + content: 'plain text', + base64: false, + binary: false, + rawPath: '', + }); + }) + .then(done) + .catch(done.fail); }); it('splits content on base64 if binary', () => { vm.createFile(binaryTarget, binaryFile); + expect(FileReader.prototype.readAsText).not.toHaveBeenCalledWith(textFile); + expect(vm.$emit).toHaveBeenCalledWith('create', { name: binaryFile.name, type: 'blob', diff --git a/spec/javascripts/vue_shared/components/content_viewer/content_viewer_spec.js b/spec/javascripts/vue_shared/components/content_viewer/content_viewer_spec.js index e3f6609f128..e2a1ed931f1 100644 --- a/spec/javascripts/vue_shared/components/content_viewer/content_viewer_spec.js +++ b/spec/javascripts/vue_shared/components/content_viewer/content_viewer_spec.js @@ -58,14 +58,34 @@ describe('ContentViewer', () => { it('renders fallback download control', done => { createComponent({ - path: 'test.abc', + path: 'somepath/test.abc', fileSize: 1024, }); setTimeout(() => { - expect(vm.$el.querySelector('.file-info').textContent.trim()).toContain('test.abc'); - expect(vm.$el.querySelector('.file-info').textContent.trim()).toContain('(1.00 KiB)'); - expect(vm.$el.querySelector('.btn.btn-default').textContent.trim()).toContain('Download'); + expect( + vm.$el + .querySelector('.file-info') + .textContent.trim() + .replace(/\s+/, ' '), + ).toEqual('test.abc (1.00 KiB)'); + + expect(vm.$el.querySelector('.btn.btn-default').textContent.trim()).toEqual('Download'); + + done(); + }); + }); + + it('renders fallback download control for file with a data URL path properly', done => { + createComponent({ + path: 'data:application/octet-stream;base64,U0VMRUNUICfEhHNnc2cnIGZyb20gVGFibGVuYW1lOwoK', + filePath: 'somepath/test.abc', + }); + + setTimeout(() => { + expect(vm.$el.querySelector('.file-info').textContent.trim()).toEqual('test.abc'); + expect(vm.$el.querySelector('.btn.btn-default')).toHaveAttr('download', 'test.abc'); + expect(vm.$el.querySelector('.btn.btn-default').textContent.trim()).toEqual('Download'); done(); }); diff --git a/spec/lib/gitlab/repository_cache_spec.rb b/spec/lib/gitlab/repository_cache_spec.rb index 1b7dd1766da..e787288fc51 100644 --- a/spec/lib/gitlab/repository_cache_spec.rb +++ b/spec/lib/gitlab/repository_cache_spec.rb @@ -50,6 +50,18 @@ describe Gitlab::RepositoryCache do end end + describe '#write' do + it 'writes the given key and value to the cache' do + cache.write(:test, 'test') + expect(backend).to have_received(:write).with("test:#{namespace}", 'test') + end + + it 'passes additional options to the backend' do + cache.write(:test, 'test', expires_in: 10.minutes) + expect(backend).to have_received(:write).with("test:#{namespace}", 'test', expires_in: 10.minutes) + end + end + describe '#fetch_without_caching_false', :use_clean_rails_memory_store_caching do let(:key) { :foo } let(:backend) { Rails.cache } diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 19a45ce5f88..3d28adade05 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -494,6 +494,100 @@ describe Repository do it { is_expected.to eq(commit.sha) } end + describe "#merged_branch_names", :clean_gitlab_redis_cache do + subject { repository.merged_branch_names(branch_names) } + + let(:branch_names) { %w(test beep boop definitely_merged) } + let(:already_merged) { Set.new(["definitely_merged"]) } + + let(:merge_state_hash) do + { + "test" => false, + "beep" => false, + "boop" => false, + "definitely_merged" => true + } + end + + let_it_be(:cache) do + caching_config_hash = Gitlab::Redis::Cache.params + ActiveSupport::Cache.lookup_store(:redis_cache_store, caching_config_hash) + end + + let(:repository_cache) do + Gitlab::RepositoryCache.new(repository, backend: Rails.cache) + end + + let(:cache_key) { repository_cache.cache_key(:merged_branch_names) } + + before do + allow(Rails).to receive(:cache) { cache } + allow(repository).to receive(:cache) { repository_cache } + allow(repository.raw_repository).to receive(:merged_branch_names).with(branch_names).and_return(already_merged) + end + + it { is_expected.to eq(already_merged) } + it { is_expected.to be_a(Set) } + + context "cache is empty" do + before do + cache.delete(cache_key) + end + + it { is_expected.to eq(already_merged) } + + describe "cache values" do + it "writes the values to redis" do + expect(cache).to receive(:write).with(cache_key, merge_state_hash, expires_in: Repository::MERGED_BRANCH_NAMES_CACHE_DURATION) + + subject + end + + it "matches the supplied hash" do + subject + + expect(cache.read(cache_key)).to eq(merge_state_hash) + end + end + end + + context "cache is not empty" do + before do + cache.write(cache_key, merge_state_hash) + end + + it { is_expected.to eq(already_merged) } + + it "doesn't fetch from the disk" do + expect(repository.raw_repository).not_to receive(:merged_branch_names) + + subject + end + end + + context "cache is partially complete" do + before do + allow(repository.raw_repository).to receive(:merged_branch_names).with(["boop"]).and_return([]) + hash = merge_state_hash.except("boop") + cache.write(cache_key, hash) + end + + it { is_expected.to eq(already_merged) } + + it "does fetch from the disk" do + expect(repository.raw_repository).to receive(:merged_branch_names).with(["boop"]) + + subject + end + end + + context "requested branches array is empty" do + let(:branch_names) { [] } + + it { is_expected.to eq(already_merged) } + end + end + describe '#can_be_merged?' do context 'mergeable branches' do subject { repository.can_be_merged?('0b4bc9a49b562e85de7cc9e834518ea6828729b9', 'master') } @@ -1784,6 +1878,7 @@ describe Repository do :avatar, :exists?, :root_ref, + :merged_branch_names, :has_visible_content?, :issue_template_names, :merge_request_template_names, @@ -1959,7 +2054,7 @@ describe Repository do describe '#expire_branches_cache' do it 'expires the cache' do expect(repository).to receive(:expire_method_caches) - .with(%i(branch_names branch_count has_visible_content?)) + .with(%i(branch_names merged_branch_names branch_count has_visible_content?)) .and_call_original repository.expire_branches_cache diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index 99374d28324..d4deb049ea7 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -608,7 +608,7 @@ describe API::Branches do expect(json_response['message']).to eq('Branch name is invalid') end - it 'returns 400 if branch already exists' do + it 'returns 400 if branch already exists', :clean_gitlab_redis_cache do post api(route, user), params: { branch: 'new_design1', ref: branch_sha } expect(response).to have_gitlab_http_status(201) |