Skip to content

Commit

Permalink
Fix bug with broken threads relation
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev authored and cmgmyr committed Feb 25, 2016
1 parent f4800d5 commit ff1d226
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Cmgmyr/Messenger/Traits/Messagable.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function threads()
{
return $this->belongsToMany(
Models::classname(Thread::class),
Models::classname(Participant::class),
Models::table('participants'),
'user_id',
'thread_id'
);
Expand Down
18 changes: 18 additions & 0 deletions tests/MessagableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ public function it_should_get_all_threads_with_new_messages()

$this->assertEquals(1, $user->newMessagesCount());
}

/** @test */
public function it_should_get_participant_threads()
{
$user = User::create(
[
'name' => 'Jane Doe',
'email' => '[email protected]',
]
);
$thread = $this->faktory->create('thread');
$user_1 = $this->faktory->build('participant', ['user_id' => $user->id]);
$user_2 = $this->faktory->build('participant', ['user_id' => 2]);
$thread->participants()->saveMany([$user_1, $user_2]);

$threadsCount = $user->threads->count();
$this->assertEquals(1, $threadsCount);
}
}

class User extends Eloquent
Expand Down

0 comments on commit ff1d226

Please sign in to comment.