summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-29 16:08:40 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-31 18:33:14 -0300
commitdebb65b5c81094765b2aa515a20e964cd8a14b6f (patch)
treef80182d66c1f7372eedbb4c8ebb40822ea6b296e
parent44340fede26278a7f9d70e0fb063df9673cfc551 (diff)
downloadgitlab-ce-debb65b5c81094765b2aa515a20e964cd8a14b6f.tar.gz
Update service specs to avoid instance variables
-rw-r--r--spec/services/issues/close_service_spec.rb18
-rw-r--r--spec/services/issues/reopen_service_spec.rb4
-rw-r--r--spec/services/issues/update_service_spec.rb58
3 files changed, 40 insertions, 40 deletions
diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb
index 229c8eb5b5b..4df99e41987 100644
--- a/spec/services/issues/close_service_spec.rb
+++ b/spec/services/issues/close_service_spec.rb
@@ -18,12 +18,12 @@ describe Issues::CloseService, services: true do
context "valid params" do
before do
perform_enqueued_jobs do
- @issue = described_class.new(project, user).execute(issue)
+ described_class.new(project, user).execute(issue)
end
end
- it { expect(@issue).to be_valid }
- it { expect(@issue).to be_closed }
+ it { expect(issue).to be_valid }
+ it { expect(issue).to be_closed }
it 'sends email to user2 about assign of new issue' do
email = ActionMailer::Base.deliveries.last
@@ -32,7 +32,7 @@ describe Issues::CloseService, services: true do
end
it 'creates system note about issue reassign' do
- note = @issue.notes.last
+ note = issue.notes.last
expect(note.note).to include "Status changed to closed"
end
@@ -44,12 +44,12 @@ describe Issues::CloseService, services: true do
context 'current user is not authorized to close issue' do
before do
perform_enqueued_jobs do
- @issue = described_class.new(project, guest).execute(issue)
+ described_class.new(project, guest).execute(issue)
end
end
it 'does not close the issue' do
- expect(@issue).to be_open
+ expect(issue).to be_open
end
end
@@ -67,11 +67,11 @@ describe Issues::CloseService, services: true do
context 'external issue tracker' do
before do
allow(project).to receive(:default_issues_tracker?).and_return(false)
- @issue = described_class.new(project, user).execute(issue)
+ described_class.new(project, user).execute(issue)
end
- it { expect(@issue).to be_valid }
- it { expect(@issue).to be_opened }
+ it { expect(issue).to be_valid }
+ it { expect(issue).to be_opened }
it { expect(todo.reload).to be_pending }
end
end
diff --git a/spec/services/issues/reopen_service_spec.rb b/spec/services/issues/reopen_service_spec.rb
index 83c72e64c87..4549e2b395b 100644
--- a/spec/services/issues/reopen_service_spec.rb
+++ b/spec/services/issues/reopen_service_spec.rb
@@ -11,12 +11,12 @@ describe Issues::ReopenService, services: true do
project.team << [guest, :guest]
perform_enqueued_jobs do
- @issue = described_class.new(project, guest).execute(issue)
+ described_class.new(project, guest).execute(issue)
end
end
it 'does not reopen the issue' do
- expect(@issue).to be_closed
+ expect(issue).to be_closed
end
end
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index a4bd19d317b..3c3a861b3af 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -23,14 +23,13 @@ describe Issues::UpdateService, services: true do
describe 'execute' do
def find_note(starting_with)
- @issue.notes.find do |note|
+ issue.notes.find do |note|
note && note.note.start_with?(starting_with)
end
end
def update_issue(opts)
- @issue = described_class.new(project, user, opts).execute(issue)
- @issue.reload
+ described_class.new(project, user, opts).execute(issue)
end
context "valid params" do
@@ -44,18 +43,16 @@ describe Issues::UpdateService, services: true do
}
perform_enqueued_jobs do
- @issue = described_class.new(project, user, opts).execute(issue)
+ update_issue(opts)
end
-
- @issue.reload
end
- it { expect(@issue).to be_valid }
- it { expect(@issue.title).to eq('New title') }
- it { expect(@issue.assignee).to eq(user2) }
- it { expect(@issue).to be_closed }
- it { expect(@issue.labels.count).to eq(1) }
- it { expect(@issue.labels.first.title).to eq(label.name) }
+ it { expect(issue).to be_valid }
+ it { expect(issue.title).to eq('New title') }
+ it { expect(issue.assignee).to eq(user2) }
+ it { expect(issue).to be_closed }
+ it { expect(issue.labels.count).to eq(1) }
+ it { expect(issue.labels.first.title).to eq(label.name) }
it 'sends email to user2 about assign of new issue and email to user3 about issue unassignment' do
deliveries = ActionMailer::Base.deliveries
@@ -100,7 +97,7 @@ describe Issues::UpdateService, services: true do
end
it 'creates system note about confidentiality change' do
- update_issue({ confidential: true })
+ update_issue(confidential: true)
note = find_note('Made the issue confidential')
@@ -112,7 +109,7 @@ describe Issues::UpdateService, services: true do
expect(project).not_to receive(:execute_hooks)
expect(project).not_to receive(:execute_services)
- update_issue({ confidential: true })
+ update_issue(confidential: true)
end
end
@@ -121,7 +118,7 @@ describe Issues::UpdateService, services: true do
context 'when the title change' do
before do
- update_issue({ title: 'New title' })
+ update_issue(title: 'New title')
end
it 'marks pending todos as done' do
@@ -131,7 +128,7 @@ describe Issues::UpdateService, services: true do
context 'when the description change' do
before do
- update_issue({ description: 'Also please fix' })
+ update_issue(description: 'Also please fix')
end
it 'marks todos as done' do
@@ -141,7 +138,7 @@ describe Issues::UpdateService, services: true do
context 'when is reassigned' do
before do
- update_issue({ assignee: user2 })
+ update_issue(assignee: user2)
end
it 'marks previous assignee todos as done' do
@@ -165,7 +162,7 @@ describe Issues::UpdateService, services: true do
context 'when the milestone change' do
before do
- update_issue({ milestone: create(:milestone) })
+ update_issue(milestone: create(:milestone))
end
it 'marks todos as done' do
@@ -175,7 +172,7 @@ describe Issues::UpdateService, services: true do
context 'when the labels change' do
before do
- update_issue({ label_ids: [label.id] })
+ update_issue(label_ids: [label.id])
end
it 'marks todos as done' do
@@ -186,6 +183,7 @@ describe Issues::UpdateService, services: true do
context 'when the issue is relabeled' do
let!(:non_subscriber) { create(:user) }
+
let!(:subscriber) do
create(:user).tap do |u|
label.toggle_subscription(u)
@@ -232,12 +230,14 @@ describe Issues::UpdateService, services: true do
end
context 'when issue has tasks' do
- before { update_issue({ description: "- [ ] Task 1\n- [ ] Task 2" }) }
+ before do
+ update_issue(description: "- [ ] Task 1\n- [ ] Task 2")
+ end
- it { expect(@issue.tasks?).to eq(true) }
+ it { expect(issue.tasks?).to eq(true) }
context 'when tasks are marked as completed' do
- before { update_issue({ description: "- [x] Task 1\n- [X] Task 2" }) }
+ before { update_issue(description: "- [x] Task 1\n- [X] Task 2") }
it 'creates system note about task status change' do
note1 = find_note('Marked the task **Task 1** as completed')
@@ -250,8 +250,8 @@ describe Issues::UpdateService, services: true do
context 'when tasks are marked as incomplete' do
before do
- update_issue({ description: "- [x] Task 1\n- [X] Task 2" })
- update_issue({ description: "- [ ] Task 1\n- [ ] Task 2" })
+ update_issue(description: "- [x] Task 1\n- [X] Task 2")
+ update_issue(description: "- [ ] Task 1\n- [ ] Task 2")
end
it 'creates system note about task status change' do
@@ -265,8 +265,8 @@ describe Issues::UpdateService, services: true do
context 'when tasks position has been modified' do
before do
- update_issue({ description: "- [x] Task 1\n- [X] Task 2" })
- update_issue({ description: "- [x] Task 1\n- [ ] Task 3\n- [ ] Task 2" })
+ update_issue(description: "- [x] Task 1\n- [X] Task 2")
+ update_issue(description: "- [x] Task 1\n- [ ] Task 3\n- [ ] Task 2")
end
it 'does not create a system note' do
@@ -278,8 +278,8 @@ describe Issues::UpdateService, services: true do
context 'when a Task list with a completed item is totally replaced' do
before do
- update_issue({ description: "- [ ] Task 1\n- [X] Task 2" })
- update_issue({ description: "- [ ] One\n- [ ] Two\n- [ ] Three" })
+ update_issue(description: "- [ ] Task 1\n- [X] Task 2")
+ update_issue(description: "- [ ] One\n- [ ] Two\n- [ ] Three")
end
it 'does not create a system note referencing the position the old item' do
@@ -290,7 +290,7 @@ describe Issues::UpdateService, services: true do
it 'does not generate a new note at all' do
expect do
- update_issue({ description: "- [ ] One\n- [ ] Two\n- [ ] Three" })
+ update_issue(description: "- [ ] One\n- [ ] Two\n- [ ] Three")
end.not_to change { Note.count }
end
end