Skip to content

Commit

Permalink
Changes as per code review, and fixes failing test cases.
Browse files Browse the repository at this point in the history
Signed-off-by: Abijeet <abijeetpatro@gmail.com>
  • Loading branch information
Abijeet committed Sep 16, 2018
1 parent 0c8b6b7 commit bb3004f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/Http/Controllers/PageController.php
Expand Up @@ -459,15 +459,15 @@ public function restoreRevision($bookSlug, $pageSlug, $revisionId)
* Deletes a revision using the id of the specified revision.
* @param string $bookSlug
* @param string $pageSlug
* @param int $revisionId
* @param int $revId
* @throws NotFoundException
* @throws BadRequestException
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroyRevision($bookSlug, $pageSlug, $revId)
{
$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
$this->checkOwnablePermission('page-update', $page);
$this->checkOwnablePermission('page-delete', $page);

$revision = $page->revisions()->where('id', '=', $revId)->first();
if ($revision === null) {
Expand All @@ -480,7 +480,7 @@ public function destroyRevision($bookSlug, $pageSlug, $revId)
// Check if its the latest revision, cannot delete latest revision.
if (intval($currentRevision->id) === intval($revId)) {
session()->flash('error', trans('entities.revision_cannot_delete_latest'));
return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]);
return response()->view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page], 400);
}

$revision->delete();
Expand Down
5 changes: 1 addition & 4 deletions app/Page.php
Expand Up @@ -119,9 +119,6 @@ public function entityRawQuery($withContent = false)
*/
public function getCurrentRevision()
{
if ($id = PageRevision::where('page_id', '=', $this->id)->max('id')) {
return PageRevision::find($id);
}
return null;
return $this->revisions()->first();
}
}
10 changes: 8 additions & 2 deletions tests/Entity/PageRevisionTest.php
Expand Up @@ -21,17 +21,22 @@ public function test_revision_count_shown_in_page_meta()
{
$page = Page::first();
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);

$page = Page::find($page->id);
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);

$page = Page::find($page->id);
$pageView = $this->get($page->getUrl());
$pageView->assertSee('Revision #' . $page->revision_count);
}

public function test_revision_deletion() {
$page = Page::first();
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);

$page = Page::find($page->id);
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);

$page = Page::find($page->id);
$beforeRevisionCount = $page->revisions->count();

Expand All @@ -48,7 +53,8 @@ public function test_revision_deletion() {
// Try to delete the latest revision
$beforeRevisionCount = $page->revisions->count();
$currentRevision = $page->getCurrentRevision();
$this->asEditor()->delete($currentRevision->getUrl('/delete/'));
$resp = $this->asEditor()->delete($currentRevision->getUrl('/delete/'));
$resp->assertStatus(400);

$page = Page::find($page->id);
$afterRevisionCount = $page->revisions->count();
Expand Down

0 comments on commit bb3004f

Please sign in to comment.