summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/pages_domains_controller_spec.rb17
-rw-r--r--spec/features/dashboard/todos/todos_spec.rb8
-rw-r--r--spec/features/projects/branches/user_views_branches_spec.rb2
-rw-r--r--spec/javascripts/notes/components/note_actions_spec.js30
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb90
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb38
-rw-r--r--spec/lib/gitlab/github_import/representation/pull_request_spec.rb2
-rw-r--r--spec/lib/gitlab/sql/recursive_cte_spec.rb9
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb6
-rw-r--r--spec/models/project_spec.rb15
-rw-r--r--spec/support/shared_examples/models/with_uploads_shared_examples.rb20
11 files changed, 201 insertions, 36 deletions
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
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
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/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,
});
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index cf9e0cccc71..8a9e78ba3c3 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -283,6 +283,96 @@ 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
+
+ count = repository.diverging_commit_count(branch_a_sha, branch_b_sha, max_count: 1000)
+
+ expect(count).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) }
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
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
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index 4f5993ba226..d3eae80cc56 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -124,9 +124,15 @@ describe Gitlab::UsageData do
todos
uploads
web_hooks
+ user_preferences
))
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]
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
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