From d67d43d1b693a37da73c8469e9b5c6c6f53ed0fa Mon Sep 17 00:00:00 2001 From: Jarka Kadlecova Date: Tue, 4 Apr 2017 12:36:58 +0200 Subject: [PATCH] Split status and confidentiality action --- app/models/system_note_metadata.rb | 4 +-- app/services/system_note_service.rb | 14 +++++++-- spec/services/system_note_service_spec.rb | 35 +++++++++++++++-------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/app/models/system_note_metadata.rb b/app/models/system_note_metadata.rb index 5cc66574941..1e6fc837a75 100644 --- a/app/models/system_note_metadata.rb +++ b/app/models/system_note_metadata.rb @@ -1,7 +1,7 @@ class SystemNoteMetadata < ActiveRecord::Base ICON_TYPES = %w[ - commit merge confidentiality status label assignee cross_reference - title time_tracking branch milestone discussion task moved + commit merge confidential visible label assignee cross_reference + title time_tracking branch milestone discussion task moved opened closed merged ].freeze validates :note, presence: true diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index d3e502b66dd..35cfcc3682e 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -183,7 +183,9 @@ module SystemNoteService body = status.dup body << " via #{source.gfm_reference(project)}" if source - create_note(NoteSummary.new(noteable, project, author, body, action: 'status')) + action = status == 'reopened' ? 'opened' : status + + create_note(NoteSummary.new(noteable, project, author, body, action: action)) end # Called when 'merge when pipeline succeeds' is executed @@ -273,9 +275,15 @@ module SystemNoteService # # Returns the created Note object def change_issue_confidentiality(issue, project, author) - body = issue.confidential ? 'made the issue confidential' : 'made the issue visible to everyone' + if issue.confidential + body = 'made the issue confidential' + action = 'confidential' + else + body = 'made the issue visible to everyone' + action = 'visible' + end - create_note(NoteSummary.new(issue, project, author, body, action: 'confidentiality')) + create_note(NoteSummary.new(issue, project, author, body, action: action)) end # Called when a branch in Noteable is changed diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 90cde705b85..5ec1ed8237b 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -221,26 +221,23 @@ describe SystemNoteService, services: true do describe '.change_status' do subject { described_class.change_status(noteable, project, author, status, source) } - let(:status) { 'new_status' } - let(:source) { nil } + context 'with status reopened' do + let(:status) { 'reopened' } + let(:source) { nil } - it_behaves_like 'a system note' do - let(:action) { 'status' } + it_behaves_like 'a system note' do + let(:action) { 'opened' } + end end context 'with a source' do + let(:status) { 'opened' } let(:source) { double('commit', gfm_reference: 'commit 123456') } it 'sets the note text' do expect(subject.note).to eq "#{status} via commit 123456" end end - - context 'without a source' do - it 'sets the note text' do - expect(subject.note).to eq status - end - end end describe '.merge_when_pipeline_succeeds' do @@ -298,9 +295,23 @@ describe SystemNoteService, services: true do describe '.change_issue_confidentiality' do subject { described_class.change_issue_confidentiality(noteable, project, author) } - context 'when noteable responds to `confidential`' do + context 'issue has been made confidential' do + before do + noteable.update_attribute(:confidential, true) + end + it_behaves_like 'a system note' do - let(:action) { 'confidentiality' } + let(:action) { 'confidential' } + end + + it 'sets the note text' do + expect(subject.note).to eq 'made the issue confidential' + end + end + + context 'issue has been made visible' do + it_behaves_like 'a system note' do + let(:action) { 'visible' } end it 'sets the note text' do