Skip to content

Commit

Permalink
Fix foreign constraint issue
Browse files Browse the repository at this point in the history
When using the RefreshDatabase trait, the foreign constraint for
best_reply_id wasn’t working properly. Can’t figure out why.

Switching to the DatabaseMigrations trait did the trick.
  • Loading branch information
JeffreyWay committed Feb 20, 2018
1 parent 7527db8 commit 1e49355
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
6 changes: 0 additions & 6 deletions app/Reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ protected static function boot()
$reply->owner->gainReputation('reply_posted');
});

static::deleting(function ($reply) {
if ($reply->isBest()) {
$reply->thread->unsetBestReply();
}
});

static::deleted(function ($reply) {
$reply->thread->decrement('replies_count');

Expand Down
11 changes: 0 additions & 11 deletions app/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,6 @@ public function markBestReply(Reply $reply)
$reply->owner->gainReputation('best_reply_awarded');
}

/**
* Unset best reply from thread.
*/
public function unsetBestReply()
{
if ($this->hasBestReply()) {
$this->bestReply->owner->loseReputation('best_reply_awarded');
$this->update(['best_reply_id' => null]);
}
}

/**
* Determine if the thread has a current best reply.
*
Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/BestReplyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class BestReplyTest extends TestCase
{
use RefreshDatabase;
use DatabaseMigrations;

/** @test */
function a_thread_creator_may_mark_any_reply_as_the_best_reply()
public function a_thread_creator_may_mark_any_reply_as_the_best_reply()
{
$this->signIn();

Expand All @@ -26,7 +26,7 @@ function a_thread_creator_may_mark_any_reply_as_the_best_reply()
}

/** @test */
function only_the_thread_creator_may_mark_a_reply_as_best()
public function only_the_thread_creator_may_mark_a_reply_as_best()
{
$this->withExceptionHandling();

Expand All @@ -44,7 +44,7 @@ function only_the_thread_creator_may_mark_a_reply_as_best()
}

/** @test */
function if_a_best_reply_is_deleted_then_the_thread_is_properly_updated_to_reflect_that()
public function if_a_best_reply_is_deleted_then_the_thread_is_properly_updated_to_reflect_that()
{
$this->signIn();

Expand Down

2 comments on commit 1e49355

@DarkaOnLine
Copy link
Contributor

@DarkaOnLine DarkaOnLine commented on 1e49355 Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem for this was on Laravel side. RefreshDatabase trait was duplicating transactions.
The fix: https://github.com/laravel/framework/pull/23132/files
More read: laravel/framework#23126

This bus should be fixed on Laravel 5.6.4

@JeffreyWay
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, good to know. That was a confusing one. :)

Please sign in to comment.