Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
35259a4f
Commit
35259a4f
authored
Jul 27, 2017
by
Hiroyuki Sato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encapsulate the commit.sha logic
parent
5c51db0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
6 deletions
+32
-6
app/models/wiki_page.rb
app/models/wiki_page.rb
+5
-1
app/views/projects/wikis/_form.html.haml
app/views/projects/wikis/_form.html.haml
+1
-1
spec/models/wiki_page_spec.rb
spec/models/wiki_page_spec.rb
+26
-4
No files found.
app/models/wiki_page.rb
View file @
35259a4f
...
...
@@ -138,6 +138,10 @@ class WikiPage
versions
.
first
end
def
last_commit_sha
commit
&
.
sha
end
# Returns the Date that this latest version was
# created on.
def
created_at
...
...
@@ -196,7 +200,7 @@ class WikiPage
@attributes
[
:content
]
=
new_content
@attributes
[
:format
]
=
format
if
last_commit_sha
&&
last_commit_sha
!=
commit
.
sha
if
last_commit_sha
&&
last_commit_sha
!=
self
.
last_commit_
sha
raise
PageChangedError
.
new
(
"You are attempting to update a page that has changed since you started editing it."
)
end
...
...
app/views/projects/wikis/_form.html.haml
View file @
35259a4f
...
...
@@ -5,7 +5,7 @@
=
f
.
hidden_field
:title
,
value:
@page
.
title
-
if
@page
.
persisted?
=
f
.
hidden_field
:last_commit_sha
,
value:
@page
.
commit
.
sha
=
f
.
hidden_field
:last_commit_sha
,
value:
@page
.
last_commit_
sha
.form-group
.col-sm-12
=
f
.
label
:format
,
class:
'control-label-full-width'
.col-sm-12
...
...
spec/models/wiki_page_spec.rb
View file @
35259a4f
...
...
@@ -211,15 +211,13 @@ 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'
,
last_commit_sha:
last_commit_sha
)).
to
be_truthy
expect
(
@page
.
update
(
'more content'
,
last_commit_sha:
@page
.
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'
,
last_commit_sha:
last_commit_sha
)
}.
to
raise_error
(
WikiPage
::
PageChangedError
)
expect
{
@page
.
update
(
'more content'
,
last_commit_sha:
'xxx'
)
}.
to
raise_error
(
WikiPage
::
PageChangedError
)
end
end
end
...
...
@@ -345,6 +343,30 @@ describe WikiPage, models: true do
end
end
describe
'#last_commit_sha'
do
before
do
create_page
(
"Update"
,
"content"
)
@page
=
wiki
.
find_page
(
"Update"
)
end
after
do
destroy_page
(
"Update"
)
end
it
'returns commit sha'
do
expect
(
@page
.
last_commit_sha
).
to
eq
@page
.
commit
.
sha
end
it
'is changed after page updated'
do
last_commit_sha_before_update
=
@page
.
last_commit_sha
@page
.
update
(
"new content"
)
@page
=
wiki
.
find_page
(
"Update"
)
expect
(
@page
.
last_commit_sha
).
not_to
eq
last_commit_sha_before_update
end
end
private
def
remove_temp_repo
(
path
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment