Refactor: use keyword arguments for optional parameters

This commit is contained in:
Hiroyuki Sato 2017-07-23 21:43:32 +09:00
parent 7ff9008f3e
commit df65334eca
3 changed files with 4 additions and 4 deletions

View file

@ -192,7 +192,7 @@ class WikiPage
#
# Returns the String SHA1 of the newly created page
# or False if the save was unsuccessful.
def update(new_content = "", format = :markdown, message = nil, last_commit_sha = nil)
def update(new_content, format: :markdown, message: nil, last_commit_sha: nil)
@attributes[:content] = new_content
@attributes[:format] = format

View file

@ -1,7 +1,7 @@
module WikiPages
class UpdateService < WikiPages::BaseService
def execute(page)
if page.update(@params[:content], @params[:format], @params[:message], @params[:last_commit_sha])
if page.update(@params[:content], format: @params[:format], message: @params[:message], last_commit_sha: @params[:last_commit_sha])
execute_hooks(page, 'update')
end

View file

@ -212,14 +212,14 @@ describe WikiPage, models: true do
context 'with same last commit sha' do
it 'returns true' do
last_commit_sha = @page.commit.sha
expect(@page.update('more content', :markdown, nil, last_commit_sha)).to be_truthy
expect(@page.update('more content', last_commit_sha: last_commit_sha)).to be_truthy
end
end
context 'with different last commit sha' do
it 'raises exception' do
last_commit_sha = 'xxx'
expect { @page.update('more content', :markdown, nil, last_commit_sha) }.to raise_error(WikiPage::PageChangedError)
expect { @page.update('more content', last_commit_sha: last_commit_sha) }.to raise_error(WikiPage::PageChangedError)
end
end
end