Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/users_controller_spec.rb48
-rw-r--r--spec/lib/gitlab/reference_extractor_spec.rb14
-rw-r--r--spec/models/external_wiki_service_spec.rb39
-rw-r--r--spec/models/note_spec.rb153
-rw-r--r--spec/models/project_services/buildbox_service_spec.rb2
-rw-r--r--spec/models/project_services/gitlab_ci_service_spec.rb4
-rw-r--r--spec/models/repository_spec.rb19
7 files changed, 255 insertions, 24 deletions
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index 44225c054f2..7962bcdde71 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -1,27 +1,59 @@
require 'spec_helper'
describe UsersController do
- let(:user) { create(:user, username: "user1", name: "User 1", email: "user1@gitlab.com") }
+ let(:user) { create(:user, username: 'user1', name: 'User 1', email: 'user1@gitlab.com') }
before do
sign_in(user)
end
- describe "GET #show" do
+ describe 'GET #show' do
render_views
- it "renders the show template" do
+ 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 render_template('show')
end
end
- describe "GET #calendar" do
- it "renders calendar" do
+ describe 'GET #calendar' do
+ it 'renders calendar' do
get :calendar, username: user.username
- expect(response).to render_template("calendar")
+ expect(response).to render_template('calendar')
end
end
-end
+ describe 'GET #calendar_activities' do
+ include RepoHelpers
+ let(:project) { create(:project) }
+ let(:calendar_user) { create(:user, email: sample_commit.author_email) }
+ let(:commit1) { '0ed8c6c6752e8c6ea63e7b92a517bf5ac1209c80' }
+ let(:commit2) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' }
+
+ before do
+ allow_any_instance_of(User).to receive(:contributed_projects_ids).and_return([project.id])
+ project.team << [user, :developer]
+ end
+
+ it 'assigns @commit_count' do
+ get :calendar_activities, username: calendar_user.username, date: '2014-07-31'
+ expect(assigns(:commit_count)).to eq(2)
+ end
+
+ it 'assigns @calendar_date' do
+ get :calendar_activities, username: calendar_user.username, date: '2014-07-31'
+ expect(assigns(:calendar_date)).to eq(Date.parse('2014-07-31'))
+ end
+
+ it 'assigns @calendar_activities' do
+ get :calendar_activities, username: calendar_user.username, date: '2014-07-31'
+ expect(assigns(:calendar_activities).values.flatten.map(&:id)).to eq([commit1, commit2])
+ end
+
+ it 'renders calendar_activities' do
+ get :calendar_activities, username: calendar_user.username
+ expect(response).to render_template('calendar_activities')
+ end
+ end
+end
diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb
index 034f8ee7c45..5ebe44f6fb7 100644
--- a/spec/lib/gitlab/reference_extractor_spec.rb
+++ b/spec/lib/gitlab/reference_extractor_spec.rb
@@ -120,4 +120,18 @@ describe Gitlab::ReferenceExtractor do
expect(extracted[0][1].message).to eq(commit.message)
end
end
+
+ context 'with a project with an underscore' do
+ let(:project) { create(:project, path: 'test_project') }
+ let(:issue) { create(:issue, project: project) }
+
+ it 'handles project issue references' do
+ subject.analyze("this refers issue #{project.path_with_namespace}##{issue.iid}",
+ project)
+ extracted = subject.issues_for(project)
+ expect(extracted.size).to eq(1)
+ expect(extracted).to eq([issue])
+ end
+
+ end
end
diff --git a/spec/models/external_wiki_service_spec.rb b/spec/models/external_wiki_service_spec.rb
new file mode 100644
index 00000000000..78ef687d29c
--- /dev/null
+++ b/spec/models/external_wiki_service_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe ExternalWikiService do
+ include ExternalWikiHelper
+ describe "Associations" do
+ it { should belong_to :project }
+ it { should have_one :service_hook }
+ end
+
+ describe "Validations" do
+ context "active" do
+ before do
+ subject.active = true
+ end
+
+ it { should validate_presence_of :external_wiki_url }
+ end
+ end
+
+ describe 'External wiki' do
+ let(:project) { create(:project) }
+
+ context 'when it is active' do
+ before do
+ properties = { 'external_wiki_url' => 'https://gitlab.com' }
+ @service = project.create_external_wiki_service(active: true, properties: properties)
+ end
+
+ after do
+ @service.destroy!
+ end
+
+ it 'should replace the wiki url' do
+ wiki_path = get_project_wiki_path(project)
+ wiki_path.should match('https://gitlab.com')
+ end
+ end
+ end
+end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 17cb439c90e..a7bf5081d5b 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -182,14 +182,14 @@ describe Note do
describe '#note' do
subject { super().note }
- it { is_expected.to match(/Status changed to #{status}/) }
+ it { is_expected.to eq("Status changed to #{status}") }
end
it 'appends a back-reference if a closing mentionable is supplied' do
commit = double('commit', gfm_reference: 'commit 123456')
n = Note.create_status_change_note(thing, project, author, status, commit)
- expect(n.note).to match(/Status changed to #{status} by commit 123456/)
+ expect(n.note).to eq("Status changed to #{status} by commit 123456")
end
end
@@ -197,7 +197,7 @@ describe Note do
let(:project) { create(:project) }
let(:thing) { create(:issue, project: project) }
let(:author) { create(:user) }
- let(:assignee) { create(:user) }
+ let(:assignee) { create(:user, username: "assigned_user") }
subject { Note.create_assignee_change_note(thing, project, author, assignee) }
@@ -227,7 +227,7 @@ describe Note do
describe '#note' do
subject { super().note }
- it { is_expected.to match(/Reassigned to @#{assignee.username}/) }
+ it { is_expected.to eq('Reassigned to @assigned_user') }
end
context 'assignee is removed' do
@@ -235,11 +235,95 @@ describe Note do
describe '#note' do
subject { super().note }
- it { is_expected.to match(/Assignee removed/) }
+ it { is_expected.to eq('Assignee removed') }
end
end
end
+ describe '#create_labels_change_note' do
+ let(:project) { create(:project) }
+ let(:thing) { create(:issue, project: project) }
+ let(:author) { create(:user) }
+ let(:label1) { create(:label) }
+ let(:label2) { create(:label) }
+ let(:added_labels) { [label1, label2] }
+ let(:removed_labels) { [] }
+
+ subject { Note.create_labels_change_note(thing, project, author, added_labels, removed_labels) }
+
+ context 'creates and saves a Note' do
+ it { is_expected.to be_a Note }
+
+ describe '#id' do
+ subject { super().id }
+ it { is_expected.not_to be_nil }
+ end
+ end
+
+ describe '#noteable' do
+ subject { super().noteable }
+ it { is_expected.to eq(thing) }
+ end
+
+ describe '#project' do
+ subject { super().project }
+ it { is_expected.to eq(thing.project) }
+ end
+
+ describe '#author' do
+ subject { super().author }
+ it { is_expected.to eq(author) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to eq("Added ~#{label1.id} ~#{label2.id} labels") }
+ end
+
+ context 'label is removed' do
+ let(:added_labels) { [label1] }
+ let(:removed_labels) { [label2] }
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to eq("Added ~#{label1.id} and removed ~#{label2.id} labels") }
+ end
+ end
+ end
+
+ describe '#create_milestone_change_note' do
+ let(:project) { create(:project) }
+ let(:thing) { create(:issue, project: project) }
+ let(:milestone) { create(:milestone, project: project, title: "first_milestone") }
+ let(:author) { create(:user) }
+
+ subject { Note.create_milestone_change_note(thing, project, author, milestone) }
+
+ context 'creates and saves a Note' do
+ it { is_expected.to be_a Note }
+
+ describe '#id' do
+ subject { super().id }
+ it { is_expected.not_to be_nil }
+ end
+ end
+
+ describe '#project' do
+ subject { super().project }
+ it { is_expected.to eq(thing.project) }
+ end
+
+ describe '#author' do
+ subject { super().author }
+ it { is_expected.to eq(author) }
+ end
+
+ describe '#note' do
+ subject { super().note }
+ it { is_expected.to eq("Milestone changed to first_milestone") }
+ end
+ end
+
describe '#create_cross_reference_note' do
let(:project) { create(:project) }
let(:author) { create(:user) }
@@ -272,7 +356,7 @@ describe Note do
describe '#note' do
subject { super().note }
- it { is_expected.to eq("_mentioned in merge request !#{mergereq.iid}_") }
+ it { is_expected.to eq("mentioned in merge request !#{mergereq.iid}") }
end
end
@@ -288,7 +372,7 @@ describe Note do
describe '#note' do
subject { super().note }
- it { is_expected.to eq("_mentioned in commit #{commit.sha}_") }
+ it { is_expected.to eq("mentioned in commit #{commit.sha}") }
end
end
@@ -309,7 +393,7 @@ describe Note do
describe '#note' do
subject { super().note }
- it { is_expected.to eq("_mentioned in issue ##{issue.iid}_") }
+ it { is_expected.to eq("mentioned in issue ##{issue.iid}") }
end
end
@@ -330,7 +414,7 @@ describe Note do
describe '#note' do
subject { super().note }
- it { is_expected.to eq("_mentioned in merge request !#{mergereq.iid}_") }
+ it { is_expected.to eq("mentioned in merge request !#{mergereq.iid}") }
end
end
@@ -362,7 +446,7 @@ describe Note do
describe '#note' do
subject { super().note }
- it { is_expected.to eq("_mentioned in issue ##{issue.iid}_") }
+ it { is_expected.to eq("mentioned in issue ##{issue.iid}") }
end
end
@@ -389,7 +473,7 @@ describe Note do
describe '#note' do
subject { super().note }
- it { is_expected.to eq("_mentioned in commit #{parent_commit.id}_") }
+ it { is_expected.to eq("mentioned in commit #{parent_commit.id}") }
end
end
end
@@ -421,6 +505,41 @@ describe Note do
it { expect(Note.cross_reference_exists?(commit0, commit1)).to be_truthy }
it { expect(Note.cross_reference_exists?(commit1, commit0)).to be_falsey }
end
+
+ context 'legacy note with Markdown emphasis' do
+ let(:issue2) { create :issue, project: project }
+ let!(:note) do
+ create :note, system: true, noteable_id: issue2.id,
+ noteable_type: "Issue", note: "_mentioned in issue " \
+ "#{issue.project.path_with_namespace}##{issue.iid}_"
+ end
+
+ it 'detects if a mentionable with emphasis has been mentioned' do
+ expect(Note.cross_reference_exists?(issue2, issue)).to be_truthy
+ end
+ end
+ end
+
+ describe '#cross_references_with_underscores?' do
+ let(:project) { create :project, path: "first_project" }
+ let(:second_project) { create :project, path: "second_project" }
+
+ let(:author) { create :user }
+ let(:issue0) { create :issue, project: project }
+ let(:issue1) { create :issue, project: second_project }
+ let!(:note) { Note.create_cross_reference_note(issue0, issue1, author, project) }
+
+ it 'detects if a mentionable has already been mentioned' do
+ expect(Note.cross_reference_exists?(issue0, issue1)).to be_truthy
+ end
+
+ it 'detects if a mentionable has not already been mentioned' do
+ expect(Note.cross_reference_exists?(issue1, issue0)).to be_falsey
+ end
+
+ it 'detects that text has underscores' do
+ expect(note.note).to eq("mentioned in issue #{second_project.path_with_namespace}##{issue1.iid}")
+ end
end
describe '#system?' do
@@ -429,6 +548,8 @@ describe Note do
let(:other) { create(:issue, project: project) }
let(:author) { create(:user) }
let(:assignee) { create(:user) }
+ let(:label) { create(:label) }
+ let(:milestone) { create(:milestone) }
it 'should recognize user-supplied notes as non-system' do
@note = create(:note_on_issue)
@@ -449,6 +570,16 @@ describe Note do
@note = Note.create_assignee_change_note(issue, project, author, assignee)
expect(@note).to be_system
end
+
+ it 'should identify label-change notes as system notes' do
+ @note = Note.create_labels_change_note(issue, project, author, [label], [])
+ expect(@note).to be_system
+ end
+
+ it 'should identify milestone-change notes as system notes' do
+ @note = Note.create_milestone_change_note(issue, project, author, milestone)
+ expect(@note).to be_system
+ end
end
describe :authorization do
diff --git a/spec/models/project_services/buildbox_service_spec.rb b/spec/models/project_services/buildbox_service_spec.rb
index 39d7df54cf0..fcbf3e45b9a 100644
--- a/spec/models/project_services/buildbox_service_spec.rb
+++ b/spec/models/project_services/buildbox_service_spec.rb
@@ -59,7 +59,7 @@ describe BuildboxService do
describe :build_page do
it 'returns the correct build page' do
- expect(@service.build_page('2ab7834c')).to eq(
+ expect(@service.build_page('2ab7834c', nil)).to eq(
'https://buildbox.io/account-name/example-project/builds?commit=2ab7834c'
)
end
diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb
index 8bfb19e524b..610f33c5823 100644
--- a/spec/models/project_services/gitlab_ci_service_spec.rb
+++ b/spec/models/project_services/gitlab_ci_service_spec.rb
@@ -39,11 +39,11 @@ describe GitlabCiService do
end
describe :commit_status_path do
- it { expect(@service.commit_status_path("2ab7834c")).to eq("http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret")}
+ it { expect(@service.commit_status_path("2ab7834c", 'master')).to eq("http://ci.gitlab.org/projects/2/refs/master/commits/2ab7834c/status.json?token=verySecret")}
end
describe :build_page do
- it { expect(@service.build_page("2ab7834c")).to eq("http://ci.gitlab.org/projects/2/commits/2ab7834c")}
+ it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://ci.gitlab.org/projects/2/refs/master/commits/2ab7834c")}
end
end
end
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index b3a38f6c5b9..0e3e0b167d7 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -29,7 +29,7 @@ describe Repository do
subject { repository.timestamps_by_user_log(user) }
- it { is_expected.to eq(["2014-08-06", "2014-07-31", "2014-07-31"]) }
+ it { is_expected.to eq(['2014-08-06', '2014-07-31', '2014-07-31']) }
end
describe 'multiple emails for user' do
@@ -38,7 +38,22 @@ describe Repository do
subject { repository.timestamps_by_user_log(user) }
- it { is_expected.to eq(["2015-01-10", "2014-08-06", "2014-07-31", "2014-07-31"]) }
+ it { is_expected.to eq(['2015-01-10', '2014-08-06', '2014-07-31', '2014-07-31']) }
+ end
+ end
+
+ context :commits_by_user_on_date_log do
+
+ describe 'single e-mail for user' do
+ let(:user) { create(:user, email: sample_commit.author_email) }
+ let(:commit1) { '0ed8c6c6752e8c6ea63e7b92a517bf5ac1209c80' }
+ let(:commit2) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' }
+
+ subject { repository.commits_by_user_on_date_log(user,Date.new(2014, 07, 31)) }
+
+ it 'contains the exepected commits' do
+ expect(subject.flatten.map(&:id)).to eq([commit1, commit2])
+ end
end
end
end