summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/milestones_controller_spec.rb28
-rw-r--r--spec/controllers/projects/tree_controller_spec.rb (renamed from spec/controllers/tree_controller_spec.rb)29
-rw-r--r--spec/controllers/users_controller_spec.rb35
-rw-r--r--spec/factories/projects.rb3
-rw-r--r--spec/features/markdown_spec.rb427
-rw-r--r--spec/features/security/admin_access_spec.rb (renamed from spec/features/admin/security_spec.rb)2
-rw-r--r--spec/features/security/dashboard_access_spec.rb2
-rw-r--r--spec/features/security/group/group_access_spec.rb98
-rw-r--r--spec/features/security/group/internal_group_access_spec.rb82
-rw-r--r--spec/features/security/group/mixed_group_access_spec.rb83
-rw-r--r--spec/features/security/group/public_group_access_spec.rb82
-rw-r--r--spec/features/security/group_access_spec.rb284
-rw-r--r--spec/features/security/profile_access_spec.rb14
-rw-r--r--spec/features/security/project/internal_access_spec.rb2
-rw-r--r--spec/features/security/project/private_access_spec.rb2
-rw-r--r--spec/features/security/project/public_access_spec.rb3
-rw-r--r--spec/fixtures/GoogleCodeProjectHosting.json5
-rw-r--r--spec/fixtures/markdown.md.erb13
-rw-r--r--spec/helpers/auth_helper_spec.rb20
-rw-r--r--spec/helpers/blob_helper_spec.rb18
-rw-r--r--spec/helpers/oauth_helper_spec.rb20
-rw-r--r--spec/helpers/projects_helper_spec.rb20
-rw-r--r--spec/javascripts/fixtures/line_highlighter.html.haml4
-rw-r--r--spec/javascripts/line_highlighter_spec.js.coffee8
-rw-r--r--spec/javascripts/merge_request_tabs_spec.js.coffee6
-rw-r--r--spec/lib/gitlab/google_code_import/importer_spec.rb1
-rw-r--r--spec/lib/gitlab/markdown/relative_link_filter_spec.rb16
-rw-r--r--spec/models/application_setting_spec.rb5
-rw-r--r--spec/models/project_services/gitlab_ci_service_spec.rb27
-rw-r--r--spec/models/project_spec.rb21
-rw-r--r--spec/models/user_spec.rb13
-rw-r--r--spec/requests/api/branches_spec.rb5
-rw-r--r--spec/requests/api/merge_requests_spec.rb6
-rw-r--r--spec/requests/api/projects_spec.rb2
-rw-r--r--spec/requests/api/services_spec.rb14
-rw-r--r--spec/requests/api/users_spec.rb171
-rw-r--r--spec/services/projects/create_service_spec.rb12
-rw-r--r--spec/services/projects/fork_service_spec.rb2
-rw-r--r--spec/support/markdown_feature.rb106
-rw-r--r--spec/support/matchers.rb66
-rw-r--r--spec/support/matchers/access_matchers.rb54
-rw-r--r--spec/support/matchers/include_module.rb13
-rw-r--r--spec/support/matchers/is_within.rb9
-rw-r--r--spec/support/matchers/markdown_matchers.rb156
-rw-r--r--spec/support/test_env.rb19
-rw-r--r--spec/tasks/gitlab/backup_rake_spec.rb52
46 files changed, 1251 insertions, 809 deletions
diff --git a/spec/controllers/projects/milestones_controller_spec.rb b/spec/controllers/projects/milestones_controller_spec.rb
new file mode 100644
index 00000000000..d3868c13202
--- /dev/null
+++ b/spec/controllers/projects/milestones_controller_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe Projects::MilestonesController do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+ let(:milestone) { create(:milestone, project: project) }
+ let(:issue) { create(:issue, project: project, milestone: milestone) }
+
+ before do
+ sign_in(user)
+ project.team << [user, :master]
+ controller.instance_variable_set(:@project, project)
+ end
+
+ describe "#destroy" do
+ it "should remove milestone" do
+ expect(issue.milestone_id).to eq(milestone.id)
+ delete :destroy, namespace_id: project.namespace.id, project_id: project.id, id: milestone.id, format: :js
+ expect(response).to be_success
+ expect { Milestone.find(milestone.id) }.to raise_exception(ActiveRecord::RecordNotFound)
+ issue.reload
+ expect(issue.milestone_id).to eq(nil)
+ # Check system note left for milestone removal
+ last_note = project.issues.find(issue.id).notes[-1].note
+ expect(last_note).to eq('Milestone removed')
+ end
+ end
+end
diff --git a/spec/controllers/tree_controller_spec.rb b/spec/controllers/projects/tree_controller_spec.rb
index e09caf5df13..53915856357 100644
--- a/spec/controllers/tree_controller_spec.rb
+++ b/spec/controllers/projects/tree_controller_spec.rb
@@ -8,9 +8,6 @@ describe Projects::TreeController do
sign_in(user)
project.team << [user, :master]
-
- allow(project).to receive(:branches).and_return(['master', 'foo/bar/baz'])
- allow(project).to receive(:tags).and_return(['v1.0.0', 'v2.0.0'])
controller.instance_variable_set(:@project, project)
end
@@ -44,6 +41,32 @@ describe Projects::TreeController do
let(:id) { 'invalid-branch/encoding/' }
it { is_expected.to respond_with(:not_found) }
end
+
+ context "valid empty branch, invalid path" do
+ let(:id) { 'empty-branch/invalid-path/' }
+ it { is_expected.to respond_with(:not_found) }
+ end
+
+ context "valid empty branch" do
+ let(:id) { 'empty-branch' }
+ it { is_expected.to respond_with(:success) }
+ end
+
+ context "invalid SHA commit ID" do
+ let(:id) { 'ff39438/.gitignore' }
+ it { is_expected.to respond_with(:not_found) }
+ end
+
+ context "valid SHA commit ID" do
+ let(:id) { '6d39438' }
+ it { is_expected.to respond_with(:success) }
+ end
+
+ context "valid SHA commit ID with path" do
+ let(:id) { '6d39438/.gitignore' }
+ it { expect(response.status).to eq(302) }
+ end
+
end
describe 'GET show with blob path' do
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index d47a37914df..9f89101d7f7 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -1,25 +1,38 @@
require 'spec_helper'
describe UsersController do
- let(:user) { create(:user, username: 'user1', name: 'User 1', email: 'user1@gitlab.com') }
-
- before do
- sign_in(user)
- end
+ let(:user) { create(:user) }
describe 'GET #show' do
- render_views
+ it 'is case-insensitive' do
+ user = create(:user, username: 'CamelCaseUser')
+ sign_in(user)
+
+ get :show, username: user.username.downcase
- it 'renders the show template' do
- get :show, username: user.username
- expect(response.status).to eq(200)
- expect(response).to render_template('show')
+ expect(response).to be_success
+ end
+
+ context 'with rendered views' do
+ render_views
+
+ it 'renders the show template' do
+ sign_in(user)
+
+ get :show, username: user.username
+
+ expect(response).to be_success
+ expect(response).to render_template('show')
+ end
end
end
describe 'GET #calendar' do
it 'renders calendar' do
+ sign_in(user)
+
get :calendar, username: user.username
+
expect(response).to render_template('calendar')
end
end
@@ -30,6 +43,8 @@ describe UsersController do
before do
allow_any_instance_of(User).to receive(:contributed_projects_ids).and_return([project.id])
+
+ sign_in(user)
project.team << [user, :developer]
end
diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb
index 102678a1d74..1d500a11ad7 100644
--- a/spec/factories/projects.rb
+++ b/spec/factories/projects.rb
@@ -21,12 +21,13 @@
# import_url :string(255)
# visibility_level :integer default(0), not null
# archived :boolean default(FALSE), not null
+# avatar :string(255)
# import_status :string(255)
# repository_size :float default(0.0)
# star_count :integer default(0), not null
# import_type :string(255)
# import_source :string(255)
-# avatar :string(255)
+# commit_count :integer default(0)
#
FactoryGirl.define do
diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb
index b8199aa5e61..859a62f740f 100644
--- a/spec/features/markdown_spec.rb
+++ b/spec/features/markdown_spec.rb
@@ -17,410 +17,215 @@ require 'erb'
# -> Post-process HTML
# -> `gfm_with_options` helper
# -> HTML::Pipeline
-# -> Sanitize
-# -> RelativeLink
-# -> Emoji
-# -> Table of Contents
-# -> Autolinks
-# -> Rinku (http, https, ftp)
-# -> Other schemes
-# -> ExternalLink
-# -> References
-# -> TaskList
+# -> SanitizationFilter
+# -> Other filters, depending on pipeline
# -> `html_safe`
# -> Template
#
# See the MarkdownFeature class for setup details.
describe 'GitLab Markdown', feature: true do
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::UrlHelper
include Capybara::Node::Matchers
include GitlabMarkdownHelper
+ include MarkdownMatchers
- # `markdown` calls these two methods
- def current_user
- @feat.user
- end
-
- def user_color_scheme_class
- :white
- end
-
- # Let's only parse this thing once
- before(:all) do
- @feat = MarkdownFeature.new
-
- # `markdown` expects a `@project` variable
- @project = @feat.project
-
- @md = markdown(@feat.raw_markdown)
- @doc = Nokogiri::HTML::DocumentFragment.parse(@md)
- end
-
- after(:all) do
- @feat.teardown
+ # Sometimes it can be useful to see the parsed output of the Markdown document
+ # for debugging. Call this method to write the output to
+ # `tmp/capybara/<filename>.html`.
+ def write_markdown(filename = 'markdown_spec')
+ File.open(Rails.root.join("tmp/capybara/#{filename}.html"), 'w') do |file|
+ file.puts @html
+ end
end
- # Given a header ID, goes to that element's parent (the header itself), then
- # its next sibling element (the body).
- def get_section(id)
- @doc.at_css("##{id}").parent.next_element
+ def doc(html = @html)
+ Nokogiri::HTML::DocumentFragment.parse(html)
end
- # Sometimes it can be useful to see the parsed output of the Markdown document
- # for debugging. Uncomment this block to write the output to
- # tmp/capybara/markdown_spec.html.
- #
- # it 'writes to a file' do
- # File.open(Rails.root.join('tmp/capybara/markdown_spec.html'), 'w') do |file|
- # file.puts @md
- # end
- # end
-
- describe 'Markdown' do
- describe 'No Intra Emphasis' do
+ # Shared behavior that all pipelines should exhibit
+ shared_examples 'all pipelines' do
+ describe 'Redcarpet extensions' do
it 'does not parse emphasis inside of words' do
- body = get_section('no-intra-emphasis')
- expect(body.to_html).not_to match('foo<em>bar</em>baz')
+ expect(doc.to_html).not_to match('foo<em>bar</em>baz')
end
- end
- describe 'Tables' do
it 'parses table Markdown' do
- body = get_section('tables')
- expect(body).to have_selector('th:contains("Header")')
- expect(body).to have_selector('th:contains("Row")')
- expect(body).to have_selector('th:contains("Example")')
+ aggregate_failures do
+ expect(doc).to have_selector('th:contains("Header")')
+ expect(doc).to have_selector('th:contains("Row")')
+ expect(doc).to have_selector('th:contains("Example")')
+ end
end
it 'allows Markdown in tables' do
- expect(@doc.at_css('td:contains("Baz")').children.to_html).
+ expect(doc.at_css('td:contains("Baz")').children.to_html).
to eq '<strong>Baz</strong>'
end
- end
- describe 'Fenced Code Blocks' do
it 'parses fenced code blocks' do
- expect(@doc).to have_selector('pre.code.highlight.white.c')
- expect(@doc).to have_selector('pre.code.highlight.white.python')
+ aggregate_failures do
+ expect(doc).to have_selector('pre.code.highlight.white.c')
+ expect(doc).to have_selector('pre.code.highlight.white.python')
+ end
end
- end
- describe 'Strikethrough' do
it 'parses strikethroughs' do
- expect(@doc).to have_selector(%{del:contains("and this text doesn't")})
+ expect(doc).to have_selector(%{del:contains("and this text doesn't")})
end
- end
- describe 'Superscript' do
it 'parses superscript' do
- body = get_section('superscript')
- expect(body.to_html).to match('1<sup>st</sup>')
- expect(body.to_html).to match('2<sup>nd</sup>')
+ expect(doc).to have_selector('sup', count: 2)
end
end
- end
- describe 'HTML::Pipeline' do
describe 'SanitizationFilter' do
- it 'uses a permissive whitelist' do
- expect(@doc).to have_selector('b:contains("b tag")')
- expect(@doc).to have_selector('em:contains("em tag")')
- expect(@doc).to have_selector('code:contains("code tag")')
- expect(@doc).to have_selector('kbd:contains("s")')
- expect(@doc).to have_selector('strike:contains(Emoji)')
- expect(@doc).to have_selector('img[src*="smile.png"]')
- expect(@doc).to have_selector('br')
- expect(@doc).to have_selector('hr')
+ it 'permits b elements' do
+ expect(doc).to have_selector('b:contains("b tag")')
end
- it 'permits span elements' do
- expect(@doc).to have_selector('span:contains("span tag")')
+ it 'permits em elements' do
+ expect(doc).to have_selector('em:contains("em tag")')
end
- it 'permits table alignment' do
- expect(@doc.at_css('th:contains("Header")')['style']).to eq 'text-align: center'
- expect(@doc.at_css('th:contains("Row")')['style']).to eq 'text-align: right'
- expect(@doc.at_css('th:contains("Example")')['style']).to eq 'text-align: left'
-
- expect(@doc.at_css('td:contains("Foo")')['style']).to eq 'text-align: center'
- expect(@doc.at_css('td:contains("Bar")')['style']).to eq 'text-align: right'
- expect(@doc.at_css('td:contains("Baz")')['style']).to eq 'text-align: left'
+ it 'permits code elements' do
+ expect(doc).to have_selector('code:contains("code tag")')
end
- it 'removes `rel` attribute from links' do
- body = get_section('sanitizationfilter')
- expect(body).not_to have_selector('a[rel="bookmark"]')
+ it 'permits kbd elements' do
+ expect(doc).to have_selector('kbd:contains("s")')
end
- it "removes `href` from `a` elements if it's fishy" do
- expect(@doc).not_to have_selector('a[href*="javascript"]')
+ it 'permits strike elements' do
+ expect(doc).to have_selector('strike:contains(Emoji)')
end
- end
- describe 'Escaping' do
- let(:table) { @doc.css('table').last.at_css('tbody') }
-
- it 'escapes non-tag angle brackets' do
- expect(table.at_xpath('.//tr[1]/td[3]').inner_html).to eq '1 &lt; 3 &amp; 5'
+ it 'permits img elements' do
+ expect(doc).to have_selector('img[src*="smile.png"]')
end
- end
-
- describe 'Edge Cases' do
- it 'allows markup inside link elements' do
- expect(@doc.at_css('a[href="#link-emphasis"]').to_html).
- to eq %{<a href="#link-emphasis"><em>text</em></a>}
-
- expect(@doc.at_css('a[href="#link-strong"]').to_html).
- to eq %{<a href="#link-strong"><strong>text</strong></a>}
- expect(@doc.at_css('a[href="#link-code"]').to_html).
- to eq %{<a href="#link-code"><code>text</code></a>}
+ it 'permits br elements' do
+ expect(doc).to have_selector('br')
end
- end
- describe 'EmojiFilter' do
- it 'parses Emoji' do
- expect(@doc).to have_selector('img.emoji', count: 10)
+ it 'permits hr elements' do
+ expect(doc).to have_selector('hr')
end
- end
- describe 'TableOfContentsFilter' do
- it 'creates anchors inside header elements' do
- expect(@doc).to have_selector('h1 a#gitlab-markdown')
- expect(@doc).to have_selector('h2 a#markdown')
- expect(@doc).to have_selector('h3 a#autolinkfilter')
+ it 'permits span elements' do
+ expect(doc).to have_selector('span:contains("span tag")')
end
- end
- describe 'AutolinkFilter' do
- let(:list) { get_section('autolinkfilter').next_element }
-
- def item(index)
- list.at_css("li:nth-child(#{index})")
+ it 'permits style attribute in th elements' do
+ aggregate_failures do
+ expect(doc.at_css('th:contains("Header")')['style']).to eq 'text-align: center'
+ expect(doc.at_css('th:contains("Row")')['style']).to eq 'text-align: right'
+ expect(doc.at_css('th:contains("Example")')['style']).to eq 'text-align: left'
+ end
end
- it 'autolinks http://' do
- expect(item(1).children.first.name).to eq 'a'
- expect(item(1).children.first['href']).to eq 'http://about.gitlab.com/'
+ it 'permits style attribute in td elements' do
+ aggregate_failures do
+ expect(doc.at_css('td:contains("Foo")')['style']).to eq 'text-align: center'
+ expect(doc.at_css('td:contains("Bar")')['style']).to eq 'text-align: right'
+ expect(doc.at_css('td:contains("Baz")')['style']).to eq 'text-align: left'
+ end
end
- it 'autolinks https://' do
- expect(item(2).children.first.name).to eq 'a'
- expect(item(2).children.first['href']).to eq 'https://google.com/'
+ it 'removes `rel` attribute from links' do
+ expect(doc).not_to have_selector('a[rel="bookmark"]')
end
- it 'autolinks ftp://' do
- expect(item(3).children.first.name).to eq 'a'
- expect(item(3).children.first['href']).to eq 'ftp://ftp.us.debian.org/debian/'
+ it "removes `href` from `a` elements if it's fishy" do
+ expect(doc).not_to have_selector('a[href*="javascript"]')
end
+ end
- it 'autolinks smb://' do
- expect(item(4).children.first.name).to eq 'a'
- expect(item(4).children.first['href']).to eq 'smb://foo/bar/baz'
+ describe 'Escaping' do
+ it 'escapes non-tag angle brackets' do
+ table = doc.css('table').last.at_css('tbody')
+ expect(table.at_xpath('.//tr[1]/td[3]').inner_html).to eq '1 &lt; 3 &amp; 5'
end
+ end
- it 'autolinks irc://' do
- expect(item(5).children.first.name).to eq 'a'
- expect(item(5).children.first['href']).to eq 'irc://irc.freenode.net/git'
- end
+ describe 'Edge Cases' do
+ it 'allows markup inside link elements' do
+ aggregate_failures do
+ expect(doc.at_css('a[href="#link-emphasis"]').to_html).
+ to eq %{<a href="#link-emphasis"><em>text</em></a>}
- it 'autolinks short, invalid URLs' do
- expect(item(6).children.first.name).to eq 'a'
- expect(item(6).children.first['href']).to eq 'http://localhost:3000'
- end
+ expect(doc.at_css('a[href="#link-strong"]').to_html).
+ to eq %{<a href="#link-strong"><strong>text</strong></a>}
- %w(code a kbd).each do |elem|
- it "ignores links inside '#{elem}' element" do
- body = get_section('autolinkfilter')
- expect(body).not_to have_selector("#{elem} a")
+ expect(doc.at_css('a[href="#link-code"]').to_html).
+ to eq %{<a href="#link-code"><code>text</code></a>}
end
end
end
describe 'ExternalLinkFilter' do
- let(:links) { get_section('externallinkfilter').next_element }
-
it 'adds nofollow to external link' do
- expect(links.css('a').first.to_html).to match 'nofollow'
+ link = doc.at_css('a:contains("Google")')
+ expect(link.attr('rel')).to match 'nofollow'
end
it 'ignores internal link' do
- expect(links.css('a').last.to_html).not_to match 'nofollow'
+ link = doc.at_css('a:contains("GitLab Root")')
+ expect(link.attr('rel')).not_to match 'nofollow'
end
end
+ end
- describe 'ReferenceFilter' do
- it 'handles references in headers' do
- header = @doc.at_css('#reference-filters-eg-1').parent
-
- expect(header.css('a').size).to eq 2
- end
-
- it "handles references in Markdown" do
- body = get_section('reference-filters-eg-1')
- expect(body).to have_selector('em a.gfm-merge_request', count: 1)
- end
-
- it 'parses user references' do
- body = get_section('userreferencefilter')
- expect(body).to have_selector('a.gfm.gfm-project_member', count: 3)
- end
-
- it 'parses issue references' do
- body = get_section('issuereferencefilter')
- expect(body).to have_selector('a.gfm.gfm-issue', count: 2)
- end
-
- it 'parses merge request references' do
- body = get_section('mergerequestreferencefilter')
- expect(body).to have_selector('a.gfm.gfm-merge_request', count: 2)
- end
+ context 'default pipeline' do
+ before(:all) do
+ @feat = MarkdownFeature.new
- it 'parses snippet references' do
- body = get_section('snippetreferencefilter')
- expect(body).to have_selector('a.gfm.gfm-snippet', count: 2)
- end
+ # `gfm_with_options` depends on a `@project` variable
+ @project = @feat.project
- it 'parses commit range references' do
- body = get_section('commitrangereferencefilter')
- expect(body).to have_selector('a.gfm.gfm-commit_range', count: 2)
- end
+ @html = markdown(@feat.raw_markdown)
+ end
- it 'parses commit references' do
- body = get_section('commitreferencefilter')
- expect(body).to have_selector('a.gfm.gfm-commit', count: 2)
- end
+ it_behaves_like 'all pipelines'
- it 'parses label references' do
- body = get_section('labelreferencefilter')
- expect(body).to have_selector('a.gfm.gfm-label', count: 3)
- end
+ it 'includes RelativeLinkFilter' do
+ expect(doc).to parse_relative_links
end
- describe 'Task Lists' do
- it 'generates task lists' do
- body = get_section('task-lists')
- expect(body).to have_selector('ul.task-list', count: 2)
- expect(body).to have_selector('li.task-list-item', count: 7)
- expect(body).to have_selector('input[checked]', count: 3)
- end
+ it 'includes EmojiFilter' do
+ expect(doc).to parse_emoji
end
- end
-end
-
-# This is a helper class used by the GitLab Markdown feature spec
-#
-# Because the feature spec only cares about the output of the Markdown, and the
-# test setup and teardown and parsing is fairly expensive, we only want to do it
-# once. Unfortunately RSpec will not let you access `let`s in a `before(:all)`
-# block, so we fake it by encapsulating all the shared setup in this class.
-#
-# The class renders `spec/fixtures/markdown.md.erb` using ERB, allowing for
-# reference to the factory-created objects.
-class MarkdownFeature
- include FactoryGirl::Syntax::Methods
-
- def initialize
- DatabaseCleaner.start
- end
-
- def teardown
- DatabaseCleaner.clean
- end
-
- def user
- @user ||= create(:user)
- end
- def group
- unless @group
- @group = create(:group)
- @group.add_user(user, Gitlab::Access::DEVELOPER)
+ it 'includes TableOfContentsFilter' do
+ expect(doc).to create_header_links
end
- @group
- end
-
- # Direct references ----------------------------------------------------------
-
- def project
- @project ||= create(:project)
- end
-
- def issue
- @issue ||= create(:issue, project: project)
- end
-
- def merge_request
- @merge_request ||= create(:merge_request, :simple, source_project: project)
- end
-
- def snippet
- @snippet ||= create(:project_snippet, project: project)
- end
-
- def commit
- @commit ||= project.commit
- end
-
- def commit_range
- unless @commit_range
- commit2 = project.commit('HEAD~3')
- @commit_range = CommitRange.new("#{commit.id}...#{commit2.id}", project)
+ it 'includes AutolinkFilter' do
+ expect(doc).to create_autolinks
end
- @commit_range
- end
-
- def simple_label
- @simple_label ||= create(:label, name: 'gfm', project: project)
- end
-
- def label
- @label ||= create(:label, name: 'awaiting feedback', project: project)
- end
-
- # Cross-references -----------------------------------------------------------
-
- def xproject
- unless @xproject
- namespace = create(:namespace, name: 'cross-reference')
- @xproject = create(:project, namespace: namespace)
- @xproject.team << [user, :developer]
+ it 'includes all reference filters' do
+ aggregate_failures do
+ expect(doc).to reference_users
+ expect(doc).to reference_issues
+ expect(doc).to reference_merge_requests
+ expect(doc).to reference_snippets
+ expect(doc).to reference_commit_ranges
+ expect(doc).to reference_commits
+ expect(doc).to reference_labels
+ end
end
- @xproject
- end
-
- def xissue
- @xissue ||= create(:issue, project: xproject)
- end
-
- def xmerge_request
- @xmerge_request ||= create(:merge_request, :simple, source_project: xproject)
- end
-
- def xsnippet
- @xsnippet ||= create(:project_snippet, project: xproject)
- end
-
- def xcommit
- @xcommit ||= xproject.commit
- end
-
- def xcommit_range
- unless @xcommit_range
- xcommit2 = xproject.commit('HEAD~2')
- @xcommit_range = CommitRange.new("#{xcommit.id}...#{xcommit2.id}", xproject)
+ it 'includes TaskListFilter' do
+ expect(doc).to parse_task_lists
end
+ end
- @xcommit_range
+ # `markdown` calls these two methods
+ def current_user
+ @feat.user
end
- def raw_markdown
- fixture = Rails.root.join('spec/fixtures/markdown.md.erb')
- ERB.new(File.read(fixture)).result(binding)
+ def user_color_scheme_class
+ :white
end
end
diff --git a/spec/features/admin/security_spec.rb b/spec/features/security/admin_access_spec.rb
index 175fa9d4647..fe8cd7b7602 100644
--- a/spec/features/admin/security_spec.rb
+++ b/spec/features/security/admin_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Admin::Projects", feature: true do
+ include AccessMatchers
+
describe "GET /admin/projects" do
subject { admin_namespaces_projects_path }
diff --git a/spec/features/security/dashboard_access_spec.rb b/spec/features/security/dashboard_access_spec.rb
index 67238e3ab76..c38cddbb904 100644
--- a/spec/features/security/dashboard_access_spec.rb
+++ b/spec/features/security/dashboard_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Dashboard access", feature: true do
+ include AccessMatchers
+
describe "GET /dashboard" do
subject { dashboard_path }
diff --git a/spec/features/security/group/group_access_spec.rb b/spec/features/security/group/group_access_spec.rb
deleted file mode 100644
index 63793149459..00000000000
--- a/spec/features/security/group/group_access_spec.rb
+++ /dev/null
@@ -1,98 +0,0 @@
-require 'spec_helper'
-
-describe "Group access", feature: true do
- describe "GET /projects/new" do
- it { expect(new_group_path).to be_allowed_for :admin }
- it { expect(new_group_path).to be_allowed_for :user }
- it { expect(new_group_path).to be_denied_for :visitor }
- end
-
- describe "Group" do
- let(:group) { create(:group) }
-
- let(:owner) { create(:owner) }
- let(:master) { create(:user) }
- let(:reporter) { create(:user) }
- let(:guest) { create(:user) }
- let(:nonmember) { create(:user) }
-
- before do
- group.add_user(owner, Gitlab::Access::OWNER)
- group.add_user(master, Gitlab::Access::MASTER)
- group.add_user(reporter, Gitlab::Access::REPORTER)
- group.add_user(guest, Gitlab::Access::GUEST)
- end
-
- describe "GET /groups/:path" do
- subject { group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_denied_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
-
- describe "GET /groups/:path/issues" do
- subject { issues_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_denied_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
-
- describe "GET /groups/:path/merge_requests" do
- subject { merge_requests_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_denied_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
-
- describe "GET /groups/:path/group_members" do
- subject { group_group_members_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_denied_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
-
- describe "GET /groups/:path/edit" do
- subject { edit_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_denied_for master }
- it { is_expected.to be_denied_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_denied_for guest }
- it { is_expected.to be_denied_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
-
- describe "GET /groups/:path/projects" do
- subject { projects_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_denied_for master }
- it { is_expected.to be_denied_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_denied_for guest }
- it { is_expected.to be_denied_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
- end
-end
diff --git a/spec/features/security/group/internal_group_access_spec.rb b/spec/features/security/group/internal_group_access_spec.rb
deleted file mode 100644
index d17a7412e43..00000000000
--- a/spec/features/security/group/internal_group_access_spec.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-require 'spec_helper'
-
-describe "Group with internal project access", feature: true do
- describe "Group" do
- let(:group) { create(:group) }
-
- let(:owner) { create(:owner) }
- let(:master) { create(:user) }
- let(:reporter) { create(:user) }
- let(:guest) { create(:user) }
- let(:nonmember) { create(:user) }
-
- before do
- group.add_user(owner, Gitlab::Access::OWNER)
- group.add_user(master, Gitlab::Access::MASTER)
- group.add_user(reporter, Gitlab::Access::REPORTER)
- group.add_user(guest, Gitlab::Access::GUEST)
-
- create(:project, :internal, group: group)
- end
-
- describe "GET /groups/:path" do
- subject { group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
-
- describe "GET /groups/:path/issues" do
- subject { issues_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
-
- describe "GET /groups/:path/merge_requests" do
- subject { merge_requests_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
-
- describe "GET /groups/:path/group_members" do
- subject { group_group_members_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
-
- describe "GET /groups/:path/edit" do
- subject { edit_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_denied_for master }
- it { is_expected.to be_denied_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_denied_for guest }
- it { is_expected.to be_denied_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
- end
-end
diff --git a/spec/features/security/group/mixed_group_access_spec.rb b/spec/features/security/group/mixed_group_access_spec.rb
deleted file mode 100644
index b3db7b5dea4..00000000000
--- a/spec/features/security/group/mixed_group_access_spec.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-require 'spec_helper'
-
-describe "Group access", feature: true do
- describe "Group" do
- let(:group) { create(:group) }
-
- let(:owner) { create(:owner) }
- let(:master) { create(:user) }
- let(:reporter) { create(:user) }
- let(:guest) { create(:user) }
- let(:nonmember) { create(:user) }
-
- before do
- group.add_user(owner, Gitlab::Access::OWNER)
- group.add_user(master, Gitlab::Access::MASTER)
- group.add_user(reporter, Gitlab::Access::REPORTER)
- group.add_user(guest, Gitlab::Access::GUEST)
-
- create(:project, :internal, path: "internal_project", group: group)
- create(:project, :public, path: "public_project", group: group)
- end
-
- describe "GET /groups/:path" do
- subject { group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_allowed_for :visitor }
- end
-
- describe "GET /groups/:path/issues" do
- subject { issues_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_allowed_for :visitor }
- end
-
- describe "GET /groups/:path/merge_requests" do
- subject { merge_requests_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_allowed_for :visitor }
- end
-
- describe "GET /groups/:path/group_members" do
- subject { group_group_members_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_allowed_for :visitor }
- end
-
- describe "GET /groups/:path/edit" do
- subject { edit_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_denied_for master }
- it { is_expected.to be_denied_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_denied_for guest }
- it { is_expected.to be_denied_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
- end
-end
diff --git a/spec/features/security/group/public_group_access_spec.rb b/spec/features/security/group/public_group_access_spec.rb
deleted file mode 100644
index c16f0c0d1e1..00000000000
--- a/spec/features/security/group/public_group_access_spec.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-require 'spec_helper'
-
-describe "Group with public project access", feature: true do
- describe "Group" do
- let(:group) { create(:group) }
-
- let(:owner) { create(:owner) }
- let(:master) { create(:user) }
- let(:reporter) { create(:user) }
- let(:guest) { create(:user) }
- let(:nonmember) { create(:user) }
-
- before do
- group.add_user(owner, Gitlab::Access::OWNER)
- group.add_user(master, Gitlab::Access::MASTER)
- group.add_user(reporter, Gitlab::Access::REPORTER)
- group.add_user(guest, Gitlab::Access::GUEST)
-
- create(:project, :public, group: group)
- end
-
- describe "GET /groups/:path" do
- subject { group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_allowed_for :visitor }
- end
-
- describe "GET /groups/:path/issues" do
- subject { issues_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_allowed_for :visitor }
- end
-
- describe "GET /groups/:path/merge_requests" do
- subject { merge_requests_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_allowed_for :visitor }
- end
-
- describe "GET /groups/:path/group_members" do
- subject { group_group_members_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_allowed_for master }
- it { is_expected.to be_allowed_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_allowed_for guest }
- it { is_expected.to be_allowed_for :user }
- it { is_expected.to be_allowed_for :visitor }
- end
-
- describe "GET /groups/:path/edit" do
- subject { edit_group_path(group) }
-
- it { is_expected.to be_allowed_for owner }
- it { is_expected.to be_denied_for master }
- it { is_expected.to be_denied_for reporter }
- it { is_expected.to be_allowed_for :admin }
- it { is_expected.to be_denied_for guest }
- it { is_expected.to be_denied_for :user }
- it { is_expected.to be_denied_for :visitor }
- end
- end
-end
diff --git a/spec/features/security/group_access_spec.rb b/spec/features/security/group_access_spec.rb
new file mode 100644
index 00000000000..8ce15388605
--- /dev/null
+++ b/spec/features/security/group_access_spec.rb
@@ -0,0 +1,284 @@
+require 'rails_helper'
+
+describe 'Group access', feature: true do
+ include AccessMatchers
+
+ def group
+ @group ||= create(:group)
+ end
+
+ def create_project(access_level)
+ if access_level == :mixed
+ create(:empty_project, :public, group: group)
+ create(:empty_project, :internal, group: group)
+ else
+ create(:empty_project, access_level, group: group)
+ end
+ end
+
+ def group_member(access_level, group = group)
+ level = Object.const_get("Gitlab::Access::#{access_level.upcase}")
+
+ create(:user).tap do |user|
+ group.add_user(user, level)
+ end
+ end
+
+ describe 'GET /groups/new' do
+ subject { new_group_path }
+
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+
+ describe 'GET /groups/:path' do
+ subject { group_path(group) }
+
+ context 'with public projects' do
+ let!(:project) { create_project(:public) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_allowed_for :visitor }
+ end
+
+ context 'with mixed projects' do
+ let!(:project) { create_project(:mixed) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_allowed_for :visitor }
+ end
+
+ context 'with internal projects' do
+ let!(:project) { create_project(:internal) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+
+ context 'with no projects' do
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_denied_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+ end
+
+ describe 'GET /groups/:path/issues' do
+ subject { issues_group_path(group) }
+
+ context 'with public projects' do
+ let!(:project) { create_project(:public) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_allowed_for :visitor }
+ end
+
+ context 'with mixed projects' do
+ let!(:project) { create_project(:mixed) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_allowed_for :visitor }
+ end
+
+ context 'with internal projects' do
+ let!(:project) { create_project(:internal) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+
+ context 'with no projects' do
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_denied_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+ end
+
+ describe 'GET /groups/:path/merge_requests' do
+ subject { merge_requests_group_path(group) }
+
+ context 'with public projects' do
+ let!(:project) { create_project(:public) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_allowed_for :visitor }
+ end
+
+ context 'with mixed projects' do
+ let!(:project) { create_project(:mixed) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_allowed_for :visitor }
+ end
+
+ context 'with internal projects' do
+ let!(:project) { create_project(:internal) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+
+ context 'with no projects' do
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_denied_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+ end
+
+ describe 'GET /groups/:path/group_members' do
+ subject { group_group_members_path(group) }
+
+ context 'with public projects' do
+ let!(:project) { create_project(:public) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_allowed_for :visitor }
+ end
+
+ context 'with mixed projects' do
+ let!(:project) { create_project(:mixed) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_allowed_for :visitor }
+ end
+
+ context 'with internal projects' do
+ let!(:project) { create_project(:internal) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_allowed_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+
+ context 'with no projects' do
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_allowed_for group_member(:master) }
+ it { is_expected.to be_allowed_for group_member(:reporter) }
+ it { is_expected.to be_allowed_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_denied_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+ end
+
+ describe 'GET /groups/:path/edit' do
+ subject { edit_group_path(group) }
+
+ context 'with public projects' do
+ let!(:project) { create_project(:public) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_denied_for group_member(:master) }
+ it { is_expected.to be_denied_for group_member(:reporter) }
+ it { is_expected.to be_denied_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_denied_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+
+ context 'with mixed projects' do
+ let!(:project) { create_project(:mixed) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_denied_for group_member(:master) }
+ it { is_expected.to be_denied_for group_member(:reporter) }
+ it { is_expected.to be_denied_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_denied_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+
+ context 'with internal projects' do
+ let!(:project) { create_project(:internal) }
+
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_denied_for group_member(:master) }
+ it { is_expected.to be_denied_for group_member(:reporter) }
+ it { is_expected.to be_denied_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_denied_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+
+ context 'with no projects' do
+ it { is_expected.to be_allowed_for group_member(:owner) }
+ it { is_expected.to be_denied_for group_member(:master) }
+ it { is_expected.to be_denied_for group_member(:reporter) }
+ it { is_expected.to be_denied_for group_member(:guest) }
+ it { is_expected.to be_allowed_for :admin }
+ it { is_expected.to be_denied_for :user }
+ it { is_expected.to be_denied_for :visitor }
+ end
+ end
+end
diff --git a/spec/features/security/profile_access_spec.rb b/spec/features/security/profile_access_spec.rb
index bcabc2d53ac..c19678ab381 100644
--- a/spec/features/security/profile_access_spec.rb
+++ b/spec/features/security/profile_access_spec.rb
@@ -1,18 +1,11 @@
require 'spec_helper'
describe "Profile access", feature: true do
- before do
- @u1 = create(:user)
- end
-
- describe "GET /login" do
- it { expect(new_user_session_path).not_to be_not_found_for :visitor }
- end
+ include AccessMatchers
describe "GET /profile/keys" do
subject { profile_keys_path }
- it { is_expected.to be_allowed_for @u1 }
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_denied_for :visitor }
@@ -21,7 +14,6 @@ describe "Profile access", feature: true do
describe "GET /profile" do
subject { profile_path }
- it { is_expected.to be_allowed_for @u1 }
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_denied_for :visitor }
@@ -30,7 +22,6 @@ describe "Profile access", feature: true do
describe "GET /profile/account" do
subject { profile_account_path }
- it { is_expected.to be_allowed_for @u1 }
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_denied_for :visitor }
@@ -39,7 +30,6 @@ describe "Profile access", feature: true do
describe "GET /profile/preferences" do
subject { profile_preferences_path }
- it { is_expected.to be_allowed_for @u1 }
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_denied_for :visitor }
@@ -48,7 +38,6 @@ describe "Profile access", feature: true do
describe "GET /profile/audit_log" do
subject { audit_log_profile_path }
- it { is_expected.to be_allowed_for @u1 }
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_denied_for :visitor }
@@ -57,7 +46,6 @@ describe "Profile access", feature: true do
describe "GET /profile/notifications" do
subject { profile_notifications_path }
- it { is_expected.to be_allowed_for @u1 }
it { is_expected.to be_allowed_for :admin }
it { is_expected.to be_allowed_for :user }
it { is_expected.to be_denied_for :visitor }
diff --git a/spec/features/security/project/internal_access_spec.rb b/spec/features/security/project/internal_access_spec.rb
index 4649e58cb1a..57563add74c 100644
--- a/spec/features/security/project/internal_access_spec.rb
+++ b/spec/features/security/project/internal_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Internal Project Access", feature: true do
+ include AccessMatchers
+
let(:project) { create(:project, :internal) }
let(:master) { create(:user) }
diff --git a/spec/features/security/project/private_access_spec.rb b/spec/features/security/project/private_access_spec.rb
index 2866bf0355b..a1e111c6cab 100644
--- a/spec/features/security/project/private_access_spec.rb
+++ b/spec/features/security/project/private_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Private Project Access", feature: true do
+ include AccessMatchers
+
let(:project) { create(:project) }
let(:master) { create(:user) }
diff --git a/spec/features/security/project/public_access_spec.rb b/spec/features/security/project/public_access_spec.rb
index 554c96bcdc5..655d2c8b7d9 100644
--- a/spec/features/security/project/public_access_spec.rb
+++ b/spec/features/security/project/public_access_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Public Project Access", feature: true do
+ include AccessMatchers
+
let(:project) { create(:project) }
let(:master) { create(:user) }
@@ -17,7 +19,6 @@ describe "Public Project Access", feature: true do
# readonly
project.team << [reporter, :reporter]
-
end
describe "Project should be public" do
diff --git a/spec/fixtures/GoogleCodeProjectHosting.json b/spec/fixtures/GoogleCodeProjectHosting.json
index d05e77271ae..67bb3bae5b7 100644
--- a/spec/fixtures/GoogleCodeProjectHosting.json
+++ b/spec/fixtures/GoogleCodeProjectHosting.json
@@ -382,6 +382,11 @@
"fileName" : "screenshot.png",
"fileSize" : 0,
"mimetype" : "image/png"
+ }, {
+ "attachmentId" : "001",
+ "fileName" : "screenshot1.PNG",
+ "fileSize" : 0,
+ "mimetype" : "image/x-png"
} ]
}, {
"id" : 1,
diff --git a/spec/fixtures/markdown.md.erb b/spec/fixtures/markdown.md.erb
index 02ab46c905a..41d12afa9ce 100644
--- a/spec/fixtures/markdown.md.erb
+++ b/spec/fixtures/markdown.md.erb
@@ -100,6 +100,13 @@ Markdown should be usable inside a link. Let's try!
- [**text**](#link-strong)
- [`text`](#link-code)
+### RelativeLinkFilter
+
+Linking to a file relative to this project's repository should work.
+
+[Relative Link](doc/README.md)
+![Relative Image](app/assets/images/touch-icon-ipad.png)
+
### EmojiFilter
Because life would be :zzz: without Emoji, right? :rocket:
@@ -123,9 +130,9 @@ These are all plain text that should get turned into links:
But it shouldn't autolink text inside certain tags:
-- <code>http://about.gitlab.com/</code>
-- <a>http://about.gitlab.com/</a>
-- <kbd>http://about.gitlab.com/</kbd>
+- <code>http://code.gitlab.com/</code>
+- <a>http://a.gitlab.com/</a>
+- <kbd>http://kbd.gitlab.com/</kbd>
### ExternalLinkFilter
diff --git a/spec/helpers/auth_helper_spec.rb b/spec/helpers/auth_helper_spec.rb
new file mode 100644
index 00000000000..e47a54fdac5
--- /dev/null
+++ b/spec/helpers/auth_helper_spec.rb
@@ -0,0 +1,20 @@
+require "spec_helper"
+
+describe AuthHelper do
+ describe "button_based_providers" do
+ it 'returns all enabled providers' do
+ allow(helper).to receive(:auth_providers) { [:twitter, :github] }
+ expect(helper.button_based_providers).to include(*[:twitter, :github])
+ end
+
+ it 'does not return ldap provider' do
+ allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] }
+ expect(helper.button_based_providers).to include(:twitter)
+ end
+
+ it 'returns empty array' do
+ allow(helper).to receive(:auth_providers) { [] }
+ expect(helper.button_based_providers).to eq([])
+ end
+ end
+end
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb
index e49e4e6d5d8..76009c36099 100644
--- a/spec/helpers/blob_helper_spec.rb
+++ b/spec/helpers/blob_helper_spec.rb
@@ -6,6 +6,14 @@ describe BlobHelper do
let(:no_context_content) { ":type \"assem\"))" }
let(:blob_content) { "(make-pathname :defaults name\n#{no_context_content}" }
let(:split_content) { blob_content.split("\n") }
+ let(:multiline_content) do
+ %q(
+ def test(input):
+ """This is line 1 of a multi-line comment.
+ This is line 2.
+ """
+ )
+ end
it 'should return plaintext for unknown lexer context' do
result = highlight(blob_name, no_context_content, nowrap: true, continue: false)
@@ -29,5 +37,15 @@ describe BlobHelper do
result = split_content.map{ |content| highlight(blob_name, content, nowrap: true, continue: true) }
expect(result).to eq(expected)
end
+
+ it 'should highlight multi-line comments' do
+ result = highlight(blob_name, multiline_content, nowrap: true, continue: false)
+ html = Nokogiri::HTML(result)
+ lines = html.search('.s')
+ expect(lines.count).to eq(3)
+ expect(lines[0].text).to eq('"""This is line 1 of a multi-line comment.')
+ expect(lines[1].text).to eq(' This is line 2.')
+ expect(lines[2].text).to eq(' """')
+ end
end
end
diff --git a/spec/helpers/oauth_helper_spec.rb b/spec/helpers/oauth_helper_spec.rb
deleted file mode 100644
index 3ef35f35102..00000000000
--- a/spec/helpers/oauth_helper_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require "spec_helper"
-
-describe OauthHelper do
- describe "additional_providers" do
- it 'returns all enabled providers' do
- allow(helper).to receive(:enabled_oauth_providers) { [:twitter, :github] }
- expect(helper.additional_providers).to include(*[:twitter, :github])
- end
-
- it 'does not return ldap provider' do
- allow(helper).to receive(:enabled_oauth_providers) { [:twitter, :ldapmain] }
- expect(helper.additional_providers).to include(:twitter)
- end
-
- it 'returns empty array' do
- allow(helper).to receive(:enabled_oauth_providers) { [] }
- expect(helper.additional_providers).to eq([])
- end
- end
-end
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index beb9b4e438e..99abb95d906 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -22,7 +22,7 @@ describe ProjectsHelper do
let(:user) { create(:user) }
- it "returns false if there are no approipriate permissions" do
+ it "returns false if there are no appropriate permissions" do
allow(helper).to receive(:can?) { false }
expect(helper.can_change_visibility_level?(project, user)).to be_falsey
@@ -52,4 +52,22 @@ describe ProjectsHelper do
end
end
end
+
+ describe "readme_cache_key" do
+ let(:project) { create(:project) }
+
+ before do
+ helper.instance_variable_set(:@project, project)
+ end
+
+ it "returns a valid cach key" do
+ expect(helper.send(:readme_cache_key)).to eq("#{project.id}-#{project.commit.id}-readme")
+ end
+
+ it "returns a valid cache key if HEAD does not exist" do
+ allow(project).to receive(:commit) { nil }
+
+ expect(helper.send(:readme_cache_key)).to eq("#{project.id}-nil-readme")
+ end
+ end
end
diff --git a/spec/javascripts/fixtures/line_highlighter.html.haml b/spec/javascripts/fixtures/line_highlighter.html.haml
index 15ad1d8968f..da1ebcdb23c 100644
--- a/spec/javascripts/fixtures/line_highlighter.html.haml
+++ b/spec/javascripts/fixtures/line_highlighter.html.haml
@@ -2,7 +2,9 @@
.file-content
.line-numbers
- 1.upto(25) do |i|
- %a{href: "#L#{i}", id: "L#{i}", 'data-line-number' => i}= i
+ %a{href: "#L#{i}", id: "L#{i}", 'data-line-number' => i}
+ %i.fa.fa-link
+ = i
%pre.code.highlight
%code
- 1.upto(25) do |i|
diff --git a/spec/javascripts/line_highlighter_spec.js.coffee b/spec/javascripts/line_highlighter_spec.js.coffee
index 14fa487ff7f..57453c716a5 100644
--- a/spec/javascripts/line_highlighter_spec.js.coffee
+++ b/spec/javascripts/line_highlighter_spec.js.coffee
@@ -48,6 +48,14 @@ describe 'LineHighlighter', ->
clickLine(13)
expect(spy).toHaveBeenPrevented()
+ it 'handles clicking on a child icon element', ->
+ spy = spyOn(@class, 'setHash').and.callThrough()
+
+ $('#L13 i').mousedown().click()
+
+ expect(spy).toHaveBeenCalledWith(13)
+ expect($('#LC13')).toHaveClass(@css)
+
describe 'without shiftKey', ->
it 'highlights one line when clicked', ->
clickLine(13)
diff --git a/spec/javascripts/merge_request_tabs_spec.js.coffee b/spec/javascripts/merge_request_tabs_spec.js.coffee
index 6cc96fb68a0..a0cfba455ea 100644
--- a/spec/javascripts/merge_request_tabs_spec.js.coffee
+++ b/spec/javascripts/merge_request_tabs_spec.js.coffee
@@ -51,6 +51,12 @@ describe 'MergeRequestTabs', ->
expect(@subject('notes')).toBe('/foo/bar/merge_requests/1')
expect(@subject('commits')).toBe('/foo/bar/merge_requests/1/commits')
+ it 'changes from diffs.html', ->
+ @class._location = stubLocation(pathname: '/foo/bar/merge_requests/1/diffs.html')
+
+ expect(@subject('notes')).toBe('/foo/bar/merge_requests/1')
+ expect(@subject('commits')).toBe('/foo/bar/merge_requests/1/commits')
+
it 'changes from notes', ->
@class._location = stubLocation(pathname: '/foo/bar/merge_requests/1')
diff --git a/spec/lib/gitlab/google_code_import/importer_spec.rb b/spec/lib/gitlab/google_code_import/importer_spec.rb
index c53ddeb87b5..f49cbb7f532 100644
--- a/spec/lib/gitlab/google_code_import/importer_spec.rb
+++ b/spec/lib/gitlab/google_code_import/importer_spec.rb
@@ -65,6 +65,7 @@ describe Gitlab::GoogleCodeImport::Importer do
expect(issue.description).to include('all the best!')
expect(issue.description).to include('[tint2_task_scrolling.diff](https://storage.googleapis.com/google-code-attachments/tint2/issue-169/comment-0/tint2_task_scrolling.diff)')
expect(issue.description).to include('![screenshot.png](https://storage.googleapis.com/google-code-attachments/tint2/issue-169/comment-0/screenshot.png)')
+ expect(issue.description).to include('![screenshot1.PNG](https://storage.googleapis.com/google-code-attachments/tint2/issue-169/comment-0/screenshot1.PNG)')
end
it "imports issue comments" do
diff --git a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb
index 5ee5310825d..7f4d67e403f 100644
--- a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb
@@ -1,3 +1,5 @@
+# encoding: UTF-8
+
require 'spec_helper'
module Gitlab::Markdown
@@ -101,6 +103,20 @@ module Gitlab::Markdown
expect(doc.at_css('a')['href']).to eq 'http://example.com'
end
+ it 'supports Unicode filenames' do
+ path = 'files/images/한글.png'
+ escaped = Addressable::URI.escape(path)
+
+ # Stub these methods so the file doesn't actually need to be in the repo
+ allow_any_instance_of(described_class).to receive(:file_exists?).
+ and_return(true)
+ allow_any_instance_of(described_class).
+ to receive(:image?).with(path).and_return(true)
+
+ doc = filter(image(escaped))
+ expect(doc.at_css('img')['src']).to match '/raw/'
+ end
+
context 'when requested path is a file in the repo' do
let(:requested_path) { 'doc/api/README.md' }
include_examples :relative_to_requested
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index d648f4078be..bc14ff98fd8 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -14,11 +14,14 @@
# default_branch_protection :integer default(2)
# twitter_sharing_enabled :boolean default(TRUE)
# restricted_visibility_levels :text
+# version_check_enabled :boolean default(TRUE)
# max_attachment_size :integer default(10), not null
-# session_expire_delay :integer default(10080), not null
# default_project_visibility :integer
# default_snippet_visibility :integer
# restricted_signup_domains :text
+# user_oauth_applications :boolean default(TRUE)
+# after_sign_out_path :string(255)
+# session_expire_delay :integer default(10080), not null
#
require 'spec_helper'
diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb
index fedc37c9b94..a14384c87b4 100644
--- a/spec/models/project_services/gitlab_ci_service_spec.rb
+++ b/spec/models/project_services/gitlab_ci_service_spec.rb
@@ -26,6 +26,33 @@ describe GitlabCiService do
it { is_expected.to have_one(:service_hook) }
end
+ describe 'validations' do
+ context 'active' do
+ before { allow(subject).to receive(:activated?).and_return(true) }
+
+ it { is_expected.to validate_presence_of(:token) }
+ it { is_expected.to validate_presence_of(:project_url) }
+ it { is_expected.to allow_value('ewf9843kdnfdfs89234n').for(:token) }
+ it { is_expected.to allow_value('http://ci.example.com/project/1').for(:project_url) }
+ it { is_expected.not_to allow_value('token with spaces').for(:token) }
+ it { is_expected.not_to allow_value('token/with%spaces').for(:token) }
+ it { is_expected.not_to allow_value('this is not url').for(:project_url) }
+ it { is_expected.not_to allow_value('http//noturl').for(:project_url) }
+ it { is_expected.not_to allow_value('ftp://ci.example.com/projects/3').for(:project_url) }
+ end
+
+ context 'inactive' do
+ before { allow(subject).to receive(:activated?).and_return(false) }
+
+ it { is_expected.not_to validate_presence_of(:token) }
+ it { is_expected.not_to validate_presence_of(:project_url) }
+ it { is_expected.to allow_value('ewf9843kdnfdfs89234n').for(:token) }
+ it { is_expected.to allow_value('http://ci.example.com/project/1').for(:project_url) }
+ it { is_expected.to allow_value('token with spaces').for(:token) }
+ it { is_expected.to allow_value('ftp://ci.example.com/projects/3').for(:project_url) }
+ end
+ end
+
describe 'commits methods' do
before do
@service = GitlabCiService.new
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 721ae88c120..2fcbd5ae108 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -21,12 +21,13 @@
# import_url :string(255)
# visibility_level :integer default(0), not null
# archived :boolean default(FALSE), not null
+# avatar :string(255)
# import_status :string(255)
# repository_size :float default(0.0)
# star_count :integer default(0), not null
# import_type :string(255)
# import_source :string(255)
-# avatar :string(255)
+# commit_count :integer default(0)
#
require 'spec_helper'
@@ -110,14 +111,20 @@ describe Project do
expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git')
end
- it 'returns the full web URL for this repo' do
- project = Project.new(path: 'somewhere')
- expect(project.web_url).to eq("#{Gitlab.config.gitlab.url}/somewhere")
+ describe "#web_url" do
+ let(:project) { create(:empty_project, path: "somewhere") }
+
+ it 'returns the full web URL for this repo' do
+ expect(project.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.namespace.path}/somewhere")
+ end
end
- it 'returns the web URL without the protocol for this repo' do
- project = Project.new(path: 'somewhere')
- expect(project.web_url_without_protocol).to eq("#{Gitlab.config.gitlab.url.split('://')[1]}/somewhere")
+ describe "#web_url_without_protocol" do
+ let(:project) { create(:empty_project, path: "somewhere") }
+
+ it 'returns the web URL without the protocol for this repo' do
+ expect(project.web_url_without_protocol).to eq("#{Gitlab.config.gitlab.url.split('://')[1]}/#{project.namespace.path}/somewhere")
+ end
end
describe 'last_activity methods' do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 16902317f10..922e9ebf844 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -57,6 +57,7 @@
# otp_backup_codes :text
# public_email :string(255) default(""), not null
# dashboard :integer default(0)
+# project_view :integer default(0)
#
require 'spec_helper'
@@ -442,6 +443,18 @@ describe User do
end
end
+ describe '.find_by_username!' do
+ it 'raises RecordNotFound' do
+ expect { described_class.find_by_username!('JohnDoe') }.
+ to raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ it 'is case-insensitive' do
+ user = create(:user, username: 'JohnDoe')
+ expect(described_class.find_by_username!('JOHNDOE')).to eq user
+ end
+ end
+
describe 'all_ssh_keys' do
it { is_expected.to have_many(:keys).dependent(:destroy) }
diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb
index cb6e5e89625..5c1b58535cc 100644
--- a/spec/requests/api/branches_spec.rb
+++ b/spec/requests/api/branches_spec.rb
@@ -14,10 +14,13 @@ describe API::API, api: true do
describe "GET /projects/:id/repository/branches" do
it "should return an array of project branches" do
+ project.repository.expire_cache
+
get api("/projects/#{project.id}/repository/branches", user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
- expect(json_response.first['name']).to eq(project.repository.branch_names.first)
+ branch_names = json_response.map { |x| x['name'] }
+ expect(branch_names).to match_array(project.repository.branch_names)
end
end
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 780ff93a232..942768fa254 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -8,6 +8,7 @@ describe API::API, api: true do
let!(:merge_request_closed) { create(:merge_request, state: "closed", author: user, assignee: user, source_project: project, target_project: project, title: "Closed test") }
let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignee: user, source_project: project, target_project: project, title: "Merged test") }
let!(:note) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "a comment on a MR") }
+ let!(:note2) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "another comment on a MR") }
before do
project.team << [user, :reporters]
@@ -395,13 +396,14 @@ describe API::API, api: true do
end
describe "GET :id/merge_request/:merge_request_id/comments" do
- it "should return merge_request comments" do
+ it "should return merge_request comments ordered by created_at" do
get api("/projects/#{project.id}/merge_request/#{merge_request.id}/comments", user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
- expect(json_response.length).to eq(1)
+ expect(json_response.length).to eq(2)
expect(json_response.first['note']).to eq("a comment on a MR")
expect(json_response.first['author']['id']).to eq(user.id)
+ expect(json_response.last['note']).to eq("another comment on a MR")
end
it "should return a 404 error if merge_request_id not found" do
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 4178bb2e836..5bd8206b890 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -89,7 +89,7 @@ describe API::API, api: true do
it 'returns projects in the correct order when ci_enabled_first parameter is passed' do
[project, project2, project3].each{ |project| project.build_missing_services }
- project2.gitlab_ci_service.update(active: true, token: "token", project_url: "url")
+ project2.gitlab_ci_service.update(active: true, token: "token", project_url: "http://ci.example.com/projects/1")
get api('/projects', user), { ci_enabled_first: 'true' }
expect(response.status).to eq(200)
expect(json_response).to be_an Array
diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb
index 51c543578df..6d29a28580a 100644
--- a/spec/requests/api/services_spec.rb
+++ b/spec/requests/api/services_spec.rb
@@ -7,7 +7,7 @@ describe API::API, api: true do
describe "POST /projects/:id/services/gitlab-ci" do
it "should update gitlab-ci settings" do
- put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'secret-token', project_url: "http://ci.example.com/projects/1"
+ put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'secrettoken', project_url: "http://ci.example.com/projects/1"
expect(response.status).to eq(200)
end
@@ -17,6 +17,18 @@ describe API::API, api: true do
expect(response.status).to eq(400)
end
+
+ it "should return if the format of token is invalid" do
+ put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'token-with dashes and spaces%', project_url: "http://ci.example.com/projects/1", active: true
+
+ expect(response.status).to eq(404)
+ end
+
+ it "should return if the format of token is invalid" do
+ put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'token-with dashes and spaces%', project_url: "ftp://ci.example/projects/1", active: true
+
+ expect(response.status).to eq(404)
+ end
end
describe "DELETE /projects/:id/services/gitlab-ci" do
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index c4dd1f76cf2..f2aa369985e 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -6,6 +6,7 @@ describe API::API, api: true do
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let(:key) { create(:key, user: user) }
+ let(:email) { create(:email, user: user) }
describe "GET /users" do
context "when unauthenticated" do
@@ -384,6 +385,87 @@ describe API::API, api: true do
end
end
+ describe "POST /users/:id/emails" do
+ before { admin }
+
+ it "should not create invalid email" do
+ post api("/users/#{user.id}/emails", admin), {}
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('400 (Bad request) "email" not given')
+ end
+
+ it "should create email" do
+ email_attrs = attributes_for :email
+ expect do
+ post api("/users/#{user.id}/emails", admin), email_attrs
+ end.to change{ user.emails.count }.by(1)
+ end
+ end
+
+ describe 'GET /user/:uid/emails' do
+ before { admin }
+
+ context 'when unauthenticated' do
+ it 'should return authentication error' do
+ get api("/users/#{user.id}/emails")
+ expect(response.status).to eq(401)
+ end
+ end
+
+ context 'when authenticated' do
+ it 'should return 404 for non-existing user' do
+ get api('/users/999999/emails', admin)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 User Not Found')
+ end
+
+ it 'should return array of emails' do
+ user.emails << email
+ user.save
+ get api("/users/#{user.id}/emails", admin)
+ expect(response.status).to eq(200)
+ expect(json_response).to be_an Array
+ expect(json_response.first['email']).to eq(email.email)
+ end
+ end
+ end
+
+ describe 'DELETE /user/:uid/emails/:id' do
+ before { admin }
+
+ context 'when unauthenticated' do
+ it 'should return authentication error' do
+ delete api("/users/#{user.id}/emails/42")
+ expect(response.status).to eq(401)
+ end
+ end
+
+ context 'when authenticated' do
+ it 'should delete existing email' do
+ user.emails << email
+ user.save
+ expect do
+ delete api("/users/#{user.id}/emails/#{email.id}", admin)
+ end.to change { user.emails.count }.by(-1)
+ expect(response.status).to eq(200)
+ end
+
+ it 'should return 404 error if user not found' do
+ user.emails << email
+ user.save
+ delete api("/users/999999/emails/#{email.id}", admin)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 User Not Found')
+ end
+
+ it 'should return 404 error if email not foud' do
+ delete api("/users/#{user.id}/emails/42", admin)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 Email Not Found')
+ end
+ end
+ end
+
describe "DELETE /users/:id" do
before { admin }
@@ -528,6 +610,95 @@ describe API::API, api: true do
end
end
+ describe "GET /user/emails" do
+ context "when unauthenticated" do
+ it "should return authentication error" do
+ get api("/user/emails")
+ expect(response.status).to eq(401)
+ end
+ end
+
+ context "when authenticated" do
+ it "should return array of emails" do
+ user.emails << email
+ user.save
+ get api("/user/emails", user)
+ expect(response.status).to eq(200)
+ expect(json_response).to be_an Array
+ expect(json_response.first["email"]).to eq(email.email)
+ end
+ end
+ end
+
+ describe "GET /user/emails/:id" do
+ it "should return single email" do
+ user.emails << email
+ user.save
+ get api("/user/emails/#{email.id}", user)
+ expect(response.status).to eq(200)
+ expect(json_response["email"]).to eq(email.email)
+ end
+
+ it "should return 404 Not Found within invalid ID" do
+ get api("/user/emails/42", user)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 Not found')
+ end
+
+ it "should return 404 error if admin accesses user's email" do
+ user.emails << email
+ user.save
+ admin
+ get api("/user/emails/#{email.id}", admin)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 Not found')
+ end
+ end
+
+ describe "POST /user/emails" do
+ it "should create email" do
+ email_attrs = attributes_for :email
+ expect do
+ post api("/user/emails", user), email_attrs
+ end.to change{ user.emails.count }.by(1)
+ expect(response.status).to eq(201)
+ end
+
+ it "should return a 401 error if unauthorized" do
+ post api("/user/emails"), email: 'some email'
+ expect(response.status).to eq(401)
+ end
+
+ it "should not create email with invalid email" do
+ post api("/user/emails", user), {}
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('400 (Bad request) "email" not given')
+ end
+ end
+
+ describe "DELETE /user/emails/:id" do
+ it "should delete existed email" do
+ user.emails << email
+ user.save
+ expect do
+ delete api("/user/emails/#{email.id}", user)
+ end.to change{user.emails.count}.by(-1)
+ expect(response.status).to eq(200)
+ end
+
+ it "should return success if email ID not found" do
+ delete api("/user/emails/42", user)
+ expect(response.status).to eq(200)
+ end
+
+ it "should return 401 error if unauthorized" do
+ user.emails << email
+ user.save
+ delete api("/user/emails/#{email.id}")
+ expect(response.status).to eq(401)
+ end
+ end
+
describe 'PUT /user/:id/block' do
before { admin }
it 'should block existing user' do
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index 97b206c9854..66cdfd5d758 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -4,13 +4,19 @@ describe Projects::CreateService do
describe :create_by_user do
before do
@user = create :user
- @admin = create :user, admin: true
@opts = {
name: "GitLab",
namespace: @user.namespace
}
end
+ it 'creates services on Project creation' do
+ project = create_project(@user, @opts)
+ project.reload
+
+ expect(project.services).not_to be_empty
+ end
+
context 'user namespace' do
before do
@project = create_project(@user, @opts)
@@ -75,7 +81,9 @@ describe Projects::CreateService do
end
it 'should allow a restricted visibility level for admins' do
- project = create_project(@admin, @opts)
+ admin = create(:admin)
+ project = create_project(admin, @opts)
+
expect(project.errors.any?).to be(false)
expect(project.saved?).to be(true)
end
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index 439a492cea9..c04e842c67e 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -29,7 +29,7 @@ describe Projects::ForkService do
it "fails due to transaction failure" do
@to_project = fork_project(@from_project, @to_user, false)
expect(@to_project.errors).not_to be_empty
- expect(@to_project.errors[:base]).to include("Failed to fork repository")
+ expect(@to_project.errors[:base]).to include("Failed to fork repository via gitlab-shell")
end
end
diff --git a/spec/support/markdown_feature.rb b/spec/support/markdown_feature.rb
new file mode 100644
index 00000000000..2a868aed73b
--- /dev/null
+++ b/spec/support/markdown_feature.rb
@@ -0,0 +1,106 @@
+# This is a helper class used by the GitLab Markdown feature spec
+#
+# Because the feature spec only cares about the output of the Markdown, and the
+# test setup and teardown and parsing is fairly expensive, we only want to do it
+# once. Unfortunately RSpec will not let you access `let`s in a `before(:all)`
+# block, so we fake it by encapsulating all the shared setup in this class.
+#
+# The class renders `spec/fixtures/markdown.md.erb` using ERB, allowing for
+# reference to the factory-created objects.
+class MarkdownFeature
+ include FactoryGirl::Syntax::Methods
+
+ def user
+ @user ||= create(:user)
+ end
+
+ def group
+ unless @group
+ @group = create(:group)
+ @group.add_user(user, Gitlab::Access::DEVELOPER)
+ end
+
+ @group
+ end
+
+ # Direct references ----------------------------------------------------------
+
+ def project
+ @project ||= create(:project)
+ end
+
+ def issue
+ @issue ||= create(:issue, project: project)
+ end
+
+ def merge_request
+ @merge_request ||= create(:merge_request, :simple, source_project: project)
+ end
+
+ def snippet
+ @snippet ||= create(:project_snippet, project: project)
+ end
+
+ def commit
+ @commit ||= project.commit
+ end
+
+ def commit_range
+ unless @commit_range
+ commit2 = project.commit('HEAD~3')
+ @commit_range = CommitRange.new("#{commit.id}...#{commit2.id}", project)
+ end
+
+ @commit_range
+ end
+
+ def simple_label
+ @simple_label ||= create(:label, name: 'gfm', project: project)
+ end
+
+ def label
+ @label ||= create(:label, name: 'awaiting feedback', project: project)
+ end
+
+ # Cross-references -----------------------------------------------------------
+
+ def xproject
+ unless @xproject
+ namespace = create(:namespace, name: 'cross-reference')
+ @xproject = create(:project, namespace: namespace)
+ @xproject.team << [user, :developer]
+ end
+
+ @xproject
+ end
+
+ def xissue
+ @xissue ||= create(:issue, project: xproject)
+ end
+
+ def xmerge_request
+ @xmerge_request ||= create(:merge_request, :simple, source_project: xproject)
+ end
+
+ def xsnippet
+ @xsnippet ||= create(:project_snippet, project: xproject)
+ end
+
+ def xcommit
+ @xcommit ||= xproject.commit
+ end
+
+ def xcommit_range
+ unless @xcommit_range
+ xcommit2 = xproject.commit('HEAD~2')
+ @xcommit_range = CommitRange.new("#{xcommit.id}...#{xcommit2.id}", xproject)
+ end
+
+ @xcommit_range
+ end
+
+ def raw_markdown
+ fixture = Rails.root.join('spec/fixtures/markdown.md.erb')
+ ERB.new(File.read(fixture)).result(binding)
+ end
+end
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb
deleted file mode 100644
index a2f853e3e70..00000000000
--- a/spec/support/matchers.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-RSpec::Matchers.define :be_valid_commit do
- match do |actual|
- actual &&
- actual.id == ValidCommit::ID &&
- actual.message == ValidCommit::MESSAGE &&
- actual.author_name == ValidCommit::AUTHOR_FULL_NAME
- end
-end
-
-def emulate_user(user)
- user = case user
- when :user then create(:user)
- when :visitor then nil
- when :admin then create(:admin)
- else user
- end
- login_with(user) if user
-end
-
-RSpec::Matchers.define :be_allowed_for do |user|
- match do |url|
- emulate_user(user)
- visit url
- status_code != 404 && current_path != new_user_session_path
- end
-end
-
-RSpec::Matchers.define :be_denied_for do |user|
- match do |url|
- emulate_user(user)
- visit url
- status_code == 404 || current_path == new_user_session_path
- end
-end
-
-RSpec::Matchers.define :be_not_found_for do |user|
- match do |url|
- emulate_user(user)
- visit url
- status_code == 404
- end
-end
-
-RSpec::Matchers.define :include_module do |expected|
- match do
- described_class.included_modules.include?(expected)
- end
-
- description do
- "includes the #{expected} module"
- end
-
- failure_message do
- "expected #{described_class} to include the #{expected} module"
- end
-end
-
-# Extend shoulda-matchers
-module Shoulda::Matchers::ActiveModel
- class ValidateLengthOfMatcher
- # Shortcut for is_at_least and is_at_most
- def is_within(range)
- is_at_least(range.min) && is_at_most(range.max)
- end
- end
-end
diff --git a/spec/support/matchers/access_matchers.rb b/spec/support/matchers/access_matchers.rb
new file mode 100644
index 00000000000..558e8b1612f
--- /dev/null
+++ b/spec/support/matchers/access_matchers.rb
@@ -0,0 +1,54 @@
+# AccessMatchers
+#
+# The custom matchers contained in this module are used to test a user's access
+# to a URL by emulating a specific user or type of user account, visiting the
+# URL, and then checking the response status code and resulting path.
+module AccessMatchers
+ extend RSpec::Matchers::DSL
+ include Warden::Test::Helpers
+
+ def emulate_user(user)
+ case user
+ when :user
+ login_as(create(:user))
+ when :visitor
+ logout
+ when :admin
+ login_as(create(:admin))
+ when User
+ login_as(user)
+ else
+ raise ArgumentError, "cannot emulate user #{user}"
+ end
+ end
+
+ def description_for(user, type)
+ if user.kind_of?(User)
+ # User#inspect displays too much information for RSpec's description
+ # messages
+ "be #{type} for supplied User"
+ else
+ "be #{type} for #{user}"
+ end
+ end
+
+ matcher :be_allowed_for do |user|
+ match do |url|
+ emulate_user(user)
+ visit url
+ status_code != 404 && current_path != new_user_session_path
+ end
+
+ description { description_for(user, 'allowed') }
+ end
+
+ matcher :be_denied_for do |user|
+ match do |url|
+ emulate_user(user)
+ visit url
+ status_code == 404 || current_path == new_user_session_path
+ end
+
+ description { description_for(user, 'denied') }
+ end
+end
diff --git a/spec/support/matchers/include_module.rb b/spec/support/matchers/include_module.rb
new file mode 100644
index 00000000000..0a78af1e90e
--- /dev/null
+++ b/spec/support/matchers/include_module.rb
@@ -0,0 +1,13 @@
+RSpec::Matchers.define :include_module do |expected|
+ match do
+ described_class.included_modules.include?(expected)
+ end
+
+ description do
+ "includes the #{expected} module"
+ end
+
+ failure_message do
+ "expected #{described_class} to include the #{expected} module"
+ end
+end
diff --git a/spec/support/matchers/is_within.rb b/spec/support/matchers/is_within.rb
new file mode 100644
index 00000000000..0c35fc7e899
--- /dev/null
+++ b/spec/support/matchers/is_within.rb
@@ -0,0 +1,9 @@
+# Extend shoulda-matchers
+module Shoulda::Matchers::ActiveModel
+ class ValidateLengthOfMatcher
+ # Shortcut for is_at_least and is_at_most
+ def is_within(range)
+ is_at_least(range.min) && is_at_most(range.max)
+ end
+ end
+end
diff --git a/spec/support/matchers/markdown_matchers.rb b/spec/support/matchers/markdown_matchers.rb
new file mode 100644
index 00000000000..9df226c3af8
--- /dev/null
+++ b/spec/support/matchers/markdown_matchers.rb
@@ -0,0 +1,156 @@
+# MarkdownMatchers
+#
+# Custom matchers for our custom HTML::Pipeline filters. These are used to test
+# that specific filters are or are not used by our defined pipelines.
+#
+# Must be included manually.
+module MarkdownMatchers
+ extend RSpec::Matchers::DSL
+ include Capybara::Node::Matchers
+
+ # RelativeLinkFilter
+ matcher :parse_relative_links do
+ set_default_markdown_messages
+
+ match do |actual|
+ link = actual.at_css('a:contains("Relative Link")')
+ image = actual.at_css('img[alt="Relative Image"]')
+
+ expect(link['href']).to end_with('master/doc/README.md')
+ expect(image['src']).to end_with('master/app/assets/images/touch-icon-ipad.png')
+ end
+ end
+
+ # EmojiFilter
+ matcher :parse_emoji do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('img.emoji', count: 10)
+ end
+ end
+
+ # TableOfContentsFilter
+ matcher :create_header_links do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('h1 a#gitlab-markdown')
+ expect(actual).to have_selector('h2 a#markdown')
+ expect(actual).to have_selector('h3 a#autolinkfilter')
+ end
+ end
+
+ # AutolinkFilter
+ matcher :create_autolinks do
+ def have_autolink(link)
+ have_link(link, href: link)
+ end
+
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_autolink('http://about.gitlab.com/')
+ expect(actual).to have_autolink('https://google.com/')
+ expect(actual).to have_autolink('ftp://ftp.us.debian.org/debian/')
+ expect(actual).to have_autolink('smb://foo/bar/baz')
+ expect(actual).to have_autolink('irc://irc.freenode.net/git')
+ expect(actual).to have_autolink('http://localhost:3000')
+
+ %w(code a kbd).each do |elem|
+ expect(body).not_to have_selector("#{elem} a")
+ end
+ end
+ end
+
+ # UserReferenceFilter
+ matcher :reference_users do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-project_member', count: 3)
+ end
+ end
+
+ # IssueReferenceFilter
+ matcher :reference_issues do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-issue', count: 3)
+ end
+ end
+
+ # MergeRequestReferenceFilter
+ matcher :reference_merge_requests do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-merge_request', count: 3)
+ expect(actual).to have_selector('em a.gfm-merge_request')
+ end
+ end
+
+ # SnippetReferenceFilter
+ matcher :reference_snippets do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-snippet', count: 2)
+ end
+ end
+
+ # CommitRangeReferenceFilter
+ matcher :reference_commit_ranges do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-commit_range', count: 2)
+ end
+ end
+
+ # CommitReferenceFilter
+ matcher :reference_commits do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-commit', count: 2)
+ end
+ end
+
+ # LabelReferenceFilter
+ matcher :reference_labels do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-label', count: 3)
+ end
+ end
+
+ # TaskListFilter
+ matcher :parse_task_lists do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('ul.task-list', count: 2)
+ expect(actual).to have_selector('li.task-list-item', count: 7)
+ expect(actual).to have_selector('input[checked]', count: 3)
+ end
+ end
+end
+
+# Monkeypatch the matcher DSL so that we can reduce some noisy duplication for
+# setting the failure messages for these matchers
+module RSpec::Matchers::DSL::Macros
+ def set_default_markdown_messages
+ failure_message do
+ # expected to parse emoji, but didn't
+ "expected to #{description}, but didn't"
+ end
+
+ failure_message_when_negated do
+ # expected not to parse task lists, but did
+ "expected not to #{description}, but did"
+ end
+ end
+end
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index 8bdd6b43cdd..8dc687c3580 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -5,18 +5,24 @@ module TestEnv
# When developing the seed repository, comment out the branch you will modify.
BRANCH_SHA = {
+ 'empty-branch' => '7efb185',
'flatten-dir' => 'e56497b',
'feature' => '0b4bc9a',
'feature_conflict' => 'bb5206f',
'fix' => '12d65c8',
'improve/awesome' => '5937ac0',
'markdown' => '0ed8c6c',
- 'master' => '5937ac0'
+ 'master' => '5937ac0',
+ "'test'" => 'e56497b',
}
- FORKED_BRANCH_SHA = BRANCH_SHA.merge({
- 'add-submodule-version-bump' => '3f547c08'
- })
+ # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
+ # need to keep all the branches in sync.
+ # We currently only need a subset of the branches
+ FORKED_BRANCH_SHA = {
+ 'add-submodule-version-bump' => '3f547c08',
+ 'master' => '5937ac0'
+ }
# Test environment
#
@@ -29,6 +35,7 @@ module TestEnv
clean_test_path
FileUtils.mkdir_p(repos_path)
+ FileUtils.mkdir_p(backup_path)
# Setup GitLab shell for test instance
setup_gitlab_shell
@@ -121,6 +128,10 @@ module TestEnv
Gitlab.config.gitlab_shell.repos_path
end
+ def backup_path
+ Gitlab.config.backup.path
+ end
+
def copy_forked_repo_with_submodules(project)
base_repo_path = File.expand_path(forked_repo_path_bare)
target_repo_path = File.expand_path(repos_path + "/#{project.namespace.path}/#{project.path}.git")
diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb
index cdcfeba8d1f..23f322e0a62 100644
--- a/spec/tasks/gitlab/backup_rake_spec.rb
+++ b/spec/tasks/gitlab/backup_rake_spec.rb
@@ -15,6 +15,12 @@ describe 'gitlab:app namespace rake task' do
Rake.application.invoke_task task_name
end
+ def reenable_backup_sub_tasks
+ %w{db repo uploads}.each do |subtask|
+ Rake::Task["gitlab:backup:#{subtask}:create"].reenable
+ end
+ end
+
describe 'backup_restore' do
before do
# avoid writing task output to spec progress
@@ -60,26 +66,47 @@ describe 'gitlab:app namespace rake task' do
Dir.glob(File.join(Gitlab.config.backup.path, '*_gitlab_backup.tar'))
end
- before :all do
- # Record the existing backup tars so we don't touch them
- existing_tars = tars_glob
+ def create_backup
+ FileUtils.rm tars_glob
# Redirect STDOUT and run the rake task
orig_stdout = $stdout
$stdout = StringIO.new
+ reenable_backup_sub_tasks
run_rake_task('gitlab:backup:create')
+ reenable_backup_sub_tasks
$stdout = orig_stdout
- @backup_tar = (tars_glob - existing_tars).first
+ @backup_tar = tars_glob.first
end
- after :all do
+ before do
+ create_backup
+ end
+
+ after do
FileUtils.rm(@backup_tar)
end
- it 'should set correct permissions on the tar file' do
- expect(File.exist?(@backup_tar)).to be_truthy
- expect(File::Stat.new(@backup_tar).mode.to_s(8)).to eq('100600')
+ context 'archive file permissions' do
+ it 'should set correct permissions on the tar file' do
+ expect(File.exist?(@backup_tar)).to be_truthy
+ expect(File::Stat.new(@backup_tar).mode.to_s(8)).to eq('100600')
+ end
+
+ context 'with custom archive_permissions' do
+ before do
+ allow(Gitlab.config.backup).to receive(:archive_permissions).and_return(0651)
+ # We created a backup in a before(:all) so it got the default permissions.
+ # We now need to do some work to create a _new_ backup file using our stub.
+ FileUtils.rm(@backup_tar)
+ create_backup
+ end
+
+ it 'uses the custom permissions' do
+ expect(File::Stat.new(@backup_tar).mode.to_s(8)).to eq('100651')
+ end
+ end
end
it 'should set correct permissions on the tar contents' do
@@ -110,12 +137,9 @@ describe 'gitlab:app namespace rake task' do
before :all do
@origin_cd = Dir.pwd
- Rake::Task["gitlab:backup:db:create"].reenable
- Rake::Task["gitlab:backup:repo:create"].reenable
- Rake::Task["gitlab:backup:uploads:create"].reenable
+ reenable_backup_sub_tasks
- # Record the existing backup tars so we don't touch them
- existing_tars = tars_glob
+ FileUtils.rm tars_glob
# Redirect STDOUT and run the rake task
orig_stdout = $stdout
@@ -124,7 +148,7 @@ describe 'gitlab:app namespace rake task' do
run_rake_task('gitlab:backup:create')
$stdout = orig_stdout
- @backup_tar = (tars_glob - existing_tars).first
+ @backup_tar = tars_glob.first
end
after :all do