Skip to content

Commit

Permalink
Add inviter relation to TeamInvite
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranb committed May 10, 2016
1 parent 5931381 commit 8a2b9d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ In addition to these attributes, the model has these relations:

- `user()` — one-to-one relation using the `email` as a unique identifier on the User model.
- `team()` — one-to-one relation return the Team, that invite was aiming for.
- `inviter()` — one-to-one relation return the User, that created the invite.

**Note:**
The `inviteToTeam` method will **not** check if the given email already has a pending invite. To check for pending invites use the `hasPendingInvite` method on the `Teamwork` facade.
Expand Down
10 changes: 10 additions & 0 deletions src/Mpociot/Teamwork/Traits/TeamworkTeamInviteTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ public function user()
return $this->hasOne( Config::get( 'teamwork.user_model' ), 'email', 'email' );
}

/**
* Has-One relations with the user model.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function inviter()
{
return $this->hasOne( Config::get( 'teamwork.user_model' ), 'id', 'user_id' );
}

}
15 changes: 15 additions & 0 deletions tests/TeamworkTeamInviteTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ public function testGetUser()
$this->assertEquals( [], $stub->user() );
}

public function testGetInviter()
{
Config::shouldReceive('get')
->once()
->with('teamwork.user_model')
->andReturn('User');

$stub = m::mock( 'TestUserTeamInviteTraitStub[hasOne]' );
$stub->shouldReceive('hasOne')
->once()
->with('User', 'id', 'user_id' )
->andReturn( [] );
$this->assertEquals( [], $stub->inviter() );
}

}

class TestUserTeamInviteTraitStub extends Illuminate\Database\Eloquent\Model {
Expand Down

0 comments on commit 8a2b9d6

Please sign in to comment.