Commit 7d0a27a2 authored by Patrick Derichs's avatar Patrick Derichs

Use named arguments for SystemNotes::BaseService constructor

parent be0877c6
......@@ -18,7 +18,7 @@ module SystemNoteService
#
# Returns the created Note object
def add_commits(noteable, project, author, new_commits, existing_commits = [], oldrev = nil)
::SystemNotes::CommitService.new(noteable, project, author).add_commits(new_commits, existing_commits, oldrev)
::SystemNotes::CommitService.new(noteable: noteable, project: project, author: author).add_commits(new_commits, existing_commits, oldrev)
end
# Called when a commit was tagged
......@@ -30,7 +30,7 @@ module SystemNoteService
#
# Returns the created Note object
def tag_commit(noteable, project, author, tag_name)
::SystemNotes::CommitService.new(noteable, project, author).tag_commit(tag_name)
::SystemNotes::CommitService.new(noteable: noteable, project: project, author: author).tag_commit(tag_name)
end
# Called when the assignee of a Noteable is changed or removed
......
......@@ -4,7 +4,7 @@ module SystemNotes
class BaseService
attr_reader :noteable, :project, :author
def initialize(noteable, project, author)
def initialize(noteable: nil, author: nil, project: nil)
@noteable = noteable
@project = project
@author = author
......
......@@ -7,23 +7,38 @@ describe SystemNotes::BaseService do
let(:project) { double }
let(:author) { double }
let(:base_service) { described_class.new(noteable, project, author) }
let(:base_service) { described_class.new(noteable: noteable, project: project, author: author) }
describe '#noteable' do
subject { base_service.noteable }
it { is_expected.to eq(noteable) }
it 'returns nil if no arguments are given' do
instance = described_class.new
expect(instance.noteable).to be_nil
end
end
describe '#project' do
subject { base_service.project }
it { is_expected.to eq(project) }
it 'returns nil if no arguments are given' do
instance = described_class.new
expect(instance.project).to be_nil
end
end
describe '#author' do
subject { base_service.author }
it { is_expected.to eq(author) }
it 'returns nil if no arguments are given' do
instance = described_class.new
expect(instance.author).to be_nil
end
end
end
......@@ -7,7 +7,7 @@ describe SystemNotes::CommitService do
set(:project) { create(:project, :repository, group: group) }
set(:author) { create(:user) }
let(:commit_service) { described_class.new(noteable, project, author) }
let(:commit_service) { described_class.new(noteable: noteable, project: project, author: author) }
describe '#add_commits' do
subject { commit_service.add_commits(new_commits, old_commits, oldrev) }
......@@ -111,7 +111,7 @@ describe SystemNotes::CommitService do
commit = double(title: '<pre>This is a test</pre>', short_id: '12345678')
escaped = '&lt;pre&gt;This is a test&lt;/pre&gt;'
expect(described_class.new(nil, nil, nil).new_commit_summary([commit])).to all(match(/- #{escaped}/))
expect(described_class.new.new_commit_summary([commit])).to all(match(/- #{escaped}/))
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment