summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/features/markdown_spec.rb17
-rw-r--r--spec/fixtures/markdown.md.erb8
-rw-r--r--spec/helpers/diff_helper_spec.rb54
-rw-r--r--spec/mailers/notify_spec.rb6
-rw-r--r--spec/services/git_push_service_spec.rb15
5 files changed, 93 insertions, 7 deletions
diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb
index 296055e89fa..1746ce128e4 100644
--- a/spec/features/markdown_spec.rb
+++ b/spec/features/markdown_spec.rb
@@ -63,7 +63,7 @@ describe 'GitLab Markdown' do
# Given a header ID, goes to that element's parent (the header), then to its
# second sibling (the body).
def get_section(id)
- @doc.at_css("##{id}").parent.next.next
+ @doc.at_css("##{id}").parent.next_element
end
# it 'writes to a file' do
@@ -162,6 +162,19 @@ describe 'GitLab Markdown' do
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>}
+ end
+ end
+
describe 'EmojiFilter' do
it 'parses Emoji' do
expect(@doc).to have_selector('img.emoji', count: 10)
@@ -177,7 +190,7 @@ describe 'GitLab Markdown' do
end
describe 'AutolinkFilter' do
- let(:list) { get_section('autolinkfilter').parent.search('ul') }
+ let(:list) { get_section('autolinkfilter').next_element }
def item(index)
list.at_css("li:nth-child(#{index})")
diff --git a/spec/fixtures/markdown.md.erb b/spec/fixtures/markdown.md.erb
index 09ee83ba77c..bc023ecf793 100644
--- a/spec/fixtures/markdown.md.erb
+++ b/spec/fixtures/markdown.md.erb
@@ -94,6 +94,14 @@ The problem with SanitizationFilter is that it can be too aggressive.
| `1 < 3 & 5` | 1 &lt; 3 &amp; 5 | 1 < 3 & 5 |
| `<foo>` | &lt;foo&gt; | <foo> |
+### Edge Cases
+
+Markdown should be usable inside a link. Let's try!
+
+- [_text_](#link-emphasis)
+- [**text**](#link-strong)
+- [`text`](#link-code)
+
### EmojiFilter
Because life would be :zzz: without Emoji, right? :rocket:
diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb
index 95719b4b49f..dd4c1d645e2 100644
--- a/spec/helpers/diff_helper_spec.rb
+++ b/spec/helpers/diff_helper_spec.rb
@@ -5,7 +5,8 @@ describe DiffHelper do
let(:project) { create(:project) }
let(:commit) { project.commit(sample_commit.id) }
- let(:diff) { commit.diffs.first }
+ let(:diffs) { commit.diffs }
+ let(:diff) { diffs.first }
let(:diff_file) { Gitlab::Diff::File.new(diff) }
describe 'diff_hard_limit_enabled?' do
@@ -30,6 +31,57 @@ describe DiffHelper do
end
end
+ describe 'allowed_diff_lines' do
+ it 'should return hard limit for number of lines in a diff if force diff is true' do
+ allow(controller).to receive(:params) { { force_show_diff: true } }
+ expect(allowed_diff_lines).to eq(50000)
+ end
+
+ it 'should return safe limit for numbers of lines a diff if force diff is false' do
+ expect(allowed_diff_lines).to eq(5000)
+ end
+ end
+
+ describe 'safe_diff_files' do
+ it 'should return all files from a commit that is smaller than safe limits' do
+ expect(safe_diff_files(diffs).length).to eq(2)
+ end
+
+ it 'should return only the first file if the diff line count in the 2nd file takes the total beyond safe limits' do
+ diffs[1].diff.stub(lines: [""] * 4999) #simulate 4999 lines
+ expect(safe_diff_files(diffs).length).to eq(1)
+ end
+
+ it 'should return all files from a commit that is beyond safe limit for numbers of lines if force diff is true' do
+ allow(controller).to receive(:params) { { force_show_diff: true } }
+ diffs[1].diff.stub(lines: [""] * 4999) #simulate 4999 lines
+ expect(safe_diff_files(diffs).length).to eq(2)
+ end
+
+ it 'should return only the first file if the diff line count in the 2nd file takes the total beyond hard limits' do
+ allow(controller).to receive(:params) { { force_show_diff: true } }
+ diffs[1].diff.stub(lines: [""] * 49999) #simulate 49999 lines
+ expect(safe_diff_files(diffs).length).to eq(1)
+ end
+
+ it 'should return only a safe number of file diffs if a commit touches more files than the safe limits' do
+ large_diffs = diffs * 100 #simulate 200 diffs
+ expect(safe_diff_files(large_diffs).length).to eq(100)
+ end
+
+ it 'should return all file diffs if a commit touches more files than the safe limits but force diff is true' do
+ allow(controller).to receive(:params) { { force_show_diff: true } }
+ large_diffs = diffs * 100 #simulate 200 diffs
+ expect(safe_diff_files(large_diffs).length).to eq(200)
+ end
+
+ it 'should return a limited file diffs if a commit touches more files than the hard limits and force diff is true' do
+ allow(controller).to receive(:params) { { force_show_diff: true } }
+ very_large_diffs = diffs * 1000 #simulate 2000 diffs
+ expect(safe_diff_files(very_large_diffs).length).to eq(1000)
+ end
+ end
+
describe 'parallel_diff' do
it 'should return an array of arrays containing the parsed diff' do
expect(parallel_diff(diff_file, 0)).
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index f626efe1f76..dbcf7286e45 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -5,9 +5,9 @@ describe Notify do
include EmailSpec::Matchers
include RepoHelpers
- let(:gitlab_sender_display_name) { Gitlab.config.outgoing_emails.display_name }
- let(:gitlab_sender) { Gitlab.config.outgoing_emails.from }
- let(:gitlab_sender_reply_to) { Gitlab.config.outgoing_emails.reply_to }
+ let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name }
+ let(:gitlab_sender) { Gitlab.config.gitlab.email_from }
+ let(:gitlab_sender_reply_to) { Gitlab.config.gitlab.email_reply_to }
let(:recipient) { create(:user, email: 'recipient@example.com') }
let(:project) { create(:project) }
diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb
index af37e8319a4..e7558f28768 100644
--- a/spec/services/git_push_service_spec.rb
+++ b/spec/services/git_push_service_spec.rb
@@ -234,5 +234,18 @@ describe GitPushService do
expect(Issue.find(issue.id)).to be_opened
end
end
-end
+ describe "empty project" do
+ let(:project) { create(:project_empty_repo) }
+ let(:new_ref) { 'refs/heads/feature'}
+
+ before do
+ allow(project).to receive(:default_branch).and_return('feature')
+ expect(project).to receive(:change_head) { 'feature'}
+ end
+
+ it 'push to first branch updates HEAD' do
+ service.execute(project, user, @blankrev, @newrev, new_ref)
+ end
+ end
+end