summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-20 12:43:32 +0100
committerSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-20 12:43:32 +0100
commiteefb27f5ae0edf0c005eb8ce6da56cbd17c9aa8a (patch)
tree9dc7d17953ee7851e1934903b45faf5f18d860a2 /spec
parent1b97a2eee8b89320de891e3ae8496adfa7f3a84b (diff)
parentb7ac654b88aa9b03f431d93c25e397ff2bc66a7a (diff)
downloadgitlab-ce-eefb27f5ae0edf0c005eb8ce6da56cbd17c9aa8a.tar.gz
Merge branch 'master' into fixes/api
Conflicts: spec/requests/api/projects_spec.rb
Diffstat (limited to 'spec')
-rw-r--r--spec/factories.rb32
-rw-r--r--spec/factories_spec.rb5
-rw-r--r--spec/models/concerns/issuable_spec.rb1
-rw-r--r--spec/models/issue_spec.rb35
-rw-r--r--spec/models/key_spec.rb6
-rw-r--r--spec/models/merge_request_spec.rb37
-rw-r--r--spec/models/milestone_spec.rb39
-rw-r--r--spec/models/project_spec.rb8
-rw-r--r--spec/observers/issue_observer_spec.rb159
-rw-r--r--spec/observers/merge_request_observer_spec.rb119
-rw-r--r--spec/requests/api/issues_spec.rb16
-rw-r--r--spec/requests/api/merge_requests_spec.rb17
-rw-r--r--spec/requests/api/milestones_spec.rb10
-rw-r--r--spec/requests/api/projects_spec.rb62
-rw-r--r--spec/requests/issues_spec.rb3
15 files changed, 273 insertions, 276 deletions
diff --git a/spec/factories.rb b/spec/factories.rb
index d2e9f48c47b..b81984b5d53 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -54,10 +54,15 @@ FactoryGirl.define do
project
trait :closed do
- closed true
+ state :closed
+ end
+
+ trait :reopened do
+ state :reopened
end
factory :closed_issue, traits: [:closed]
+ factory :reopened_issue, traits: [:reopened]
end
factory :merge_request do
@@ -67,10 +72,6 @@ FactoryGirl.define do
source_branch "master"
target_branch "stable"
- trait :closed do
- closed true
- end
-
# pick 3 commits "at random" (from bcf03b5d~3 to bcf03b5d)
trait :with_diffs do
target_branch "master" # pretend bcf03b5d~3
@@ -85,7 +86,16 @@ FactoryGirl.define do
end
end
+ trait :closed do
+ state :closed
+ end
+
+ trait :reopened do
+ state :reopened
+ end
+
factory :closed_merge_request, traits: [:closed]
+ factory :reopened_merge_request, traits: [:reopened]
factory :merge_request_with_diffs, traits: [:with_diffs]
end
@@ -148,11 +158,23 @@ FactoryGirl.define do
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa ++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
end
end
+
+ factory :invalid_key do
+ key do
+ "ssh-rsa this_is_invalid_key=="
+ end
+ end
end
factory :milestone do
title
project
+
+ trait :closed do
+ state :closed
+ end
+
+ factory :closed_milestone, traits: [:closed]
end
factory :system_hook do
diff --git a/spec/factories_spec.rb b/spec/factories_spec.rb
index 5ee7354688a..8360477d8fe 100644
--- a/spec/factories_spec.rb
+++ b/spec/factories_spec.rb
@@ -1,6 +1,9 @@
require 'spec_helper'
-INVALID_FACTORIES = [:key_with_a_space_in_the_middle]
+INVALID_FACTORIES = [
+ :key_with_a_space_in_the_middle,
+ :invalid_key,
+]
FactoryGirl.factories.map(&:name).each do |factory_name|
next if INVALID_FACTORIES.include?(factory_name)
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index b5d4bd7b406..551e1753be0 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -15,7 +15,6 @@ describe Issue, "Issuable" do
it { should validate_presence_of(:author) }
it { should validate_presence_of(:title) }
it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) }
- it { should ensure_inclusion_of(:closed).in_array([true, false]) }
end
describe "Scope" do
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 10db53e0745..99d9f65b0d7 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -9,7 +9,7 @@
# project_id :integer
# created_at :datetime not null
# updated_at :datetime not null
-# closed :boolean default(FALSE), not null
+# state :string default(FALSE), not null
# position :integer default(0)
# branch_name :string(255)
# description :text
@@ -44,34 +44,15 @@ describe Issue do
end
end
- describe '#is_being_closed?' do
- it 'returns true if the closed attribute has changed and is now true' do
- subject.closed = true
- subject.is_being_closed?.should be_true
- end
- it 'returns false if the closed attribute has changed and is now false' do
- issue = create(:closed_issue)
- issue.closed = false
- issue.is_being_closed?.should be_false
- end
- it 'returns false if the closed attribute has not changed' do
- subject.is_being_closed?.should be_false
- end
- end
+ describe '#is_being_reassigned?' do
+ it 'returnes issues assigned to user' do
+ user = create :user
+ 2.times do
+ issue = create :issue, assignee: user
+ end
- describe '#is_being_reopened?' do
- it 'returns true if the closed attribute has changed and is now false' do
- issue = create(:closed_issue)
- issue.closed = false
- issue.is_being_reopened?.should be_true
- end
- it 'returns false if the closed attribute has changed and is now true' do
- subject.closed = true
- subject.is_being_reopened?.should be_false
- end
- it 'returns false if the closed attribute has not changed' do
- subject.is_being_reopened?.should be_false
+ Issue.open_for(user).count.should eq 2
end
end
end
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb
index 94b952cf932..a9ab2f05a34 100644
--- a/spec/models/key_spec.rb
+++ b/spec/models/key_spec.rb
@@ -73,8 +73,12 @@ describe Key do
build(:key, user: user).should be_valid
end
- it "rejects the unfingerprintable key" do
+ it "rejects the unfingerprintable key (contains space in middle)" do
build(:key_with_a_space_in_the_middle).should_not be_valid
end
+
+ it "rejects the unfingerprintable key (not a key)" do
+ build(:invalid_key).should_not be_valid
+ end
end
end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 41f4ede5d89..e61bf44ce53 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -15,7 +15,7 @@
# st_commits :text(2147483647)
# st_diffs :text(2147483647)
# merged :boolean default(FALSE), not null
-# state :integer default(1), not null
+# merge_status :integer default(1), not null
# milestone_id :integer
#
@@ -37,6 +37,10 @@ describe MergeRequest do
end
describe "#mr_and_commit_notes" do
+
+ end
+
+ describe "#mr_and_commit_notes" do
let!(:merge_request) { create(:merge_request) }
before do
@@ -62,35 +66,4 @@ describe MergeRequest do
subject.is_being_reassigned?.should be_false
end
end
-
- describe '#is_being_closed?' do
- it 'returns true if the closed attribute has changed and is now true' do
- subject.closed = true
- subject.is_being_closed?.should be_true
- end
- it 'returns false if the closed attribute has changed and is now false' do
- merge_request = create(:closed_merge_request)
- merge_request.closed = false
- merge_request.is_being_closed?.should be_false
- end
- it 'returns false if the closed attribute has not changed' do
- subject.is_being_closed?.should be_false
- end
- end
-
-
- describe '#is_being_reopened?' do
- it 'returns true if the closed attribute has changed and is now false' do
- merge_request = create(:closed_merge_request)
- merge_request.closed = false
- merge_request.is_being_reopened?.should be_true
- end
- it 'returns false if the closed attribute has changed and is now true' do
- subject.closed = true
- subject.is_being_reopened?.should be_false
- end
- it 'returns false if the closed attribute has not changed' do
- subject.is_being_reopened?.should be_false
- end
- end
end
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index 2ea2c56a6f7..b473f843146 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -7,7 +7,7 @@
# project_id :integer not null
# description :text
# due_date :date
-# closed :boolean default(FALSE), not null
+# state :string default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
#
@@ -27,7 +27,6 @@ describe Milestone do
describe "Validation" do
it { should validate_presence_of(:title) }
it { should validate_presence_of(:project) }
- it { should ensure_inclusion_of(:closed).in_array([true, false]) }
end
let(:milestone) { create(:milestone) }
@@ -41,7 +40,7 @@ describe Milestone do
it "should count closed issues" do
IssueObserver.current_user = issue.author
- issue.update_attributes(closed: true)
+ issue.close
milestone.issues << issue
milestone.percent_complete.should == 100
end
@@ -96,7 +95,7 @@ describe Milestone do
describe :items_count do
before do
milestone.issues << create(:issue)
- milestone.issues << create(:issue, closed: true)
+ milestone.issues << create(:closed_issue)
milestone.merge_requests << create(:merge_request)
end
@@ -110,7 +109,35 @@ describe Milestone do
it { milestone.can_be_closed?.should be_true }
end
- describe :open? do
- it { milestone.open?.should be_true }
+ describe :is_empty? do
+ before do
+ issue = create :closed_issue, milestone: milestone
+ merge_request = create :merge_request, milestone: milestone
+ end
+
+ it 'Should return total count of issues and merge requests assigned to milestone' do
+ milestone.total_items_count.should eq 2
+ end
+ end
+
+ describe :can_be_closed? do
+ before do
+ milestone = create :milestone
+ create :closed_issue, milestone: milestone
+
+ issue = create :issue
+ end
+
+ it 'should be true if milestone active and all nestied issues closed' do
+ milestone.can_be_closed?.should be_true
+ end
+
+ it 'should be false if milestone active and not all nestied issues closed' do
+ issue.milestone = milestone
+ issue.save
+
+ milestone.can_be_closed?.should be_false
+ end
end
+
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 4b620a2fa3e..5c27f363401 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -121,10 +121,7 @@ describe Project do
let(:project) { create(:project) }
before do
- @merge_request = create(:merge_request,
- project: project,
- merged: false,
- closed: false)
+ @merge_request = create(:merge_request, project: project)
@key = create(:key, user_id: project.owner.id)
end
@@ -133,8 +130,7 @@ describe Project do
@merge_request.last_commit.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a", "refs/heads/stable", @key.user)
@merge_request.reload
- @merge_request.merged.should be_true
- @merge_request.closed.should be_true
+ @merge_request.merged?.should be_true
end
it "should update merge request commits with new one if pushed to source branch" do
diff --git a/spec/observers/issue_observer_spec.rb b/spec/observers/issue_observer_spec.rb
index 700c9a3a69b..e4e66917e8a 100644
--- a/spec/observers/issue_observer_spec.rb
+++ b/spec/observers/issue_observer_spec.rb
@@ -1,10 +1,15 @@
require 'spec_helper'
describe IssueObserver do
- let(:some_user) { double(:user, id: 1) }
- let(:assignee) { double(:user, id: 2) }
- let(:author) { double(:user, id: 3) }
- let(:issue) { double(:issue, id: 42, assignee: assignee, author: author) }
+ let(:some_user) { create :user }
+ let(:assignee) { create :user }
+ let(:author) { create :user }
+ let(:mock_issue) { double(:issue, id: 42, assignee: assignee, author: author) }
+ let(:assigned_issue) { create(:issue, assignee: assignee, author: author) }
+ let(:unassigned_issue) { create(:issue, author: author) }
+ let(:closed_assigned_issue) { create(:closed_issue, assignee: assignee, author: author) }
+ let(:closed_unassigned_issue) { create(:closed_issue, author: author) }
+
before(:each) { subject.stub(:current_user).and_return(some_user) }
@@ -21,137 +26,91 @@ describe IssueObserver do
end
it 'sends an email to the assignee' do
- Notify.should_receive(:new_issue_email).with(issue.id)
+ Notify.should_receive(:new_issue_email).with(mock_issue.id)
- subject.after_create(issue)
+ subject.after_create(mock_issue)
end
it 'does not send an email to the assignee if assignee created the issue' do
subject.stub(:current_user).and_return(assignee)
Notify.should_not_receive(:new_issue_email)
- subject.after_create(issue)
+ subject.after_create(mock_issue)
end
end
- context '#after_update' do
- before(:each) do
- issue.stub(:is_being_reassigned?).and_return(false)
- issue.stub(:is_being_closed?).and_return(false)
- issue.stub(:is_being_reopened?).and_return(false)
- end
-
- it 'is called when an issue is changed' do
- changed = create(:issue, project: create(:project))
- subject.should_receive(:after_update)
-
- Issue.observers.enable :issue_observer do
- changed.description = 'I changed'
- changed.save
- end
- end
-
- context 'a reassigned email' do
- it 'is sent if the issue is being reassigned' do
- issue.should_receive(:is_being_reassigned?).and_return(true)
- subject.should_receive(:send_reassigned_email).with(issue)
-
- subject.after_update(issue)
- end
-
- it 'is not sent if the issue is not being reassigned' do
- issue.should_receive(:is_being_reassigned?).and_return(false)
- subject.should_not_receive(:send_reassigned_email)
-
- subject.after_update(issue)
- end
- end
-
+ context '#after_close' do
context 'a status "closed"' do
it 'note is created if the issue is being closed' do
- issue.should_receive(:is_being_closed?).and_return(true)
- Notify.should_receive(:issue_status_changed_email).twice
- Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed')
-
- subject.after_update(issue)
- end
-
- it 'note is not created if the issue is not being closed' do
- issue.should_receive(:is_being_closed?).and_return(false)
- Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'closed')
+ Note.should_receive(:create_status_change_note).with(assigned_issue, some_user, 'closed')
- subject.after_update(issue)
+ assigned_issue.close
end
it 'notification is delivered if the issue being closed' do
- issue.stub(:is_being_closed?).and_return(true)
Notify.should_receive(:issue_status_changed_email).twice
- Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed')
- subject.after_update(issue)
- end
-
- it 'notification is not delivered if the issue not being closed' do
- issue.stub(:is_being_closed?).and_return(false)
- Notify.should_not_receive(:issue_status_changed_email)
- Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'closed')
-
- subject.after_update(issue)
+ assigned_issue.close
end
it 'notification is delivered only to author if the issue being closed' do
- issue_without_assignee = double(:issue, id: 42, author: author, assignee: nil)
- issue_without_assignee.stub(:is_being_reassigned?).and_return(false)
- issue_without_assignee.stub(:is_being_closed?).and_return(true)
- issue_without_assignee.stub(:is_being_reopened?).and_return(false)
Notify.should_receive(:issue_status_changed_email).once
- Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed')
+ Note.should_receive(:create_status_change_note).with(unassigned_issue, some_user, 'closed')
- subject.after_update(issue_without_assignee)
+ unassigned_issue.close
end
end
context 'a status "reopened"' do
it 'note is created if the issue is being reopened' do
+ Note.should_receive(:create_status_change_note).with(closed_assigned_issue, some_user, 'reopened')
+
+ closed_assigned_issue.reopen
+ end
+
+ it 'notification is delivered if the issue being reopened' do
Notify.should_receive(:issue_status_changed_email).twice
- issue.should_receive(:is_being_reopened?).and_return(true)
- Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened')
- subject.after_update(issue)
+ closed_assigned_issue.reopen
end
- it 'note is not created if the issue is not being reopened' do
- issue.should_receive(:is_being_reopened?).and_return(false)
- Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'reopened')
+ it 'notification is delivered only to author if the issue being reopened' do
+ Notify.should_receive(:issue_status_changed_email).once
+ Note.should_receive(:create_status_change_note).with(closed_unassigned_issue, some_user, 'reopened')
- subject.after_update(issue)
+ closed_unassigned_issue.reopen
end
+ end
+ end
- it 'notification is delivered if the issue being reopened' do
- issue.stub(:is_being_reopened?).and_return(true)
- Notify.should_receive(:issue_status_changed_email).twice
- Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened')
+ context '#after_update' do
+ before(:each) do
+ mock_issue.stub(:is_being_reassigned?).and_return(false)
+ end
+
+ it 'is called when an issue is changed' do
+ changed = create(:issue, project: create(:project))
+ subject.should_receive(:after_update)
- subject.after_update(issue)
+ Issue.observers.enable :issue_observer do
+ changed.description = 'I changed'
+ changed.save
end
+ end
- it 'notification is not delivered if the issue not being reopened' do
- issue.stub(:is_being_reopened?).and_return(false)
- Notify.should_not_receive(:issue_status_changed_email)
- Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'reopened')
+ context 'a reassigned email' do
+ it 'is sent if the issue is being reassigned' do
+ mock_issue.should_receive(:is_being_reassigned?).and_return(true)
+ subject.should_receive(:send_reassigned_email).with(mock_issue)
- subject.after_update(issue)
+ subject.after_update(mock_issue)
end
- it 'notification is delivered only to author if the issue being reopened' do
- issue_without_assignee = double(:issue, id: 42, author: author, assignee: nil)
- issue_without_assignee.stub(:is_being_reassigned?).and_return(false)
- issue_without_assignee.stub(:is_being_closed?).and_return(false)
- issue_without_assignee.stub(:is_being_reopened?).and_return(true)
- Notify.should_receive(:issue_status_changed_email).once
- Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened')
+ it 'is not sent if the issue is not being reassigned' do
+ mock_issue.should_receive(:is_being_reassigned?).and_return(false)
+ subject.should_not_receive(:send_reassigned_email)
- subject.after_update(issue_without_assignee)
+ subject.after_update(mock_issue)
end
end
end
@@ -160,23 +119,23 @@ describe IssueObserver do
let(:previous_assignee) { double(:user, id: 3) }
before(:each) do
- issue.stub(:assignee_id).and_return(assignee.id)
- issue.stub(:assignee_id_was).and_return(previous_assignee.id)
+ mock_issue.stub(:assignee_id).and_return(assignee.id)
+ mock_issue.stub(:assignee_id_was).and_return(previous_assignee.id)
end
def it_sends_a_reassigned_email_to(recipient)
- Notify.should_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id)
+ Notify.should_receive(:reassigned_issue_email).with(recipient, mock_issue.id, previous_assignee.id)
end
def it_does_not_send_a_reassigned_email_to(recipient)
- Notify.should_not_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id)
+ Notify.should_not_receive(:reassigned_issue_email).with(recipient, mock_issue.id, previous_assignee.id)
end
it 'sends a reassigned email to the previous and current assignees' do
it_sends_a_reassigned_email_to assignee.id
it_sends_a_reassigned_email_to previous_assignee.id
- subject.send(:send_reassigned_email, issue)
+ subject.send(:send_reassigned_email, mock_issue)
end
context 'does not send an email to the user who made the reassignment' do
@@ -185,14 +144,14 @@ describe IssueObserver do
it_sends_a_reassigned_email_to previous_assignee.id
it_does_not_send_a_reassigned_email_to assignee.id
- subject.send(:send_reassigned_email, issue)
+ subject.send(:send_reassigned_email, mock_issue)
end
it 'if the user is the previous assignee' do
subject.stub(:current_user).and_return(previous_assignee)
it_sends_a_reassigned_email_to assignee.id
it_does_not_send_a_reassigned_email_to previous_assignee.id
- subject.send(:send_reassigned_email, issue)
+ subject.send(:send_reassigned_email, mock_issue)
end
end
end
diff --git a/spec/observers/merge_request_observer_spec.rb b/spec/observers/merge_request_observer_spec.rb
index 4841bf88fc5..9d702107a89 100644
--- a/spec/observers/merge_request_observer_spec.rb
+++ b/spec/observers/merge_request_observer_spec.rb
@@ -1,10 +1,14 @@
require 'spec_helper'
describe MergeRequestObserver do
- let(:some_user) { double(:user, id: 1) }
- let(:assignee) { double(:user, id: 2) }
- let(:author) { double(:user, id: 3) }
- let(:mr) { double(:merge_request, id: 42, assignee: assignee, author: author) }
+ let(:some_user) { create :user }
+ let(:assignee) { create :user }
+ let(:author) { create :user }
+ let(:mr_mock) { double(:merge_request, id: 42, assignee: assignee, author: author) }
+ let(:assigned_mr) { create(:merge_request, assignee: assignee, author: author) }
+ let(:unassigned_mr) { create(:merge_request, author: author) }
+ let(:closed_assigned_mr) { create(:closed_merge_request, assignee: assignee, author: author) }
+ let(:closed_unassigned_mr) { create(:closed_merge_request, author: author) }
before(:each) { subject.stub(:current_user).and_return(some_user) }
@@ -21,23 +25,21 @@ describe MergeRequestObserver do
end
it 'sends an email to the assignee' do
- Notify.should_receive(:new_merge_request_email).with(mr.id)
- subject.after_create(mr)
+ Notify.should_receive(:new_merge_request_email).with(mr_mock.id)
+ subject.after_create(mr_mock)
end
it 'does not send an email to the assignee if assignee created the merge request' do
subject.stub(:current_user).and_return(assignee)
Notify.should_not_receive(:new_merge_request_email)
- subject.after_create(mr)
+ subject.after_create(mr_mock)
end
end
context '#after_update' do
before(:each) do
- mr.stub(:is_being_reassigned?).and_return(false)
- mr.stub(:is_being_closed?).and_return(false)
- mr.stub(:is_being_reopened?).and_return(false)
+ mr_mock.stub(:is_being_reassigned?).and_return(false)
end
it 'is called when a merge request is changed' do
@@ -52,97 +54,50 @@ describe MergeRequestObserver do
context 'a reassigned email' do
it 'is sent if the merge request is being reassigned' do
- mr.should_receive(:is_being_reassigned?).and_return(true)
- subject.should_receive(:send_reassigned_email).with(mr)
+ mr_mock.should_receive(:is_being_reassigned?).and_return(true)
+ subject.should_receive(:send_reassigned_email).with(mr_mock)
- subject.after_update(mr)
+ subject.after_update(mr_mock)
end
it 'is not sent if the merge request is not being reassigned' do
- mr.should_receive(:is_being_reassigned?).and_return(false)
+ mr_mock.should_receive(:is_being_reassigned?).and_return(false)
subject.should_not_receive(:send_reassigned_email)
- subject.after_update(mr)
+ subject.after_update(mr_mock)
end
end
+ end
+
+ context '#after_close' do
context 'a status "closed"' do
it 'note is created if the merge request is being closed' do
- mr.should_receive(:is_being_closed?).and_return(true)
- Note.should_receive(:create_status_change_note).with(mr, some_user, 'closed')
-
- subject.after_update(mr)
- end
-
- it 'note is not created if the merge request is not being closed' do
- mr.should_receive(:is_being_closed?).and_return(false)
- Note.should_not_receive(:create_status_change_note).with(mr, some_user, 'closed')
-
- subject.after_update(mr)
- end
-
- it 'notification is delivered if the merge request being closed' do
- mr.stub(:is_being_closed?).and_return(true)
- Note.should_receive(:create_status_change_note).with(mr, some_user, 'closed')
-
- subject.after_update(mr)
- end
-
- it 'notification is not delivered if the merge request not being closed' do
- mr.stub(:is_being_closed?).and_return(false)
- Note.should_not_receive(:create_status_change_note).with(mr, some_user, 'closed')
+ Note.should_receive(:create_status_change_note).with(assigned_mr, some_user, 'closed')
- subject.after_update(mr)
+ assigned_mr.close
end
it 'notification is delivered only to author if the merge request is being closed' do
- mr_without_assignee = double(:merge_request, id: 42, author: author, assignee: nil)
- mr_without_assignee.stub(:is_being_reassigned?).and_return(false)
- mr_without_assignee.stub(:is_being_closed?).and_return(true)
- mr_without_assignee.stub(:is_being_reopened?).and_return(false)
- Note.should_receive(:create_status_change_note).with(mr_without_assignee, some_user, 'closed')
+ Note.should_receive(:create_status_change_note).with(unassigned_mr, some_user, 'closed')
- subject.after_update(mr_without_assignee)
+ unassigned_mr.close
end
end
+ end
+ context '#after_reopen' do
context 'a status "reopened"' do
it 'note is created if the merge request is being reopened' do
- mr.should_receive(:is_being_reopened?).and_return(true)
- Note.should_receive(:create_status_change_note).with(mr, some_user, 'reopened')
-
- subject.after_update(mr)
- end
-
- it 'note is not created if the merge request is not being reopened' do
- mr.should_receive(:is_being_reopened?).and_return(false)
- Note.should_not_receive(:create_status_change_note).with(mr, some_user, 'reopened')
-
- subject.after_update(mr)
- end
-
- it 'notification is delivered if the merge request being reopened' do
- mr.stub(:is_being_reopened?).and_return(true)
- Note.should_receive(:create_status_change_note).with(mr, some_user, 'reopened')
-
- subject.after_update(mr)
- end
-
- it 'notification is not delivered if the merge request is not being reopened' do
- mr.stub(:is_being_reopened?).and_return(false)
- Note.should_not_receive(:create_status_change_note).with(mr, some_user, 'reopened')
+ Note.should_receive(:create_status_change_note).with(closed_assigned_mr, some_user, 'reopened')
- subject.after_update(mr)
+ closed_assigned_mr.reopen
end
it 'notification is delivered only to author if the merge request is being reopened' do
- mr_without_assignee = double(:merge_request, id: 42, author: author, assignee: nil)
- mr_without_assignee.stub(:is_being_reassigned?).and_return(false)
- mr_without_assignee.stub(:is_being_closed?).and_return(false)
- mr_without_assignee.stub(:is_being_reopened?).and_return(true)
- Note.should_receive(:create_status_change_note).with(mr_without_assignee, some_user, 'reopened')
+ Note.should_receive(:create_status_change_note).with(closed_unassigned_mr, some_user, 'reopened')
- subject.after_update(mr_without_assignee)
+ closed_unassigned_mr.reopen
end
end
end
@@ -151,23 +106,23 @@ describe MergeRequestObserver do
let(:previous_assignee) { double(:user, id: 3) }
before(:each) do
- mr.stub(:assignee_id).and_return(assignee.id)
- mr.stub(:assignee_id_was).and_return(previous_assignee.id)
+ mr_mock.stub(:assignee_id).and_return(assignee.id)
+ mr_mock.stub(:assignee_id_was).and_return(previous_assignee.id)
end
def it_sends_a_reassigned_email_to(recipient)
- Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id)
+ Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr_mock.id, previous_assignee.id)
end
def it_does_not_send_a_reassigned_email_to(recipient)
- Notify.should_not_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id)
+ Notify.should_not_receive(:reassigned_merge_request_email).with(recipient, mr_mock.id, previous_assignee.id)
end
it 'sends a reassigned email to the previous and current assignees' do
it_sends_a_reassigned_email_to assignee.id
it_sends_a_reassigned_email_to previous_assignee.id
- subject.send(:send_reassigned_email, mr)
+ subject.send(:send_reassigned_email, mr_mock)
end
context 'does not send an email to the user who made the reassignment' do
@@ -176,14 +131,14 @@ describe MergeRequestObserver do
it_sends_a_reassigned_email_to previous_assignee.id
it_does_not_send_a_reassigned_email_to assignee.id
- subject.send(:send_reassigned_email, mr)
+ subject.send(:send_reassigned_email, mr_mock)
end
it 'if the user is the previous assignee' do
subject.stub(:current_user).and_return(previous_assignee)
it_sends_a_reassigned_email_to assignee.id
it_does_not_send_a_reassigned_email_to previous_assignee.id
- subject.send(:send_reassigned_email, mr)
+ subject.send(:send_reassigned_email, mr_mock)
end
end
end
diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb
index 781ebab026b..630ac0f820a 100644
--- a/spec/requests/api/issues_spec.rb
+++ b/spec/requests/api/issues_spec.rb
@@ -54,14 +54,24 @@ describe Gitlab::API do
end
end
- describe "PUT /projects/:id/issues/:issue_id" do
+ describe "PUT /projects/:id/issues/:issue_id to update only title" do
it "should update a project issue" do
put api("/projects/#{project.id}/issues/#{issue.id}", user),
- title: 'updated title', labels: 'label2', closed: 1
+ title: 'updated title'
response.status.should == 200
+
json_response['title'].should == 'updated title'
+ end
+ end
+
+ describe "PUT /projects/:id/issues/:issue_id to update state and label" do
+ it "should update a project issue" do
+ put api("/projects/#{project.id}/issues/#{issue.id}", user),
+ labels: 'label2', state_event: "close"
+ response.status.should == 200
+
json_response['labels'].should == ['label2']
- json_response['closed'].should be_true
+ json_response['state'].should eq "closed"
end
end
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 431aae7cc11..8de06c33394 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -66,6 +66,23 @@ describe Gitlab::API do
end
end
+ describe "PUT /projects/:id/merge_request/:merge_request_id to close MR" do
+ it "should return merge_request" do
+ put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), state_event: "close"
+ response.status.should == 200
+ json_response['state'].should == 'closed'
+ end
+ end
+
+ describe "PUT /projects/:id/merge_request/:merge_request_id to merge MR" do
+ it "should return merge_request" do
+ put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), state_event: "merge"
+ response.status.should == 200
+ json_response['state'].should == 'merged'
+ end
+ end
+
+
describe "PUT /projects/:id/merge_request/:merge_request_id" do
it "should return merge_request" do
put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), title: "New title"
diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb
index 3cab63557a9..00e800e8b91 100644
--- a/spec/requests/api/milestones_spec.rb
+++ b/spec/requests/api/milestones_spec.rb
@@ -68,4 +68,14 @@ describe Gitlab::API do
response.status.should == 404
end
end
+
+ describe "PUT /projects/:id/milestones/:milestone_id to close milestone" do
+ it "should update a project milestone" do
+ put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
+ state_event: 'close'
+ response.status.should == 200
+
+ json_response['state'].should == 'closed'
+ end
+ end
end
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 486b63e74e5..06ab0f5e684 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -33,6 +33,20 @@ describe Gitlab::API do
end
describe "POST /projects" do
+ context "maximum number of projects reached" do
+ before do
+ (1..user2.projects_limit).each do |project|
+ post api("/projects", user2), name: "foo#{project}"
+ end
+ end
+
+ it "should not create new project" do
+ expect {
+ post api("/projects", user2), name: 'foo'
+ }.to change {Project.count}.by(0)
+ end
+ end
+
it "should create new project without path" do
expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1)
end
@@ -46,6 +60,12 @@ describe Gitlab::API do
response.status.should == 400
end
+ it "should create last project before reaching project limit" do
+ (1..user2.projects_limit-1).each { |p| post api("/projects", user2), name: "foo#{p}" }
+ post api("/projects", user2), name: "foo"
+ response.status.should == 201
+ end
+
it "should respond with 201 on success" do
post api("/projects", user), name: 'foo'
response.status.should == 201
@@ -314,22 +334,44 @@ describe Gitlab::API do
end
describe "GET /projects/:id/hooks" do
- it "should return project hooks" do
- get api("/projects/#{project.id}/hooks", user)
+ context "authorized user" do
+ it "should return project hooks" do
+ get api("/projects/#{project.id}/hooks", user)
+ response.status.should == 200
- response.status.should == 200
+ json_response.should be_an Array
+ json_response.count.should == 1
+ json_response.first['url'].should == "http://example.com"
+ end
+ end
- json_response.should be_an Array
- json_response.count.should == 1
- json_response.first['url'].should == "http://example.com"
+ context "unauthorized user" do
+ it "should not access project hooks" do
+ get api("/projects/#{project.id}/hooks", user3)
+ response.status.should == 403
+ end
end
end
describe "GET /projects/:id/hooks/:hook_id" do
- it "should return a project hook" do
- get api("/projects/#{project.id}/hooks/#{hook.id}", user)
- response.status.should == 200
- json_response['url'].should == hook.url
+ context "authorized user" do
+ it "should return a project hook" do
+ get api("/projects/#{project.id}/hooks/#{hook.id}", user)
+ response.status.should == 200
+ json_response['url'].should == hook.url
+ end
+
+ it "should return a 404 error if hook id is not available" do
+ get api("/projects/#{project.id}/hooks/1234", user)
+ response.status.should == 404
+ end
+ end
+
+ context "unauthorized user" do
+ it "should not access an existing hook" do
+ get api("/projects/#{project.id}/hooks/#{hook.id}", user3)
+ response.status.should == 403
+ end
end
it "should return a 404 error if hook id is not available" do
diff --git a/spec/requests/issues_spec.rb b/spec/requests/issues_spec.rb
index 2e94ffd0020..6fff59f036f 100644
--- a/spec/requests/issues_spec.rb
+++ b/spec/requests/issues_spec.rb
@@ -58,8 +58,7 @@ describe "Issues" do
it "should be able to search on different statuses" do
issue = Issue.first # with title 'foobar'
- issue.closed = true
- issue.save
+ issue.close
visit project_issues_path(project)
click_link 'Closed'