From 1f2f38f59a719f7dae110835b8beb3d94fdcd94d Mon Sep 17 00:00:00 2001 From: John Cai Date: Wed, 9 Jan 2019 18:45:47 -0800 Subject: Add client support for count diverging commits Adds the client call for the gitaly rpc CountDivergingCommits fixing signature simplifying commit logic adding test for max-count refactoring tests --- spec/lib/gitlab/git/repository_spec.rb | 86 ++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'spec') diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index cf9e0cccc71..aef4e433439 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -283,6 +283,92 @@ describe Gitlab::Git::Repository, :seed_helper do end end + describe '#diverging_commit_count' do + it 'counts 0 for the same branch' do + expect(repository.diverging_commit_count('master', 'master', max_count: 1000)).to eq([0, 0]) + end + + context 'max count does not truncate results' do + where(:left, :right, :expected) do + 1 | 1 | [1, 1] + 4 | 4 | [4, 4] + 2 | 2 | [2, 2] + 2 | 4 | [2, 4] + 4 | 2 | [4, 2] + 10 | 10 | [10, 10] + end + + with_them do + before do + repository.create_branch('left-branch', 'master') + repository.create_branch('right-branch', 'master') + left.times do + new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') + end + + right.times do + new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'right-branch', 'some more content for b', 'some stuff') + end + end + + after do + repository.delete_branch('left-branch') + repository.delete_branch('right-branch') + end + + it 'returns the correct count bounding at max_count' do + branch_a_sha = repository_rugged.branches['left-branch'].target.oid + branch_b_sha = repository_rugged.branches['right-branch'].target.oid + expect( + repository.diverging_commit_count( + branch_a_sha, branch_b_sha, max_count: 1000) + ).to eq(expected) + end + end + end + + context 'max count truncates results' do + where(:left, :right, :max_count) do + 1 | 1 | 1 + 4 | 4 | 4 + 2 | 2 | 3 + 2 | 4 | 3 + 4 | 2 | 5 + 10 | 10 | 10 + end + + with_them do + before do + repository.create_branch('left-branch', 'master') + repository.create_branch('right-branch', 'master') + left.times do + new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') + end + + right.times do + new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'right-branch', 'some more content for b', 'some stuff') + end + end + + after do + repository.delete_branch('left-branch') + repository.delete_branch('right-branch') + end + + it 'returns the correct count bounding at max_count' do + branch_a_sha = repository_rugged.branches['left-branch'].target.oid + branch_b_sha = repository_rugged.branches['right-branch'].target.oid + results = repository.diverging_commit_count(branch_a_sha, branch_b_sha, max_count: max_count) + expect(results[0] + results[1]).to eq(max_count) + end + end + end + + it_behaves_like 'wrapping gRPC errors', Gitlab::GitalyClient::CommitService, :diverging_commit_count do + subject { repository.diverging_commit_count('master', 'master', max_count: 1000) } + end + end + describe '#has_local_branches?' do context 'check for local branches' do it { expect(repository.has_local_branches?).to eq(true) } -- cgit v1.2.1 From a5378665a1dc0b9c8dc3a4fa279a0eb78aac5aac Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Tue, 9 Oct 2018 11:33:49 +0100 Subject: Remove HipChat integration from GitLab --- spec/factories/services.rb | 6 - .../projects/services/disable_triggers_spec.rb | 5 +- .../services/user_activates_hipchat_spec.rb | 38 -- .../projects/services/user_views_services_spec.rb | 3 +- spec/lib/gitlab/import_export/all_models.yml | 1 - spec/lib/gitlab/import_export/project.json | 22 -- .../project_services/hipchat_service_spec.rb | 408 --------------------- spec/models/project_spec.rb | 1 - 8 files changed, 5 insertions(+), 479 deletions(-) delete mode 100644 spec/features/projects/services/user_activates_hipchat_spec.rb delete mode 100644 spec/models/project_services/hipchat_service_spec.rb (limited to 'spec') diff --git a/spec/factories/services.rb b/spec/factories/services.rb index 5be56a49903..841b68c74af 100644 --- a/spec/factories/services.rb +++ b/spec/factories/services.rb @@ -56,10 +56,4 @@ FactoryBot.define do project_key: 'jira-key' ) end - - factory :hipchat_service do - project - type 'HipchatService' - token 'test_token' - end end diff --git a/spec/features/projects/services/disable_triggers_spec.rb b/spec/features/projects/services/disable_triggers_spec.rb index 1a13fe03a67..65b597da269 100644 --- a/spec/features/projects/services/disable_triggers_spec.rb +++ b/spec/features/projects/services/disable_triggers_spec.rb @@ -14,10 +14,11 @@ describe 'Disable individual triggers' do end context 'service has multiple supported events' do - let(:service_name) { 'HipChat' } + let(:service_name) { 'JIRA' } it 'shows trigger checkboxes' do - event_count = HipchatService.supported_events.count + event_count = JiraService.supported_events.count + expect(event_count).to be > 1 expect(page).to have_content "Trigger" expect(page).to have_css(checkbox_selector, count: event_count) diff --git a/spec/features/projects/services/user_activates_hipchat_spec.rb b/spec/features/projects/services/user_activates_hipchat_spec.rb deleted file mode 100644 index 2f5313c91f9..00000000000 --- a/spec/features/projects/services/user_activates_hipchat_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'spec_helper' - -describe 'User activates HipChat' do - let(:project) { create(:project) } - let(:user) { create(:user) } - - before do - project.add_maintainer(user) - sign_in(user) - - visit(project_settings_integrations_path(project)) - - click_link('HipChat') - end - - context 'with standart settings' do - it 'activates service' do - check('Active') - fill_in('Room', with: 'gitlab') - fill_in('Token', with: 'verySecret') - click_button('Save') - - expect(page).to have_content('HipChat activated.') - end - end - - context 'with custom settings' do - it 'activates service' do - check('Active') - fill_in('Room', with: 'gitlab_custom') - fill_in('Token', with: 'secretCustom') - fill_in('Server', with: 'https://chat.example.com') - click_button('Save') - - expect(page).to have_content('HipChat activated.') - end - end -end diff --git a/spec/features/projects/services/user_views_services_spec.rb b/spec/features/projects/services/user_views_services_spec.rb index e9c8cf0fe34..b0a838a7d2b 100644 --- a/spec/features/projects/services/user_views_services_spec.rb +++ b/spec/features/projects/services/user_views_services_spec.rb @@ -14,7 +14,6 @@ describe 'User views services' do it 'shows the list of available services' do expect(page).to have_content('Project services') expect(page).to have_content('Campfire') - expect(page).to have_content('HipChat') expect(page).to have_content('Assembla') expect(page).to have_content('Pushover') expect(page).to have_content('Atlassian Bamboo') @@ -22,5 +21,7 @@ describe 'User views services' do expect(page).to have_content('Asana') expect(page).to have_content('Irker (IRC gateway)') expect(page).to have_content('Packagist') + expect(page).to have_content('Mattermost') + expect(page).to have_content('Slack') end end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 6897ac8a3a8..c15b360b563 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -219,7 +219,6 @@ project: - packagist_service - pivotaltracker_service - prometheus_service -- hipchat_service - flowdock_service - assembla_service - asana_service diff --git a/spec/lib/gitlab/import_export/project.json b/spec/lib/gitlab/import_export/project.json index 58949f76bd6..1327f414498 100644 --- a/spec/lib/gitlab/import_export/project.json +++ b/spec/lib/gitlab/import_export/project.json @@ -6774,28 +6774,6 @@ "default": false, "wiki_page_events": true }, - { - "id": 93, - "title": "HipChat", - "project_id": 5, - "created_at": "2016-06-14T15:01:51.219Z", - "updated_at": "2016-06-14T15:01:51.219Z", - "active": false, - "properties": { - "notify_only_broken_pipelines": true - }, - "template": false, - "push_events": true, - "issues_events": true, - "merge_requests_events": true, - "tag_push_events": true, - "note_events": true, - "pipeline_events": true, - "type": "HipchatService", - "category": "common", - "default": false, - "wiki_page_events": true - }, { "id": 91, "title": "Flowdock", diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb deleted file mode 100644 index b0fd2ceead0..00000000000 --- a/spec/models/project_services/hipchat_service_spec.rb +++ /dev/null @@ -1,408 +0,0 @@ -require 'spec_helper' - -describe HipchatService do - describe "Associations" do - it { is_expected.to belong_to :project } - it { is_expected.to have_one :service_hook } - end - - describe 'Validations' do - context 'when service is active' do - before do - subject.active = true - end - - it { is_expected.to validate_presence_of(:token) } - end - - context 'when service is inactive' do - before do - subject.active = false - end - - it { is_expected.not_to validate_presence_of(:token) } - end - end - - describe "Execute" do - let(:hipchat) { described_class.new } - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } - let(:api_url) { 'https://hipchat.example.com/v2/room/123456/notification?auth_token=verySecret' } - let(:project_name) { project.full_name.gsub(/\s/, '') } - let(:token) { 'verySecret' } - let(:server_url) { 'https://hipchat.example.com'} - let(:push_sample_data) do - Gitlab::DataBuilder::Push.build_sample(project, user) - end - - before do - allow(hipchat).to receive_messages( - project_id: project.id, - project: project, - room: 123456, - server: server_url, - token: token - ) - WebMock.stub_request(:post, api_url) - end - - it 'tests and return errors' do - allow(hipchat).to receive(:execute).and_raise(StandardError, 'no such room') - result = hipchat.test(push_sample_data) - - expect(result[:success]).to be_falsey - expect(result[:result].to_s).to eq('no such room') - end - - it 'uses v1 if version is provided' do - allow(hipchat).to receive(:api_version).and_return('v1') - expect(HipChat::Client).to receive(:new).with( - token, - api_version: 'v1', - server_url: server_url - ).and_return(double(:hipchat_service).as_null_object) - hipchat.execute(push_sample_data) - end - - it 'uses v2 as the version when nothing is provided' do - allow(hipchat).to receive(:api_version).and_return('') - expect(HipChat::Client).to receive(:new).with( - token, - api_version: 'v2', - server_url: server_url - ).and_return(double(:hipchat_service).as_null_object) - hipchat.execute(push_sample_data) - end - - context 'push events' do - it "calls Hipchat API for push events" do - hipchat.execute(push_sample_data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates a push message" do - message = hipchat.send(:create_push_message, push_sample_data) - - push_sample_data[:object_attributes] - branch = push_sample_data[:ref].gsub('refs/heads/', '') - expect(message).to include("#{user.name} pushed to branch " \ - "#{branch} of " \ - "#{project_name}") - end - end - - context 'tag_push events' do - let(:push_sample_data) do - Gitlab::DataBuilder::Push.build( - project, - user, - Gitlab::Git::BLANK_SHA, - '1' * 40, - 'refs/tags/test', - []) - end - - it "calls Hipchat API for tag push events" do - hipchat.execute(push_sample_data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates a tag push message" do - message = hipchat.send(:create_push_message, push_sample_data) - - push_sample_data[:object_attributes] - expect(message).to eq("#{user.name} pushed new tag " \ - "test to " \ - "#{project_name}\n") - end - end - - context 'issue events' do - let(:issue) { create(:issue, title: 'Awesome issue', description: '**please** fix') } - let(:issue_service) { Issues::CreateService.new(project, user) } - let(:issues_sample_data) { issue_service.hook_data(issue, 'open') } - - it "calls Hipchat API for issue events" do - hipchat.execute(issues_sample_data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates an issue message" do - message = hipchat.send(:create_issue_message, issues_sample_data) - - obj_attr = issues_sample_data[:object_attributes] - expect(message).to eq("#{user.name} opened " \ - "issue ##{obj_attr["iid"]} in " \ - "#{project_name}: " \ - "Awesome issue" \ - "
please fix
") - end - end - - context 'merge request events' do - let(:merge_request) { create(:merge_request, description: '**please** fix', title: 'Awesome merge request', target_project: project, source_project: project) } - let(:merge_service) { MergeRequests::CreateService.new(project, user) } - let(:merge_sample_data) { merge_service.hook_data(merge_request, 'open') } - - it "calls Hipchat API for merge requests events" do - hipchat.execute(merge_sample_data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates a merge request message" do - message = hipchat.send(:create_merge_request_message, - merge_sample_data) - - obj_attr = merge_sample_data[:object_attributes] - expect(message).to eq("#{user.name} opened " \ - "merge request !#{obj_attr["iid"]} in " \ - "#{project_name}: " \ - "Awesome merge request" \ - "
please fix
") - end - end - - context "Note events" do - let(:user) { create(:user) } - let(:project) { create(:project, :repository, creator: user) } - - context 'when commit comment event triggered' do - let(:commit_note) do - create(:note_on_commit, author: user, project: project, - commit_id: project.repository.commit.id, - note: 'a comment on a commit') - end - - it "calls Hipchat API for commit comment events" do - data = Gitlab::DataBuilder::Note.build(commit_note, user) - hipchat.execute(data) - - expect(WebMock).to have_requested(:post, api_url).once - - message = hipchat.send(:create_message, data) - - obj_attr = data[:object_attributes] - commit_id = Commit.truncate_sha(data[:commit][:id]) - title = hipchat.send(:format_title, data[:commit][:message]) - - expect(message).to eq("#{user.name} commented on " \ - "commit #{commit_id} in " \ - "#{project_name}: " \ - "#{title}" \ - "
a comment on a commit
") - end - end - - context 'when merge request comment event triggered' do - let(:merge_request) do - create(:merge_request, source_project: project, - target_project: project) - end - - let(:merge_request_note) do - create(:note_on_merge_request, noteable: merge_request, - project: project, - note: "merge request **note**") - end - - it "calls Hipchat API for merge request comment events" do - data = Gitlab::DataBuilder::Note.build(merge_request_note, user) - hipchat.execute(data) - - expect(WebMock).to have_requested(:post, api_url).once - - message = hipchat.send(:create_message, data) - - obj_attr = data[:object_attributes] - merge_id = data[:merge_request]['iid'] - title = data[:merge_request]['title'] - - expect(message).to eq("#{user.name} commented on " \ - "merge request !#{merge_id} in " \ - "#{project_name}: " \ - "#{title}" \ - "
merge request note
") - end - end - - context 'when issue comment event triggered' do - let(:issue) { create(:issue, project: project) } - let(:issue_note) do - create(:note_on_issue, noteable: issue, project: project, - note: "issue **note**") - end - - it "calls Hipchat API for issue comment events" do - data = Gitlab::DataBuilder::Note.build(issue_note, user) - hipchat.execute(data) - - message = hipchat.send(:create_message, data) - - obj_attr = data[:object_attributes] - issue_id = data[:issue]['iid'] - title = data[:issue]['title'] - - expect(message).to eq("#{user.name} commented on " \ - "issue ##{issue_id} in " \ - "#{project_name}: " \ - "#{title}" \ - "
issue note
") - end - - context 'with confidential issue' do - before do - issue.update!(confidential: true) - end - - it 'calls Hipchat API with issue comment' do - data = Gitlab::DataBuilder::Note.build(issue_note, user) - hipchat.execute(data) - - message = hipchat.send(:create_message, data) - - expect(message).to include("
issue note
") - end - end - end - - context 'when snippet comment event triggered' do - let(:snippet) { create(:project_snippet, project: project) } - let(:snippet_note) do - create(:note_on_project_snippet, noteable: snippet, - project: project, - note: "snippet note") - end - - it "calls Hipchat API for snippet comment events" do - data = Gitlab::DataBuilder::Note.build(snippet_note, user) - hipchat.execute(data) - - expect(WebMock).to have_requested(:post, api_url).once - - message = hipchat.send(:create_message, data) - - obj_attr = data[:object_attributes] - snippet_id = data[:snippet]['id'] - title = data[:snippet]['title'] - - expect(message).to eq("#{user.name} commented on " \ - "snippet ##{snippet_id} in " \ - "#{project_name}: " \ - "#{title}" \ - "
snippet note
") - end - end - end - - context 'pipeline events' do - let(:pipeline) { create(:ci_empty_pipeline, user: create(:user)) } - let(:data) { Gitlab::DataBuilder::Pipeline.build(pipeline) } - - context 'for failed' do - before do - pipeline.drop - end - - it "calls Hipchat API" do - hipchat.execute(data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates a build message" do - message = hipchat.__send__(:create_pipeline_message, data) - - project_url = project.web_url - project_name = project.full_name.gsub(/\s/, '') - pipeline_attributes = data[:object_attributes] - ref = pipeline_attributes[:ref] - ref_type = pipeline_attributes[:tag] ? 'tag' : 'branch' - duration = pipeline_attributes[:duration] - user_name = data[:user][:name] - - expect(message).to eq("#{project_name}: " \ - "Pipeline ##{pipeline.id} " \ - "of #{ref} #{ref_type} " \ - "by #{user_name} failed in #{duration} second(s)") - end - end - - context 'for succeeded' do - before do - pipeline.succeed - end - - it "calls Hipchat API" do - hipchat.notify_only_broken_pipelines = false - hipchat.execute(data) - expect(WebMock).to have_requested(:post, api_url).once - end - - it "notifies only broken" do - hipchat.notify_only_broken_pipelines = true - hipchat.execute(data) - expect(WebMock).not_to have_requested(:post, api_url).once - end - end - end - - context "#message_options" do - it "is set to the defaults" do - expect(hipchat.__send__(:message_options)).to eq({ notify: false, color: 'yellow' }) - end - - it "sets notify to true" do - allow(hipchat).to receive(:notify).and_return('1') - - expect(hipchat.__send__(:message_options)).to eq({ notify: true, color: 'yellow' }) - end - - it "sets the color" do - allow(hipchat).to receive(:color).and_return('red') - - expect(hipchat.__send__(:message_options)).to eq({ notify: false, color: 'red' }) - end - - context 'with a successful build' do - it 'uses the green color' do - data = { object_kind: 'pipeline', - object_attributes: { status: 'success' } } - - expect(hipchat.__send__(:message_options, data)).to eq({ notify: false, color: 'green' }) - end - end - - context 'with a failed build' do - it 'uses the red color' do - data = { object_kind: 'pipeline', - object_attributes: { status: 'failed' } } - - expect(hipchat.__send__(:message_options, data)).to eq({ notify: false, color: 'red' }) - end - end - end - end - - context 'with UrlBlocker' do - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } - let(:hipchat) { described_class.new(project: project) } - let(:push_sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) } - - describe '#execute' do - before do - hipchat.server = 'http://localhost:9123' - end - - it 'raises UrlBlocker for localhost' do - expect(Gitlab::UrlBlocker).to receive(:validate!).and_call_original - expect { hipchat.execute(push_sample_data) }.to raise_error(Gitlab::HTTP::BlockedUrlError) - end - end - end -end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index c1767ed0535..7884e13ef54 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -41,7 +41,6 @@ describe Project do it { is_expected.to have_one(:pipelines_email_service) } it { is_expected.to have_one(:irker_service) } it { is_expected.to have_one(:pivotaltracker_service) } - it { is_expected.to have_one(:hipchat_service) } it { is_expected.to have_one(:flowdock_service) } it { is_expected.to have_one(:assembla_service) } it { is_expected.to have_one(:slack_slash_commands_service) } -- cgit v1.2.1 From 0d8fd9f7deb7a6d6e99d3a6fcffcada435c6aac2 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Thu, 31 Jan 2019 11:29:27 +0100 Subject: Change specs parameter to match requirements --- spec/support/shared_contexts/services_shared_context.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/support/shared_contexts/services_shared_context.rb b/spec/support/shared_contexts/services_shared_context.rb index 23f9b46ae0c..d92e8318fa0 100644 --- a/spec/support/shared_contexts/services_shared_context.rb +++ b/spec/support/shared_contexts/services_shared_context.rb @@ -19,7 +19,7 @@ Service.available_services_names.each do |service| elsif service == 'irker' && k == :server_port hash.merge!(k => 1234) elsif service == 'jira' && k == :jira_issue_transition_id - hash.merge!(k => 1234) + hash.merge!(k => '1,2,3') else hash.merge!(k => "someword") end -- cgit v1.2.1 From 9ab268b9c1bc028d50dee7c126878aa1df389cfe Mon Sep 17 00:00:00 2001 From: Ash McKenzie Date: Mon, 11 Feb 2019 14:23:35 +1100 Subject: Tidy up Gitlab::LfsToken spec - Remove unnecessary encrypted_password stubbing - Remove unnecessary attr_encrypted_db_key_base stub - Rename shared_example to 'a valid LFS token' --- spec/lib/gitlab/lfs_token_spec.rb | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'spec') diff --git a/spec/lib/gitlab/lfs_token_spec.rb b/spec/lib/gitlab/lfs_token_spec.rb index 1ec1ba19e39..b81f3be874f 100644 --- a/spec/lib/gitlab/lfs_token_spec.rb +++ b/spec/lib/gitlab/lfs_token_spec.rb @@ -4,10 +4,8 @@ require 'spec_helper' describe Gitlab::LfsToken, :clean_gitlab_redis_shared_state do describe '#token' do - shared_examples 'an LFS token generator' do + shared_examples 'a valid LFS token' do it 'returns a computed token' do - expect(Settings).to receive(:attr_encrypted_db_key_base).and_return('fbnbv6hdjweo53qka7kza8v8swxc413c05pb51qgtfte0bygh1p2e508468hfsn5ntmjcyiz7h1d92ashpet5pkdyejg7g8or3yryhuso4h8o5c73h429d9c3r6bjnet').twice - token = lfs_token.token expect(token).not_to be_nil @@ -20,11 +18,7 @@ describe Gitlab::LfsToken, :clean_gitlab_redis_shared_state do let(:actor) { create(:user, username: 'test_user_lfs_1') } let(:lfs_token) { described_class.new(actor) } - before do - allow(actor).to receive(:encrypted_password).and_return('$2a$04$ETfzVS5spE9Hexn9wh6NUenCHG1LyZ2YdciOYxieV1WLSa8DHqOFO') - end - - it_behaves_like 'an LFS token generator' + it_behaves_like 'a valid LFS token' it 'returns the correct username' do expect(lfs_token.actor_name).to eq(actor.username) @@ -40,11 +34,7 @@ describe Gitlab::LfsToken, :clean_gitlab_redis_shared_state do let(:actor) { create(:key, user: user) } let(:lfs_token) { described_class.new(actor) } - before do - allow(user).to receive(:encrypted_password).and_return('$2a$04$C1GAMKsOKouEbhKy2JQoe./3LwOfQAZc.hC8zW2u/wt8xgukvnlV.') - end - - it_behaves_like 'an LFS token generator' + it_behaves_like 'a valid LFS token' it 'returns the correct username' do expect(lfs_token.actor_name).to eq(user.username) @@ -65,7 +55,7 @@ describe Gitlab::LfsToken, :clean_gitlab_redis_shared_state do allow(actor).to receive(:id).and_return(actor_id) end - it_behaves_like 'an LFS token generator' + it_behaves_like 'a valid LFS token' it 'returns the correct username' do expect(lfs_token.actor_name).to eq("lfs+deploy-key-#{actor_id}") @@ -87,10 +77,6 @@ describe Gitlab::LfsToken, :clean_gitlab_redis_shared_state do let(:actor) { create(:user, username: 'test_user_lfs_1') } let(:lfs_token) { described_class.new(actor) } - before do - allow(actor).to receive(:encrypted_password).and_return('$2a$04$ETfzVS5spE9Hexn9wh6NUenCHG1LyZ2YdciOYxieV1WLSa8DHqOFO') - end - context 'for an HMAC token' do before do # We're not interested in testing LegacyRedisDeviseToken here -- cgit v1.2.1 From c4f1e8ed1014d2dec07ad12bed398dfa5d2bc6e1 Mon Sep 17 00:00:00 2001 From: Ash McKenzie Date: Mon, 11 Feb 2019 14:34:10 +1100 Subject: Move LFS auth hash creation into GitLab::LfsToken --- spec/lib/gitlab/lfs_token_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec') diff --git a/spec/lib/gitlab/lfs_token_spec.rb b/spec/lib/gitlab/lfs_token_spec.rb index b81f3be874f..b4d42a47263 100644 --- a/spec/lib/gitlab/lfs_token_spec.rb +++ b/spec/lib/gitlab/lfs_token_spec.rb @@ -226,4 +226,18 @@ describe Gitlab::LfsToken, :clean_gitlab_redis_shared_state do end end end + + describe '#for_gitlab_shell' do + let(:actor) { create(:user) } + let(:lfs_token) { described_class.new(actor) } + let(:repo_http_path) { 'http://localhost/user/repo.git' } + + it 'returns a Hash desgined for gitlab-shell' do + hash = lfs_token.for_gitlab_shell(repo_http_path) + + expect(hash[:username]).to eq(actor.username) + expect(hash[:repository_http_path]).to eq(repo_http_path) + expect(hash[:lfs_token]).to be_a String + end + end end -- cgit v1.2.1 From b502d90a9f0521247e8c42f1ed586f6f4a52507a Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 6 Feb 2019 09:54:53 +0000 Subject: Adapt that diverging commits could be just one bar refactors the ui for diverging commits so that it's only a single bar instead of two separate bars --- spec/features/projects/branches/user_views_branches_spec.rb | 2 ++ spec/lib/gitlab/git/repository_spec.rb | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/features/projects/branches/user_views_branches_spec.rb b/spec/features/projects/branches/user_views_branches_spec.rb index 62ae793151c..777d30fdffd 100644 --- a/spec/features/projects/branches/user_views_branches_spec.rb +++ b/spec/features/projects/branches/user_views_branches_spec.rb @@ -15,6 +15,8 @@ describe "User views branches" do it "shows branches" do expect(page).to have_content("Branches").and have_content("master") + + expect(page.all(".graph-side")).to all( have_content(/\d+/) ) end end diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index aef4e433439..8a9e78ba3c3 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -302,6 +302,7 @@ describe Gitlab::Git::Repository, :seed_helper do before do repository.create_branch('left-branch', 'master') repository.create_branch('right-branch', 'master') + left.times do new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') end @@ -319,10 +320,10 @@ describe Gitlab::Git::Repository, :seed_helper do it 'returns the correct count bounding at max_count' do branch_a_sha = repository_rugged.branches['left-branch'].target.oid branch_b_sha = repository_rugged.branches['right-branch'].target.oid - expect( - repository.diverging_commit_count( - branch_a_sha, branch_b_sha, max_count: 1000) - ).to eq(expected) + + count = repository.diverging_commit_count(branch_a_sha, branch_b_sha, max_count: 1000) + + expect(count).to eq(expected) end end end @@ -341,6 +342,7 @@ describe Gitlab::Git::Repository, :seed_helper do before do repository.create_branch('left-branch', 'master') repository.create_branch('right-branch', 'master') + left.times do new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') end @@ -358,7 +360,9 @@ describe Gitlab::Git::Repository, :seed_helper do it 'returns the correct count bounding at max_count' do branch_a_sha = repository_rugged.branches['left-branch'].target.oid branch_b_sha = repository_rugged.branches['right-branch'].target.oid + results = repository.diverging_commit_count(branch_a_sha, branch_b_sha, max_count: max_count) + expect(results[0] + results[1]).to eq(max_count) end end -- cgit v1.2.1 From 9100ca188c45f2129d5e891534ed38718ef67e46 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 11 Feb 2019 17:36:57 -0200 Subject: Replace dots with an underscore when creating an alias for the CTE When the Arel table to use as the alias contains a schema in your name, e.g., "gitlab_secondary"."namespaces" it produces an invalid query. --- spec/lib/gitlab/sql/recursive_cte_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec') diff --git a/spec/lib/gitlab/sql/recursive_cte_spec.rb b/spec/lib/gitlab/sql/recursive_cte_spec.rb index 25146860615..7fe39dd5a96 100644 --- a/spec/lib/gitlab/sql/recursive_cte_spec.rb +++ b/spec/lib/gitlab/sql/recursive_cte_spec.rb @@ -31,6 +31,15 @@ describe Gitlab::SQL::RecursiveCTE, :postgresql do expect(cte.alias_to(table).to_sql).to eq("#{source_name} AS #{alias_name}") end + + it 'replaces dots with an underscore' do + table = Arel::Table.new('gitlab.kittens') + + source_name = ActiveRecord::Base.connection.quote_table_name(:cte_name) + alias_name = ActiveRecord::Base.connection.quote_table_name(:gitlab_kittens) + + expect(cte.alias_to(table).to_sql).to eq("#{source_name} AS #{alias_name}") + end end describe '#apply_to' do -- cgit v1.2.1 From b9c19e2f1378c8e8647a55f4707186a4995f3f9c Mon Sep 17 00:00:00 2001 From: John Cai Date: Mon, 11 Feb 2019 10:18:48 -0800 Subject: Adding convenience method to project model --- spec/models/project_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 7b364395faf..1f9088c2e6b 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -4602,6 +4602,21 @@ describe Project do end end + describe '#has_pool_repsitory?' do + it 'returns false when it does not have a pool repository' do + subject = create(:project, :repository) + + expect(subject.has_pool_repository?).to be false + end + + it 'returns true when it has a pool repository' do + pool = create(:pool_repository, :ready) + subject = create(:project, :repository, pool_repository: pool) + + expect(subject.has_pool_repository?).to be true + end + end + def rugged_config rugged_repo(project.repository).config end -- cgit v1.2.1 From 44d0d0e6f96dba384bbff5da8faa05db4e881dd2 Mon Sep 17 00:00:00 2001 From: Frank Sauerburger Date: Mon, 11 Feb 2019 22:20:39 +0100 Subject: Fix broken links on help page Update the help controller to correctly handle relative links on the help pages when the relative link is before an external link on the same line in the markdown file. Test cases have been implement to check for - relative links before external link on same line, - HTTPS in query part of link, - URLs without '//' and - protocol-relative links. --- spec/controllers/help_controller_spec.rb | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'spec') diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index 5cb284e7e2d..dca67c18caa 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -37,6 +37,46 @@ describe HelpController do expect(assigns[:help_index]).to eq '[external](https://some.external.link)' end end + + context 'when relative url with external on same line' do + it 'prefix it with /help/' do + stub_readme("[API](api/README.md) [external](https://some.external.link)") + + get :index + + expect(assigns[:help_index]).to eq '[API](/help/api/README.md) [external](https://some.external.link)' + end + end + + context 'when relative url with http:// in query' do + it 'prefix it with /help/' do + stub_readme("[API](api/README.md?go=https://example.com/)") + + get :index + + expect(assigns[:help_index]).to eq '[API](/help/api/README.md?go=https://example.com/)' + end + end + + context 'when mailto URL' do + it 'do not change it' do + stub_readme("[report bug](mailto:bugs@example.com)") + + get :index + + expect(assigns[:help_index]).to eq '[report bug](mailto:bugs@example.com)' + end + end + + context 'when protocol-relative link' do + it 'do not change it' do + stub_readme("[protocol-relative](//example.com)") + + get :index + + expect(assigns[:help_index]).to eq '[protocol-relative](//example.com)' + end + end end describe 'GET #show' do -- cgit v1.2.1 From e34a321327cbbb1f615b9594c920dc04277bdb81 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 9 Feb 2019 04:28:23 -0800 Subject: Create the source branch for a GitHub import When the GitHub importer creates a merge request, it retrieves the SHA but does not actually create the source branch. This makes it impossible to merge an open merge request, particularly if the source branch were from a forked project. In that case, the branch will never exist because the original `project-name:source-branch` name is never created, nor is it a valid branch name. To prevent possible branch name conflicts, forked source branches are now renamed `github/fork/project-name/source-branch` and created when necessary. Note that we only create the source branch if the merge request is open. For projects that have many merge requests, the project would end up with a lot of possibly dead branches. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/57370 --- .../importer/pull_request_importer_spec.rb | 38 ++++++++++++++++++++-- .../representation/pull_request_spec.rb | 2 +- 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb index 0f21b8843b6..15e59718dce 100644 --- a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb @@ -89,7 +89,7 @@ describe Gitlab::GithubImport::Importer::PullRequestImporter, :clean_gitlab_redi description: 'This is my pull request', source_project_id: project.id, target_project_id: project.id, - source_branch: 'alice:feature', + source_branch: 'github/fork/alice/feature', target_branch: 'master', state: :merged, milestone_id: milestone.id, @@ -134,7 +134,7 @@ describe Gitlab::GithubImport::Importer::PullRequestImporter, :clean_gitlab_redi description: "*Created by: alice*\n\nThis is my pull request", source_project_id: project.id, target_project_id: project.id, - source_branch: 'alice:feature', + source_branch: 'github/fork/alice/feature', target_branch: 'master', state: :merged, milestone_id: milestone.id, @@ -259,6 +259,40 @@ describe Gitlab::GithubImport::Importer::PullRequestImporter, :clean_gitlab_redi .and_return(user.id) end + it 'does not create the source branch if merge request is merged' do + mr, exists = importer.create_merge_request + + importer.insert_git_data(mr, exists) + + expect(project.repository.branch_exists?(mr.source_branch)).to be_falsey + expect(project.repository.branch_exists?(mr.target_branch)).to be_truthy + end + + it 'creates the source branch if merge request is open' do + mr, exists = importer.create_merge_request + mr.state = 'opened' + mr.save + + importer.insert_git_data(mr, exists) + + expect(project.repository.branch_exists?(mr.source_branch)).to be_truthy + expect(project.repository.branch_exists?(mr.target_branch)).to be_truthy + end + + it 'ignores Git errors when creating a branch' do + mr, exists = importer.create_merge_request + mr.state = 'opened' + mr.save + + expect(project.repository).to receive(:add_branch).and_raise(Gitlab::Git::CommandError) + expect(Gitlab::Sentry).to receive(:track_acceptable_exception).and_call_original + + importer.insert_git_data(mr, exists) + + expect(project.repository.branch_exists?(mr.source_branch)).to be_falsey + expect(project.repository.branch_exists?(mr.target_branch)).to be_truthy + end + it 'creates the merge request diffs' do mr, exists = importer.create_merge_request diff --git a/spec/lib/gitlab/github_import/representation/pull_request_spec.rb b/spec/lib/gitlab/github_import/representation/pull_request_spec.rb index 33f6ff0ae6a..d478e5ae899 100644 --- a/spec/lib/gitlab/github_import/representation/pull_request_spec.rb +++ b/spec/lib/gitlab/github_import/representation/pull_request_spec.rb @@ -238,7 +238,7 @@ describe Gitlab::GithubImport::Representation::PullRequest do target_repository_id: 2 ) - expect(pr.formatted_source_branch).to eq('foo:branch') + expect(pr.formatted_source_branch).to eq('github/fork/foo/branch') end end -- cgit v1.2.1 From be485a781d6fde502627f891a1c11e93c9bfbf3c Mon Sep 17 00:00:00 2001 From: Simon Knox Date: Wed, 9 Jan 2019 23:46:43 +0000 Subject: Hide More Actions tooltip when the menu opens --- .../notes/components/note_actions_spec.js | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'spec') diff --git a/spec/javascripts/notes/components/note_actions_spec.js b/spec/javascripts/notes/components/note_actions_spec.js index 0c1962912b4..d604e90b529 100644 --- a/spec/javascripts/notes/components/note_actions_spec.js +++ b/spec/javascripts/notes/components/note_actions_spec.js @@ -1,5 +1,5 @@ import Vue from 'vue'; -import { shallowMount, createLocalVue } from '@vue/test-utils'; +import { shallowMount, createLocalVue, createWrapper } from '@vue/test-utils'; import createStore from '~/notes/stores'; import noteActions from '~/notes/components/note_actions.vue'; import { TEST_HOST } from 'spec/test_constants'; @@ -10,7 +10,7 @@ describe('noteActions', () => { let store; let props; - const createWrapper = propsData => { + const shallowMountNoteActions = propsData => { const localVue = createLocalVue(); return shallowMount(noteActions, { store, @@ -44,7 +44,7 @@ describe('noteActions', () => { beforeEach(() => { store.dispatch('setUserData', userDataMock); - wrapper = createWrapper(props); + wrapper = shallowMountNoteActions(props); }); it('should render access level badge', () => { @@ -90,13 +90,27 @@ describe('noteActions', () => { it('should be possible to delete comment', () => { expect(wrapper.find('.js-note-delete').exists()).toBe(true); }); + + it('closes tooltip when dropdown opens', done => { + wrapper.find('.more-actions-toggle').trigger('click'); + + const rootWrapper = createWrapper(wrapper.vm.$root); + Vue.nextTick() + .then(() => { + const emitted = Object.keys(rootWrapper.emitted()); + + expect(emitted).toEqual(['bv::hide::tooltip']); + done(); + }) + .catch(done.fail); + }); }); }); describe('user is not logged in', () => { beforeEach(() => { store.dispatch('setUserData', {}); - wrapper = createWrapper({ + wrapper = shallowMountNoteActions({ ...props, canDelete: false, canEdit: false, @@ -127,7 +141,7 @@ describe('noteActions', () => { describe('for showReply = true', () => { beforeEach(() => { - wrapper = createWrapper({ + wrapper = shallowMountNoteActions({ ...props, showReply: true, }); @@ -142,7 +156,7 @@ describe('noteActions', () => { describe('for showReply = false', () => { beforeEach(() => { - wrapper = createWrapper({ + wrapper = shallowMountNoteActions({ ...props, showReply: false, }); @@ -169,7 +183,7 @@ describe('noteActions', () => { describe('for showReply = true', () => { beforeEach(() => { - wrapper = createWrapper({ + wrapper = shallowMountNoteActions({ ...props, showReply: true, }); @@ -184,7 +198,7 @@ describe('noteActions', () => { describe('for showReply = false', () => { beforeEach(() => { - wrapper = createWrapper({ + wrapper = shallowMountNoteActions({ ...props, showReply: false, }); -- cgit v1.2.1 From 60bd0a24f539217d760437e49e86c04e5c43498a Mon Sep 17 00:00:00 2001 From: Victor Zagorodny Date: Wed, 6 Feb 2019 19:56:16 +0200 Subject: Add user_preferences_usage to usage ping --- spec/lib/gitlab/usage_data_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec') diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 4f5993ba226..52edc46d5e4 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -124,6 +124,7 @@ describe Gitlab::UsageData do todos uploads web_hooks + user_preferences )) end -- cgit v1.2.1 From fa518963ec7a703ddb321533884a49c516a4acd7 Mon Sep 17 00:00:00 2001 From: Victor Zagorodny Date: Fri, 8 Feb 2019 13:22:11 +0200 Subject: Protect group overview usage ping w/ feature flag user_preferences key is includes into system usage data only if group_overview_security_dashboard feature flag is enabled; see https://gitlab.com/gitlab-org/gitlab-ee/issues/7048 --- spec/lib/gitlab/usage_data_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 52edc46d5e4..d3eae80cc56 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -128,6 +128,11 @@ describe Gitlab::UsageData do )) end + it 'does not gather user preferences usage data when the feature is disabled' do + stub_feature_flags(group_overview_security_dashboard: false) + expect(subject[:counts].keys).not_to include(:user_preferences) + end + it 'gathers projects data correctly' do count_data = subject[:counts] -- cgit v1.2.1 From 13d2d1985c5346beab95e6a77706194f9f007a05 Mon Sep 17 00:00:00 2001 From: Vladimir Shushlin Date: Tue, 12 Feb 2019 12:18:17 +0000 Subject: Fix access to pages domain settings --- .../projects/pages_domains_controller_spec.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/controllers/projects/pages_domains_controller_spec.rb b/spec/controllers/projects/pages_domains_controller_spec.rb index 8b7f7587701..ffb9867a203 100644 --- a/spec/controllers/projects/pages_domains_controller_spec.rb +++ b/spec/controllers/projects/pages_domains_controller_spec.rb @@ -23,12 +23,27 @@ describe Projects::PagesDomainsController do end describe 'GET show' do - it "displays the 'show' page" do + def make_request get(:show, params: request_params.merge(id: pages_domain.domain)) + end + it "displays the 'show' page" do + make_request expect(response).to have_gitlab_http_status(200) expect(response).to render_template('show') end + + context 'when user is developer' do + before do + project.add_developer(user) + end + + it 'renders 404 page' do + make_request + + expect(response).to have_gitlab_http_status(404) + end + end end describe 'GET new' do -- cgit v1.2.1 From c3782d20afc421cee972df0fa26e9a8e67210f52 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 5 Feb 2019 12:39:46 +0100 Subject: Remove fast_destroy_uploads feature flag Fast destroy of uploads was successfully enabled and test. --- .../models/with_uploads_shared_examples.rb | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'spec') diff --git a/spec/support/shared_examples/models/with_uploads_shared_examples.rb b/spec/support/shared_examples/models/with_uploads_shared_examples.rb index 1d11b855459..43033a2d256 100644 --- a/spec/support/shared_examples/models/with_uploads_shared_examples.rb +++ b/spec/support/shared_examples/models/with_uploads_shared_examples.rb @@ -44,26 +44,6 @@ shared_examples_for 'model with uploads' do |supports_fileuploads| model_object.destroy end end - - describe 'destroy strategy depending on feature flag' do - let!(:upload) { create(:upload, uploader: FileUploader, model: model_object) } - - it 'does not destroy uploads by default' do - expect(model_object).to receive(:delete_uploads) - expect(model_object).not_to receive(:destroy_uploads) - - model_object.destroy - end - - it 'uses before destroy callback if feature flag is disabled' do - stub_feature_flags(fast_destroy_uploads: false) - - expect(model_object).to receive(:destroy_uploads) - expect(model_object).not_to receive(:delete_uploads) - - model_object.destroy - end - end end end end -- cgit v1.2.1 From 6afcc4ef52ecb7410a4e2602e02fca60fb38621b Mon Sep 17 00:00:00 2001 From: Marcel Amirault Date: Tue, 12 Feb 2019 16:01:10 +0000 Subject: Change unicode for non-standard spaces --- spec/features/dashboard/todos/todos_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/features/dashboard/todos/todos_spec.rb b/spec/features/dashboard/todos/todos_spec.rb index 51f158d3045..fd8677feab5 100644 --- a/spec/features/dashboard/todos/todos_spec.rb +++ b/spec/features/dashboard/todos/todos_spec.rb @@ -126,7 +126,7 @@ describe 'Dashboard Todos' do it 'shows you added a todo message' do page.within('.js-todos-all') do - expect(page).to have_content("You added a todo for issue #{issue.to_reference(full: true)}") + expect(page).to have_content("You added a todo for issue #{issue.to_reference(full: true)}") expect(page).not_to have_content('to yourself') end end @@ -140,7 +140,7 @@ describe 'Dashboard Todos' do it 'shows you mentioned yourself message' do page.within('.js-todos-all') do - expect(page).to have_content("You mentioned yourself on issue #{issue.to_reference(full: true)}") + expect(page).to have_content("You mentioned yourself on issue #{issue.to_reference(full: true)}") expect(page).not_to have_content('to yourself') end end @@ -154,7 +154,7 @@ describe 'Dashboard Todos' do it 'shows you directly addressed yourself message' do page.within('.js-todos-all') do - expect(page).to have_content("You directly addressed yourself on issue #{issue.to_reference(full: true)}") + expect(page).to have_content("You directly addressed yourself on issue #{issue.to_reference(full: true)}") expect(page).not_to have_content('to yourself') end end @@ -170,7 +170,7 @@ describe 'Dashboard Todos' do it 'shows you set yourself as an approver message' do page.within('.js-todos-all') do - expect(page).to have_content("You set yourself as an approver for merge request #{merge_request.to_reference(full: true)}") + expect(page).to have_content("You set yourself as an approver for merge request #{merge_request.to_reference(full: true)}") expect(page).not_to have_content('to yourself') end end -- cgit v1.2.1 From 2a5ca841c47ffc318b6e9bdebc18286999ef32eb Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Feb 2019 19:36:45 +0100 Subject: API: Expose text_color for project and group labels --- spec/fixtures/api/schemas/public_api/v4/group_labels.json | 1 + spec/requests/api/labels_spec.rb | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/fixtures/api/schemas/public_api/v4/group_labels.json b/spec/fixtures/api/schemas/public_api/v4/group_labels.json index f6c327abfdd..fbde45f2904 100644 --- a/spec/fixtures/api/schemas/public_api/v4/group_labels.json +++ b/spec/fixtures/api/schemas/public_api/v4/group_labels.json @@ -6,6 +6,7 @@ "id" : { "type": "integer" }, "name" : { "type": "string "}, "color" : { "type": "string "}, + "text_color" : { "type": "string "}, "description" : { "type": "string "}, "open_issues_count" : { "type": "integer "}, "closed_issues_count" : { "type": "integer "}, diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb index 49eea2e362b..606fa9185d8 100644 --- a/spec/requests/api/labels_spec.rb +++ b/spec/requests/api/labels_spec.rb @@ -20,7 +20,7 @@ describe API::Labels do create(:labeled_merge_request, labels: [priority_label], author: user, source_project: project ) expected_keys = %w( - id name color description + id name color text_color description open_issues_count closed_issues_count open_merge_requests_count subscribed priority ) @@ -43,6 +43,7 @@ describe API::Labels do expect(label1_response['open_merge_requests_count']).to eq(0) expect(label1_response['name']).to eq(label1.name) expect(label1_response['color']).to be_present + expect(label1_response['text_color']).to be_present expect(label1_response['description']).to be_nil expect(label1_response['priority']).to be_nil expect(label1_response['subscribed']).to be_falsey @@ -52,6 +53,7 @@ describe API::Labels do expect(group_label_response['open_merge_requests_count']).to eq(0) expect(group_label_response['name']).to eq(group_label.name) expect(group_label_response['color']).to be_present + expect(group_label_response['text_color']).to be_present expect(group_label_response['description']).to be_nil expect(group_label_response['priority']).to be_nil expect(group_label_response['subscribed']).to be_falsey @@ -61,6 +63,7 @@ describe API::Labels do expect(priority_label_response['open_merge_requests_count']).to eq(1) expect(priority_label_response['name']).to eq(priority_label.name) expect(priority_label_response['color']).to be_present + expect(priority_label_response['text_color']).to be_present expect(priority_label_response['description']).to be_nil expect(priority_label_response['priority']).to eq(3) expect(priority_label_response['subscribed']).to be_falsey -- cgit v1.2.1 From 7430149d4d7ed087eb756a21db77ea92d31d3c7c Mon Sep 17 00:00:00 2001 From: Winnie Hellmann Date: Tue, 12 Feb 2019 20:55:56 +0000 Subject: Convert noteable_note_spec.js to Vue test utils (cherry picked from commit 861f93e6fc72ef4adbc4ace3fd297382e07b619c) --- .../notes/components/noteable_note_spec.js | 118 +++++++++++++++------ .../user_avatar/user_avatar_link_spec.js | 18 +++- 2 files changed, 98 insertions(+), 38 deletions(-) (limited to 'spec') diff --git a/spec/javascripts/notes/components/noteable_note_spec.js b/spec/javascripts/notes/components/noteable_note_spec.js index 8ade6fc2ced..9420713ceca 100644 --- a/spec/javascripts/notes/components/noteable_note_spec.js +++ b/spec/javascripts/notes/components/noteable_note_spec.js @@ -1,86 +1,138 @@ -import $ from 'jquery'; import _ from 'underscore'; -import Vue from 'vue'; +import { shallowMount, createLocalVue } from '@vue/test-utils'; import createStore from '~/notes/stores'; import issueNote from '~/notes/components/noteable_note.vue'; +import NoteHeader from '~/notes/components/note_header.vue'; +import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue'; +import NoteActions from '~/notes/components/note_actions.vue'; +import NoteBody from '~/notes/components/note_body.vue'; import { noteableDataMock, notesDataMock, note } from '../mock_data'; describe('issue_note', () => { let store; - let vm; + let wrapper; beforeEach(() => { - const Component = Vue.extend(issueNote); - store = createStore(); store.dispatch('setNoteableData', noteableDataMock); store.dispatch('setNotesData', notesDataMock); - vm = new Component({ + const localVue = createLocalVue(); + wrapper = shallowMount(issueNote, { store, propsData: { note, }, - }).$mount(); + sync: false, + localVue, + }); }); afterEach(() => { - vm.$destroy(); + wrapper.destroy(); }); it('should render user information', () => { - expect(vm.$el.querySelector('.user-avatar-link img').getAttribute('src')).toEqual( - note.author.avatar_url, - ); + const { author } = note; + const avatar = wrapper.find(UserAvatarLink); + const avatarProps = avatar.props(); + + expect(avatarProps.linkHref).toBe(author.path); + expect(avatarProps.imgSrc).toBe(author.avatar_url); + expect(avatarProps.imgAlt).toBe(author.name); + expect(avatarProps.imgSize).toBe(40); }); it('should render note header content', () => { - const el = vm.$el.querySelector('.note-header .note-header-author-name'); + const noteHeader = wrapper.find(NoteHeader); + const noteHeaderProps = noteHeader.props(); - expect(el.textContent.trim()).toEqual(note.author.name); + expect(noteHeaderProps.author).toEqual(note.author); + expect(noteHeaderProps.createdAt).toEqual(note.created_at); + expect(noteHeaderProps.noteId).toEqual(note.id); }); it('should render note actions', () => { - expect(vm.$el.querySelector('.note-actions')).toBeDefined(); + const { author } = note; + const noteActions = wrapper.find(NoteActions); + const noteActionsProps = noteActions.props(); + + expect(noteActionsProps.authorId).toBe(author.id); + expect(noteActionsProps.noteId).toBe(note.id); + expect(noteActionsProps.noteUrl).toBe(note.noteable_note_url); + expect(noteActionsProps.accessLevel).toBe(note.human_access); + expect(noteActionsProps.canEdit).toBe(note.current_user.can_edit); + expect(noteActionsProps.canAwardEmoji).toBe(note.current_user.can_award_emoji); + expect(noteActionsProps.canDelete).toBe(note.current_user.can_edit); + expect(noteActionsProps.canReportAsAbuse).toBe(true); + expect(noteActionsProps.canResolve).toBe(false); + expect(noteActionsProps.reportAbusePath).toBe(note.report_abuse_path); + expect(noteActionsProps.resolvable).toBe(false); + expect(noteActionsProps.isResolved).toBe(false); + expect(noteActionsProps.isResolving).toBe(false); + expect(noteActionsProps.resolvedBy).toEqual({}); }); it('should render issue body', () => { - expect(vm.$el.querySelector('.note-text').innerHTML).toEqual(note.note_html); + const noteBody = wrapper.find(NoteBody); + const noteBodyProps = noteBody.props(); + + expect(noteBodyProps.note).toEqual(note); + expect(noteBodyProps.line).toBe(null); + expect(noteBodyProps.canEdit).toBe(note.current_user.can_edit); + expect(noteBodyProps.isEditing).toBe(false); + expect(noteBodyProps.helpPagePath).toBe(''); }); it('prevents note preview xss', done => { const imgSrc = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; const noteBody = ``; const alertSpy = spyOn(window, 'alert'); - vm.updateNote = () => new Promise($.noop); + store.hotUpdate({ + actions: { + updateNote() {}, + }, + }); + const noteBodyComponent = wrapper.find(NoteBody); - vm.formUpdateHandler(noteBody, null, $.noop); + noteBodyComponent.vm.$emit('handleFormUpdate', noteBody, null, () => {}); setTimeout(() => { expect(alertSpy).not.toHaveBeenCalled(); - expect(vm.note.note_html).toEqual(_.escape(noteBody)); + expect(wrapper.vm.note.note_html).toEqual(_.escape(noteBody)); done(); }, 0); }); describe('cancel edit', () => { it('restores content of updated note', done => { - const noteBody = 'updated note text'; - vm.updateNote = () => Promise.resolve(); - - vm.formUpdateHandler(noteBody, null, $.noop); - - setTimeout(() => { - expect(vm.note.note_html).toEqual(noteBody); - - vm.formCancelHandler(); - - setTimeout(() => { - expect(vm.note.note_html).toEqual(noteBody); - - done(); - }); + const updatedText = 'updated note text'; + store.hotUpdate({ + actions: { + updateNote() {}, + }, }); + const noteBody = wrapper.find(NoteBody); + noteBody.vm.resetAutoSave = () => {}; + + noteBody.vm.$emit('handleFormUpdate', updatedText, null, () => {}); + + wrapper.vm + .$nextTick() + .then(() => { + const noteBodyProps = noteBody.props(); + + expect(noteBodyProps.note.note_html).toBe(updatedText); + noteBody.vm.$emit('cancelForm'); + }) + .then(() => wrapper.vm.$nextTick()) + .then(() => { + const noteBodyProps = noteBody.props(); + + expect(noteBodyProps.note.note_html).toBe(note.note_html); + }) + .then(done) + .catch(done.fail); }); }); }); diff --git a/spec/javascripts/vue_shared/components/user_avatar/user_avatar_link_spec.js b/spec/javascripts/vue_shared/components/user_avatar/user_avatar_link_spec.js index f2472fd377c..80aa75847ae 100644 --- a/spec/javascripts/vue_shared/components/user_avatar/user_avatar_link_spec.js +++ b/spec/javascripts/vue_shared/components/user_avatar/user_avatar_link_spec.js @@ -1,13 +1,14 @@ import _ from 'underscore'; import Vue from 'vue'; import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue'; +import { TEST_HOST } from 'spec/test_constants'; describe('User Avatar Link Component', function() { beforeEach(function() { this.propsData = { - linkHref: 'myavatarurl.com', + linkHref: `${TEST_HOST}/myavatarurl.com`, imgSize: 99, - imgSrc: 'myavatarurl.com', + imgSrc: `${TEST_HOST}/myavatarurl.com`, imgAlt: 'mydisplayname', imgCssClasses: 'myextraavatarclass', tooltipText: 'tooltip text', @@ -37,11 +38,18 @@ describe('User Avatar Link Component', function() { }); it('should render as a child element', function() { - expect(this.userAvatarLink.$el.tagName).toBe('A'); + const link = this.userAvatarLink.$el; + + expect(link.tagName).toBe('A'); + expect(link.href).toBe(this.propsData.linkHref); }); - it('should have as a child element', function() { - expect(this.userAvatarLink.$el.querySelector('img')).not.toBeNull(); + it('renders imgSrc with imgSize as image', function() { + const { imgSrc, imgSize } = this.propsData; + const image = this.userAvatarLink.$el.querySelector('img'); + + expect(image).not.toBeNull(); + expect(image.src).toBe(`${imgSrc}?width=${imgSize}`); }); it('should return necessary props as defined', function() { -- cgit v1.2.1 From ff71ac7217a8e5fa33c9ce8c46a5642c1d27f5e4 Mon Sep 17 00:00:00 2001 From: Brett Walker Date: Tue, 12 Feb 2019 16:22:21 -0600 Subject: Find checkbox input with less specific selector --- spec/services/task_list_toggle_service_spec.rb | 32 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'spec') diff --git a/spec/services/task_list_toggle_service_spec.rb b/spec/services/task_list_toggle_service_spec.rb index 7c5480d382f..b1260cf740a 100644 --- a/spec/services/task_list_toggle_service_spec.rb +++ b/spec/services/task_list_toggle_service_spec.rb @@ -12,6 +12,10 @@ describe TaskListToggleService do 1. [X] Item 1 - [ ] Sub-item 1 + + - [ ] loose list + + with an embedded paragraph EOT end @@ -26,16 +30,22 @@ describe TaskListToggleService do

A paragraph

-
    -
  1. - Item 1 -