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:
authorAndrew8xx8 <avk@8xx8.ru>2013-02-18 13:10:58 +0400
committerAndrew8xx8 <avk@8xx8.ru>2013-02-18 14:43:50 +0400
commit1644117a1ac45bd7d250e7bced929a00a3befe5e (patch)
tree8cc9ac92f9156bc4327ac1ec49cdc6b56b3dc49e /spec
parent0b512af803d007852bcba40c75203e0e45dda177 (diff)
Issue uses StateMachine now
Diffstat (limited to 'spec')
-rw-r--r--spec/factories.rb7
-rw-r--r--spec/models/issue_spec.rb2
-rw-r--r--spec/observers/issue_observer_spec.rb159
-rw-r--r--spec/requests/api/issues_spec.rb16
-rw-r--r--spec/requests/issues_spec.rb3
5 files changed, 80 insertions, 107 deletions
diff --git a/spec/factories.rb b/spec/factories.rb
index 92d250d6d60..3f357b79496 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
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index d795a81b0a4..f72fed2292d 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
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/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/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'