summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-11-04 22:37:44 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-11-04 22:37:44 +0800
commitfb9a0e5277f9825d7faf991c0600a7247b268fe8 (patch)
tree35000cd71ebf5de840c2c931d2f1c7a9b7357dad /spec
parentce1dc4c25d3464b7a9a1b21d93157c9fed98f705 (diff)
parent5368b9f249485e254a90fe7daa551d61412bee26 (diff)
downloadgitlab-ce-fb9a0e5277f9825d7faf991c0600a7247b268fe8.tar.gz
Merge remote-tracking branch 'upstream/master' into show-status-from-branch
* upstream/master: (35 commits) Only skip group when it's actually a group in the "Share with group" select Fix: Todos Filter Shows All Users Fix: Guest sees some repository details and gets 404 Move shared params to a helper GrapeDSL for project hooks Update commits.scss updated styling commit SHA on branches page + added to changelog change build list height to show 6,5 builds + improve padding of list, with first/last child selectors Ignore builds directory from eslint Add changelog entry Document multiple repository storage paths Allow multiple repository storage shards to be enabled, and automatically round-robin between them Cleaned up global namespace JS Add tip for using Chrome to run and debug teaspoon tests. Add CHANGELOG entry file Add jquery.timeago.js to application.js Update match-regex to fix filename convention Move jquery.timeago to vendor directory Change a bunch of doc links to either relative or https://docs.gitlab.com. Show log corresponding to env in admin/logs ...
Diffstat (limited to 'spec')
-rw-r--r--spec/bin/changelog_spec.rb56
-rw-r--r--spec/features/admin/admin_runners_spec.rb27
-rw-r--r--spec/features/atom/dashboard_issues_spec.rb11
-rw-r--r--spec/features/atom/issues_spec.rb29
-rw-r--r--spec/features/commits_spec.rb8
-rw-r--r--spec/features/dashboard_issues_spec.rb20
-rw-r--r--spec/features/issues/filter_issues_spec.rb34
-rw-r--r--spec/features/merge_requests/edit_mr_spec.rb14
-rw-r--r--spec/features/projects/builds_spec.rb38
-rw-r--r--spec/features/projects/features_visibility_spec.rb15
-rw-r--r--spec/features/todos/todos_filtering_spec.rb53
-rw-r--r--spec/javascripts/merge_request_widget_spec.js2
-rw-r--r--spec/models/application_setting_spec.rb56
-rw-r--r--spec/models/project_spec.rb15
-rw-r--r--spec/models/user_spec.rb14
-rw-r--r--spec/requests/api/groups_spec.rb13
-rw-r--r--spec/requests/api/merge_request_diffs_spec.rb32
-rw-r--r--spec/requests/api/merge_requests_spec.rb16
-rw-r--r--spec/requests/api/settings_spec.rb1
-rw-r--r--spec/requests/ci/api/builds_spec.rb25
-rw-r--r--spec/requests/ci/api/runners_spec.rb10
21 files changed, 363 insertions, 126 deletions
diff --git a/spec/bin/changelog_spec.rb b/spec/bin/changelog_spec.rb
index 8c8bc1b0f1c..7f4298db59f 100644
--- a/spec/bin/changelog_spec.rb
+++ b/spec/bin/changelog_spec.rb
@@ -10,54 +10,38 @@ describe 'bin/changelog' do
expect(options.amend).to eq true
end
- it 'parses --force' do
- options = described_class.parse(%w[foo --force bar])
+ it 'parses --force and -f' do
+ %w[--force -f].each do |flag|
+ options = described_class.parse(%W[foo #{flag} bar])
- expect(options.force).to eq true
+ expect(options.force).to eq true
+ end
end
- it 'parses -f' do
- options = described_class.parse(%w[foo -f bar])
+ it 'parses --merge-request and -m' do
+ %w[--merge-request -m].each do |flag|
+ options = described_class.parse(%W[foo #{flag} 1234 bar])
- expect(options.force).to eq true
+ expect(options.merge_request).to eq 1234
+ end
end
- it 'parses --merge-request' do
- options = described_class.parse(%w[foo --merge-request 1234 bar])
+ it 'parses --dry-run and -n' do
+ %w[--dry-run -n].each do |flag|
+ options = described_class.parse(%W[foo #{flag} bar])
- expect(options.merge_request).to eq 1234
+ expect(options.dry_run).to eq true
+ end
end
- it 'parses -m' do
- options = described_class.parse(%w[foo -m 4321 bar])
-
- expect(options.merge_request).to eq 4321
- end
-
- it 'parses --dry-run' do
- options = described_class.parse(%w[foo --dry-run bar])
-
- expect(options.dry_run).to eq true
- end
-
- it 'parses -n' do
- options = described_class.parse(%w[foo -n bar])
-
- expect(options.dry_run).to eq true
- end
-
- it 'parses --git-username' do
+ it 'parses --git-username and -u' do
allow(described_class).to receive(:git_user_name).and_return('Jane Doe')
- options = described_class.parse(%w[foo --git-username bar])
-
- expect(options.author).to eq 'Jane Doe'
- end
- it 'parses -u' do
- allow(described_class).to receive(:git_user_name).and_return('John Smith')
- options = described_class.parse(%w[foo -u bar])
+ %w[--git-username -u].each do |flag|
+ options = described_class.parse(%W[foo #{flag} bar])
- expect(options.author).to eq 'John Smith'
+ expect(options.author).to eq 'Jane Doe'
+ end
end
it 'parses -h' do
diff --git a/spec/features/admin/admin_runners_spec.rb b/spec/features/admin/admin_runners_spec.rb
index 2f82fafc13a..d92c66b689d 100644
--- a/spec/features/admin/admin_runners_spec.rb
+++ b/spec/features/admin/admin_runners_spec.rb
@@ -7,15 +7,16 @@ describe "Admin Runners" do
describe "Runners page" do
before do
- runner = FactoryGirl.create(:ci_runner)
+ runner = FactoryGirl.create(:ci_runner, contacted_at: Time.now)
pipeline = FactoryGirl.create(:ci_pipeline)
FactoryGirl.create(:ci_build, pipeline: pipeline, runner_id: runner.id)
visit admin_runners_path
end
- it { page.has_text? "Manage Runners" }
- it { page.has_text? "To register a new runner" }
- it { page.has_text? "Runners with last contact less than a minute ago: 1" }
+ it 'has all necessary texts' do
+ expect(page).to have_text "To register a new Runner"
+ expect(page).to have_text "Runners with last contact less than a minute ago: 1"
+ end
describe 'search' do
before do
@@ -27,8 +28,10 @@ describe "Admin Runners" do
search_form.click_button 'Search'
end
- it { expect(page).to have_content("runner-foo") }
- it { expect(page).not_to have_content("runner-bar") }
+ it 'shows correct runner' do
+ expect(page).to have_content("runner-foo")
+ expect(page).not_to have_content("runner-bar")
+ end
end
end
@@ -46,8 +49,10 @@ describe "Admin Runners" do
end
describe 'projects' do
- it { expect(page).to have_content(@project1.name_with_namespace) }
- it { expect(page).to have_content(@project2.name_with_namespace) }
+ it 'contains project names' do
+ expect(page).to have_content(@project1.name_with_namespace)
+ expect(page).to have_content(@project2.name_with_namespace)
+ end
end
describe 'search' do
@@ -57,8 +62,10 @@ describe "Admin Runners" do
search_form.click_button 'Search'
end
- it { expect(page).to have_content(@project1.name_with_namespace) }
- it { expect(page).not_to have_content(@project2.name_with_namespace) }
+ it 'contains name of correct project' do
+ expect(page).to have_content(@project1.name_with_namespace)
+ expect(page).not_to have_content(@project2.name_with_namespace)
+ end
end
describe 'enable/create' do
diff --git a/spec/features/atom/dashboard_issues_spec.rb b/spec/features/atom/dashboard_issues_spec.rb
index 4dd9548cfc5..21ee6cedbae 100644
--- a/spec/features/atom/dashboard_issues_spec.rb
+++ b/spec/features/atom/dashboard_issues_spec.rb
@@ -19,6 +19,17 @@ describe "Dashboard Issues Feed", feature: true do
expect(body).to have_selector('title', text: "#{user.name} issues")
end
+ it "renders atom feed with url parameters" do
+ visit issues_dashboard_path(:atom, private_token: user.private_token, state: 'opened', assignee_id: user.id)
+
+ link = find('link[type="application/atom+xml"]')
+ params = CGI::parse(URI.parse(link[:href]).query)
+
+ expect(params).to include('private_token' => [user.private_token])
+ expect(params).to include('state' => ['opened'])
+ expect(params).to include('assignee_id' => [user.id.to_s])
+ end
+
context "issue with basic fields" do
let!(:issue2) { create(:issue, author: user, assignee: user, project: project2, description: 'test desc') }
diff --git a/spec/features/atom/issues_spec.rb b/spec/features/atom/issues_spec.rb
index 09c140868fb..863412d18eb 100644
--- a/spec/features/atom/issues_spec.rb
+++ b/spec/features/atom/issues_spec.rb
@@ -3,10 +3,14 @@ require 'spec_helper'
describe 'Issues Feed', feature: true do
describe 'GET /issues' do
let!(:user) { create(:user) }
+ let!(:group) { create(:group) }
let!(:project) { create(:project) }
let!(:issue) { create(:issue, author: user, project: project) }
- before { project.team << [user, :developer] }
+ before do
+ project.team << [user, :developer]
+ group.add_developer(user)
+ end
context 'when authenticated' do
it 'renders atom feed' do
@@ -33,5 +37,28 @@ describe 'Issues Feed', feature: true do
expect(body).to have_selector('entry summary', text: issue.title)
end
end
+
+ it "renders atom feed with url parameters for project issues" do
+ visit namespace_project_issues_path(project.namespace, project,
+ :atom, private_token: user.private_token, state: 'opened', assignee_id: user.id)
+
+ link = find('link[type="application/atom+xml"]')
+ params = CGI::parse(URI.parse(link[:href]).query)
+
+ expect(params).to include('private_token' => [user.private_token])
+ expect(params).to include('state' => ['opened'])
+ expect(params).to include('assignee_id' => [user.id.to_s])
+ end
+
+ it "renders atom feed with url parameters for group issues" do
+ visit issues_group_path(group, :atom, private_token: user.private_token, state: 'opened', assignee_id: user.id)
+
+ link = find('link[type="application/atom+xml"]')
+ params = CGI::parse(URI.parse(link[:href]).query)
+
+ expect(params).to include('private_token' => [user.private_token])
+ expect(params).to include('state' => ['opened'])
+ expect(params).to include('assignee_id' => [user.id.to_s])
+ end
end
end
diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb
index cd53a485ef4..44646ffc602 100644
--- a/spec/features/commits_spec.rb
+++ b/spec/features/commits_spec.rb
@@ -77,9 +77,11 @@ describe 'Commits' do
visit ci_status_path(pipeline)
end
- it { expect(page).to have_content pipeline.sha[0..7] }
- it { expect(page).to have_content pipeline.git_commit_message }
- it { expect(page).to have_content pipeline.git_author_name }
+ it 'shows pipeline`s data' do
+ expect(page).to have_content pipeline.sha[0..7]
+ expect(page).to have_content pipeline.git_commit_message
+ expect(page).to have_content pipeline.git_author_name
+ end
end
context 'Download artifacts' do
diff --git a/spec/features/dashboard_issues_spec.rb b/spec/features/dashboard_issues_spec.rb
index 9b54b5301e5..b898f9bc64f 100644
--- a/spec/features/dashboard_issues_spec.rb
+++ b/spec/features/dashboard_issues_spec.rb
@@ -44,6 +44,22 @@ describe "Dashboard Issues filtering", feature: true, js: true do
expect(page).to have_issuable_counts(open: 1, closed: 0, all: 1)
expect(page).to have_selector('.issue', count: 1)
end
+
+ it 'updates atom feed link' do
+ visit_issues(milestone_title: '', assignee_id: user.id)
+
+ link = find('.nav-controls a', text: 'Subscribe')
+ params = CGI::parse(URI.parse(link[:href]).query)
+ auto_discovery_link = find('link[type="application/atom+xml"]', visible: false)
+ auto_discovery_params = CGI::parse(URI.parse(auto_discovery_link[:href]).query)
+
+ expect(params).to include('private_token' => [user.private_token])
+ expect(params).to include('milestone_title' => [''])
+ expect(params).to include('assignee_id' => [user.id.to_s])
+ expect(auto_discovery_params).to include('private_token' => [user.private_token])
+ expect(auto_discovery_params).to include('milestone_title' => [''])
+ expect(auto_discovery_params).to include('assignee_id' => [user.id.to_s])
+ end
end
def show_milestone_dropdown
@@ -51,7 +67,7 @@ describe "Dashboard Issues filtering", feature: true, js: true do
expect(page).to have_selector('.dropdown-content', visible: true)
end
- def visit_issues
- visit issues_dashboard_path
+ def visit_issues(*args)
+ visit issues_dashboard_path(*args)
end
end
diff --git a/spec/features/issues/filter_issues_spec.rb b/spec/features/issues/filter_issues_spec.rb
index 78208aed46d..2798db92f0f 100644
--- a/spec/features/issues/filter_issues_spec.rb
+++ b/spec/features/issues/filter_issues_spec.rb
@@ -4,6 +4,7 @@ describe 'Filter issues', feature: true do
include WaitForAjax
let!(:project) { create(:project) }
+ let!(:group) { create(:group) }
let!(:user) { create(:user)}
let!(:milestone) { create(:milestone, project: project) }
let!(:label) { create(:label, project: project) }
@@ -11,6 +12,7 @@ describe 'Filter issues', feature: true do
before do
project.team << [user, :master]
+ group.add_developer(user)
login_as(user)
create(:issue, project: project)
end
@@ -347,4 +349,36 @@ describe 'Filter issues', feature: true do
end
end
end
+
+ it 'updates atom feed link for project issues' do
+ visit namespace_project_issues_path(project.namespace, project, milestone_title: '', assignee_id: user.id)
+
+ link = find('.nav-controls a', text: 'Subscribe')
+ params = CGI::parse(URI.parse(link[:href]).query)
+ auto_discovery_link = find('link[type="application/atom+xml"]', visible: false)
+ auto_discovery_params = CGI::parse(URI.parse(auto_discovery_link[:href]).query)
+
+ expect(params).to include('private_token' => [user.private_token])
+ expect(params).to include('milestone_title' => [''])
+ expect(params).to include('assignee_id' => [user.id.to_s])
+ expect(auto_discovery_params).to include('private_token' => [user.private_token])
+ expect(auto_discovery_params).to include('milestone_title' => [''])
+ expect(auto_discovery_params).to include('assignee_id' => [user.id.to_s])
+ end
+
+ it 'updates atom feed link for group issues' do
+ visit issues_group_path(group, milestone_title: '', assignee_id: user.id)
+
+ link = find('.nav-controls a', text: 'Subscribe')
+ params = CGI::parse(URI.parse(link[:href]).query)
+ auto_discovery_link = find('link[type="application/atom+xml"]', visible: false)
+ auto_discovery_params = CGI::parse(URI.parse(auto_discovery_link[:href]).query)
+
+ expect(params).to include('private_token' => [user.private_token])
+ expect(params).to include('milestone_title' => [''])
+ expect(params).to include('assignee_id' => [user.id.to_s])
+ expect(auto_discovery_params).to include('private_token' => [user.private_token])
+ expect(auto_discovery_params).to include('milestone_title' => [''])
+ expect(auto_discovery_params).to include('assignee_id' => [user.id.to_s])
+ end
end
diff --git a/spec/features/merge_requests/edit_mr_spec.rb b/spec/features/merge_requests/edit_mr_spec.rb
index c77e719c5df..c46bd8d449f 100644
--- a/spec/features/merge_requests/edit_mr_spec.rb
+++ b/spec/features/merge_requests/edit_mr_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
feature 'Edit Merge Request', feature: true do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
- let(:merge_request) { create(:merge_request, :with_diffs, source_project: project) }
+ let(:merge_request) { create(:merge_request, :simple, source_project: project) }
before do
project.team << [user, :master]
@@ -28,5 +28,17 @@ feature 'Edit Merge Request', feature: true do
expect(page).to have_content 'Someone edited the merge request the same time you did'
end
+
+ it 'allows to unselect "Remove source branch"' do
+ merge_request.update(merge_params: { 'force_remove_source_branch' => '1' })
+ expect(merge_request.merge_params['force_remove_source_branch']).to be_truthy
+
+ visit edit_namespace_project_merge_request_path(project.namespace, project, merge_request)
+ uncheck 'Remove source branch when merge request is accepted'
+
+ click_button 'Save changes'
+
+ expect(page).to have_content 'Remove source branch'
+ end
end
end
diff --git a/spec/features/projects/builds_spec.rb b/spec/features/projects/builds_spec.rb
index 63a23a14f20..a8022a5361f 100644
--- a/spec/features/projects/builds_spec.rb
+++ b/spec/features/projects/builds_spec.rb
@@ -79,12 +79,14 @@ describe "Builds" do
click_link "Cancel running"
end
- it { expect(page).to have_selector('.nav-links li.active', text: 'All') }
- it { expect(page).to have_content 'canceled' }
- it { expect(page).to have_content @build.short_sha }
- it { expect(page).to have_content @build.ref }
- it { expect(page).to have_content @build.name }
- it { expect(page).not_to have_link 'Cancel running' }
+ it 'shows all necessary content' do
+ expect(page).to have_selector('.nav-links li.active', text: 'All')
+ expect(page).to have_content 'canceled'
+ expect(page).to have_content @build.short_sha
+ expect(page).to have_content @build.ref
+ expect(page).to have_content @build.name
+ expect(page).not_to have_link 'Cancel running'
+ end
end
describe "GET /:project/builds/:id" do
@@ -93,10 +95,12 @@ describe "Builds" do
visit namespace_project_build_path(@project.namespace, @project, @build)
end
- it { expect(page.status_code).to eq(200) }
- it { expect(page).to have_content @commit.sha[0..7] }
- it { expect(page).to have_content @commit.git_commit_message }
- it { expect(page).to have_content @commit.git_author_name }
+ it 'shows commit`s data' do
+ expect(page.status_code).to eq(200)
+ expect(page).to have_content @commit.sha[0..7]
+ expect(page).to have_content @commit.git_commit_message
+ expect(page).to have_content @commit.git_author_name
+ end
end
context "Build from other project" do
@@ -167,7 +171,7 @@ describe "Builds" do
describe 'Variables' do
before do
- @trigger_request = create :ci_trigger_request_with_variables
+ @trigger_request = create :ci_trigger_request_with_variables
@build = create :ci_build, pipeline: @commit, trigger_request: @trigger_request
visit namespace_project_build_path(@project.namespace, @project, @build)
end
@@ -176,14 +180,14 @@ describe "Builds" do
expect(page).to have_css('.reveal-variables')
expect(page).not_to have_css('.js-build-variable')
expect(page).not_to have_css('.js-build-value')
-
+
click_button 'Reveal Variables'
expect(page).not_to have_css('.reveal-variables')
expect(page).to have_selector('.js-build-variable', text: 'TRIGGER_KEY_1')
expect(page).to have_selector('.js-build-value', text: 'TRIGGER_VALUE_1')
end
- end
+ end
end
describe "POST /:project/builds/:id/cancel" do
@@ -194,9 +198,11 @@ describe "Builds" do
click_link "Cancel"
end
- it { expect(page.status_code).to eq(200) }
- it { expect(page).to have_content 'canceled' }
- it { expect(page).to have_content 'Retry' }
+ it 'loads the page and shows all needed controls' do
+ expect(page.status_code).to eq(200)
+ expect(page).to have_content 'canceled'
+ expect(page).to have_content 'Retry'
+ end
end
context "Build from other project" do
diff --git a/spec/features/projects/features_visibility_spec.rb b/spec/features/projects/features_visibility_spec.rb
index e796ee570b7..09aa6758b5c 100644
--- a/spec/features/projects/features_visibility_spec.rb
+++ b/spec/features/projects/features_visibility_spec.rb
@@ -183,4 +183,19 @@ describe 'Edit Project Settings', feature: true do
end
end
end
+
+ # Regression spec for https://gitlab.com/gitlab-org/gitlab-ce/issues/24056
+ describe 'project statistic visibility' do
+ let!(:project) { create(:project, :private) }
+
+ before do
+ project.team << [member, :guest]
+ login_as(member)
+ visit namespace_project_path(project.namespace, project)
+ end
+
+ it "does not show project statistic for guest" do
+ expect(page).not_to have_selector('.project-stats')
+ end
+ end
end
diff --git a/spec/features/todos/todos_filtering_spec.rb b/spec/features/todos/todos_filtering_spec.rb
index b9e66243d84..d1f2bc78884 100644
--- a/spec/features/todos/todos_filtering_spec.rb
+++ b/spec/features/todos/todos_filtering_spec.rb
@@ -36,17 +36,54 @@ describe 'Dashboard > User filters todos', feature: true, js: true do
expect(page).not_to have_content project_2.name_with_namespace
end
- it 'filters by author' do
- click_button 'Author'
- within '.dropdown-menu-author' do
- fill_in 'Search authors', with: user_1.name
- click_link user_1.name
+ context "Author filter" do
+ it 'filters by author' do
+ click_button 'Author'
+
+ within '.dropdown-menu-author' do
+ fill_in 'Search authors', with: user_1.name
+ click_link user_1.name
+ end
+
+ wait_for_ajax
+
+ expect(find('.todos-list')).to have_content user_1.name
+ expect(find('.todos-list')).not_to have_content user_2.name
end
- wait_for_ajax
+ it "shows only authors of existing todos" do
+ click_button 'Author'
+
+ within '.dropdown-menu-author' do
+ # It should contain two users + "Any Author"
+ expect(page).to have_selector('.dropdown-menu-user-link', count: 3)
+ expect(page).to have_content(user_1.name)
+ expect(page).to have_content(user_2.name)
+ end
+ end
- expect(find('.todos-list')).to have_content user_1.name
- expect(find('.todos-list')).not_to have_content user_2.name
+ it "shows only authors of existing done todos" do
+ user_3 = create :user
+ user_4 = create :user
+ create(:todo, user: user_1, author: user_3, project: project_1, target: issue, action: 1, state: :done)
+ create(:todo, user: user_1, author: user_4, project: project_2, target: merge_request, action: 2, state: :done)
+
+ project_1.team << [user_3, :developer]
+ project_2.team << [user_4, :developer]
+
+ visit dashboard_todos_path(state: 'done')
+
+ click_button 'Author'
+
+ within '.dropdown-menu-author' do
+ # It should contain two users + "Any Author"
+ expect(page).to have_selector('.dropdown-menu-user-link', count: 3)
+ expect(page).to have_content(user_3.name)
+ expect(page).to have_content(user_4.name)
+ expect(page).not_to have_content(user_1.name)
+ expect(page).not_to have_content(user_2.name)
+ end
+ end
end
it 'filters by type' do
diff --git a/spec/javascripts/merge_request_widget_spec.js b/spec/javascripts/merge_request_widget_spec.js
index 1e2072f370a..49dfeab61d8 100644
--- a/spec/javascripts/merge_request_widget_spec.js
+++ b/spec/javascripts/merge_request_widget_spec.js
@@ -1,6 +1,6 @@
/* eslint-disable */
/*= require merge_request_widget */
-/*= require lib/utils/jquery.timeago.js */
+/*= require jquery.timeago.js */
(function() {
describe('MergeRequestWidget', function() {
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index cc215d252f9..2b76e056f3c 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -41,14 +41,62 @@ describe ApplicationSetting, models: true do
subject { setting }
end
- context 'repository storages inclussion' do
+ # Upgraded databases will have this sort of content
+ context 'repository_storages is a String, not an Array' do
+ before { setting.__send__(:raw_write_attribute, :repository_storages, 'default') }
+
+ it { expect(setting.repository_storages_before_type_cast).to eq('default') }
+ it { expect(setting.repository_storages).to eq(['default']) }
+ end
+
+ context 'repository storages' do
before do
- storages = { 'custom' => 'tmp/tests/custom_repositories' }
+ storages = {
+ 'custom1' => 'tmp/tests/custom_repositories_1',
+ 'custom2' => 'tmp/tests/custom_repositories_2',
+ 'custom3' => 'tmp/tests/custom_repositories_3',
+
+ }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end
- it { is_expected.to allow_value('custom').for(:repository_storage) }
- it { is_expected.not_to allow_value('alternative').for(:repository_storage) }
+ describe 'inclusion' do
+ it { is_expected.to allow_value('custom1').for(:repository_storages) }
+ it { is_expected.to allow_value(['custom2', 'custom3']).for(:repository_storages) }
+ it { is_expected.not_to allow_value('alternative').for(:repository_storages) }
+ it { is_expected.not_to allow_value(['alternative', 'custom1']).for(:repository_storages) }
+ end
+
+ describe 'presence' do
+ it { is_expected.not_to allow_value([]).for(:repository_storages) }
+ it { is_expected.not_to allow_value("").for(:repository_storages) }
+ it { is_expected.not_to allow_value(nil).for(:repository_storages) }
+ end
+
+ describe '.pick_repository_storage' do
+ it 'uses Array#sample to pick a random storage' do
+ array = double('array', sample: 'random')
+ expect(setting).to receive(:repository_storages).and_return(array)
+
+ expect(setting.pick_repository_storage).to eq('random')
+ end
+
+ describe '#repository_storage' do
+ it 'returns the first storage' do
+ setting.repository_storages = ['good', 'bad']
+
+ expect(setting.repository_storage).to eq('good')
+ end
+ end
+
+ describe '#repository_storage=' do
+ it 'overwrites repository_storages' do
+ setting.repository_storage = 'overwritten'
+
+ expect(setting.repository_storages).to eq(['overwritten'])
+ end
+ end
+ end
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index aef277357cf..0245897938c 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -837,16 +837,19 @@ describe Project, models: true do
context 'repository storage by default' do
let(:project) { create(:empty_project) }
- subject { project.repository_storage }
-
before do
- storages = { 'alternative_storage' => '/some/path' }
+ storages = {
+ 'default' => 'tmp/tests/repositories',
+ 'picked' => 'tmp/tests/repositories',
+ }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
- stub_application_setting(repository_storage: 'alternative_storage')
- allow_any_instance_of(Project).to receive(:ensure_dir_exist).and_return(true)
end
- it { is_expected.to eq('alternative_storage') }
+ it 'picks storage from ApplicationSetting' do
+ expect_any_instance_of(ApplicationSetting).to receive(:pick_repository_storage).and_return('picked')
+
+ expect(project.repository_storage).to eq('picked')
+ end
end
context 'shared runners by default' do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index d1ed774a914..ba47479a2e1 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -256,6 +256,20 @@ describe User, models: true do
expect(users_without_two_factor).not_to include(user_with_2fa.id)
end
end
+
+ describe '.todo_authors' do
+ it 'filters users' do
+ create :user
+ user_2 = create :user
+ user_3 = create :user
+ current_user = create :user
+ create(:todo, user: current_user, author: user_2, state: :done)
+ create(:todo, user: current_user, author: user_3, state: :pending)
+
+ expect(User.todo_authors(current_user.id, 'pending')).to eq [user_3]
+ expect(User.todo_authors(current_user.id, 'done')).to eq [user_2]
+ end
+ end
end
describe "Respond to" do
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index 3ba257256a0..7b47bf5afc1 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -37,7 +37,7 @@ describe API::API, api: true do
end
end
- context "when authenticated as admin" do
+ context "when authenticated as admin" do
it "admin: returns an array of all groups" do
get api("/groups", admin)
expect(response).to have_http_status(200)
@@ -55,6 +55,17 @@ describe API::API, api: true do
expect(json_response.length).to eq(1)
end
end
+
+ context "when using all_available in request" do
+ it "returns all groups you have access to" do
+ public_group = create :group, :public
+ get api("/groups", user1), all_available: true
+
+ expect(response).to have_http_status(200)
+ expect(json_response).to be_an Array
+ expect(json_response.first['name']).to eq(public_group.name)
+ end
+ end
end
describe "GET /groups/:id" do
diff --git a/spec/requests/api/merge_request_diffs_spec.rb b/spec/requests/api/merge_request_diffs_spec.rb
index 8f1e5ac9891..131c2d406ea 100644
--- a/spec/requests/api/merge_request_diffs_spec.rb
+++ b/spec/requests/api/merge_request_diffs_spec.rb
@@ -14,14 +14,14 @@ describe API::API, 'MergeRequestDiffs', api: true do
end
describe 'GET /projects/:id/merge_requests/:merge_request_id/versions' do
- context 'valid merge request' do
- before { get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user) }
- let(:merge_request_diff) { merge_request.merge_request_diffs.first }
-
- it { expect(response.status).to eq 200 }
- it { expect(json_response.size).to eq(merge_request.merge_request_diffs.size) }
- it { expect(json_response.first['id']).to eq(merge_request_diff.id) }
- it { expect(json_response.first['head_commit_sha']).to eq(merge_request_diff.head_commit_sha) }
+ it 'returns 200 for a valid merge request' do
+ get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user)
+ merge_request_diff = merge_request.merge_request_diffs.first
+
+ expect(response.status).to eq 200
+ expect(json_response.size).to eq(merge_request.merge_request_diffs.size)
+ expect(json_response.first['id']).to eq(merge_request_diff.id)
+ expect(json_response.first['head_commit_sha']).to eq(merge_request_diff.head_commit_sha)
end
it 'returns a 404 when merge_request_id not found' do
@@ -31,14 +31,14 @@ describe API::API, 'MergeRequestDiffs', api: true do
end
describe 'GET /projects/:id/merge_requests/:merge_request_id/versions/:version_id' do
- context 'valid merge request' do
- before { get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user) }
- let(:merge_request_diff) { merge_request.merge_request_diffs.first }
-
- it { expect(response.status).to eq 200 }
- it { expect(json_response['id']).to eq(merge_request_diff.id) }
- it { expect(json_response['head_commit_sha']).to eq(merge_request_diff.head_commit_sha) }
- it { expect(json_response['diffs'].size).to eq(merge_request_diff.diffs.size) }
+ it 'returns a 200 for a valid merge request' do
+ merge_request_diff = merge_request.merge_request_diffs.first
+ get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user)
+
+ expect(response.status).to eq 200
+ expect(json_response['id']).to eq(merge_request_diff.id)
+ expect(json_response['head_commit_sha']).to eq(merge_request_diff.head_commit_sha)
+ expect(json_response['diffs'].size).to eq(merge_request_diff.diffs.size)
end
it 'returns a 404 when merge_request_id not found' do
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index b813ee967f8..bae4fa11ec2 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -186,14 +186,14 @@ describe API::API, api: true do
end
describe 'GET /projects/:id/merge_requests/:merge_request_id/commits' do
- context 'valid merge request' do
- before { get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/commits", user) }
- let(:commit) { merge_request.commits.first }
-
- it { expect(response.status).to eq 200 }
- it { expect(json_response.size).to eq(merge_request.commits.size) }
- it { expect(json_response.first['id']).to eq(commit.id) }
- it { expect(json_response.first['title']).to eq(commit.title) }
+ it 'returns a 200 when merge request is valid' do
+ get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/commits", user)
+ commit = merge_request.commits.first
+
+ expect(response.status).to eq 200
+ expect(json_response.size).to eq(merge_request.commits.size)
+ expect(json_response.first['id']).to eq(commit.id)
+ expect(json_response.first['title']).to eq(commit.title)
end
it 'returns a 404 when merge_request_id not found' do
diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb
index f4903d8e0be..096a8ebab70 100644
--- a/spec/requests/api/settings_spec.rb
+++ b/spec/requests/api/settings_spec.rb
@@ -33,6 +33,7 @@ describe API::API, 'Settings', api: true do
expect(json_response['default_projects_limit']).to eq(3)
expect(json_response['signin_enabled']).to be_falsey
expect(json_response['repository_storage']).to eq('custom')
+ expect(json_response['repository_storages']).to eq(['custom'])
expect(json_response['koding_enabled']).to be_truthy
expect(json_response['koding_url']).to eq('http://koding.example.com')
end
diff --git a/spec/requests/ci/api/builds_spec.rb b/spec/requests/ci/api/builds_spec.rb
index 7b7d62feb2c..6d49c42c215 100644
--- a/spec/requests/ci/api/builds_spec.rb
+++ b/spec/requests/ci/api/builds_spec.rb
@@ -220,26 +220,33 @@ describe Ci::API::API do
end
context 'when request is valid' do
- it { expect(response.status).to eq 202 }
+ it 'gets correct response' do
+ expect(response.status).to eq 202
+ expect(response.header).to have_key 'Range'
+ expect(response.header).to have_key 'Build-Status'
+ end
+
it { expect(build.reload.trace).to eq 'BUILD TRACE appended' }
- it { expect(response.header).to have_key 'Range' }
- it { expect(response.header).to have_key 'Build-Status' }
end
context 'when content-range start is too big' do
let(:headers_with_range) { headers.merge({ 'Content-Range' => '15-20' }) }
- it { expect(response.status).to eq 416 }
- it { expect(response.header).to have_key 'Range' }
- it { expect(response.header['Range']).to eq '0-11' }
+ it 'gets correct response' do
+ expect(response.status).to eq 416
+ expect(response.header).to have_key 'Range'
+ expect(response.header['Range']).to eq '0-11'
+ end
end
context 'when content-range start is too small' do
let(:headers_with_range) { headers.merge({ 'Content-Range' => '8-20' }) }
- it { expect(response.status).to eq 416 }
- it { expect(response.header).to have_key 'Range' }
- it { expect(response.header['Range']).to eq '0-11' }
+ it 'gets correct response' do
+ expect(response.status).to eq 416
+ expect(response.header).to have_key 'Range'
+ expect(response.header['Range']).to eq '0-11'
+ end
end
context 'when Content-Range header is missing' do
diff --git a/spec/requests/ci/api/runners_spec.rb b/spec/requests/ci/api/runners_spec.rb
index 43596f07cb5..d6c26fd8a94 100644
--- a/spec/requests/ci/api/runners_spec.rb
+++ b/spec/requests/ci/api/runners_spec.rb
@@ -109,10 +109,12 @@ describe Ci::API::API do
end
describe "DELETE /runners/delete" do
- let!(:runner) { FactoryGirl.create(:ci_runner) }
- before { delete ci_api("/runners/delete"), token: runner.token }
+ it 'returns 200' do
+ runner = FactoryGirl.create(:ci_runner)
+ delete ci_api("/runners/delete"), token: runner.token
- it { expect(response).to have_http_status 200 }
- it { expect(Ci::Runner.count).to eq(0) }
+ expect(response).to have_http_status 200
+ expect(Ci::Runner.count).to eq(0)
+ end
end
end