Commit df65334e authored by Hiroyuki Sato's avatar Hiroyuki Sato

Refactor: use keyword arguments for optional parameters

parent 7ff9008f
......@@ -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
......
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
......
......@@ -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
......
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