Skip to content

Commit

Permalink
Fixed issue #26
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed May 18, 2016
1 parent 94b5c36 commit dc40d01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Mpociot/Teamwork/Traits/UserHasTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public function attachTeam( $team )
$this->current_team_id = $team;
$this->save();
}

// Reload relation
$this->load('teams');

if( !$this->teams->contains( $team ) )
{
$this->teams()->attach( $team );
Expand Down
21 changes: 18 additions & 3 deletions tests/UserHasTeamsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function testAttachTeamSetsCurrentTeamId()
{
$team = 1;

$stub = m::mock( 'TestUserHasTeamsTraitStub[teams,save,attach]' );
$stub = m::mock( 'TestUserHasTeamsTraitStub[teams,save,attach,load]' );
$stub->teams = m::mock('stdClass');
$stub->teams->shouldReceive('contains')
->with( $team )
Expand All @@ -167,6 +167,11 @@ public function testAttachTeamSetsCurrentTeamId()
$stub->shouldReceive('teams')
->once()
->andReturnSelf();

$stub->shouldReceive('load')
->once()
->with('teams');

$stub->shouldReceive('attach')
->once()
->with($team);
Expand All @@ -181,7 +186,7 @@ public function testAttachTeamDoesNotOverrideCurrentTeamId()
{
$team = 1;

$stub = m::mock( 'TestUserHasTeamsTraitStub[teams,save,attach]' );
$stub = m::mock( 'TestUserHasTeamsTraitStub[teams,save,attach,load]' );
$stub->teams = m::mock('stdClass');
$stub->teams->shouldReceive('contains')
->with( $team )
Expand All @@ -192,6 +197,11 @@ public function testAttachTeamDoesNotOverrideCurrentTeamId()
$stub->shouldReceive('teams')
->once()
->andReturnSelf();

$stub->shouldReceive('load')
->once()
->with('teams');

$stub->shouldReceive('attach')
->once()
->with($team);
Expand All @@ -206,7 +216,7 @@ public function testAttachTeamDoesNotAttachTeamIdWhenItExists()
{
$team = 1;

$stub = m::mock( 'TestUserHasTeamsTraitStub[teams,save,attach]' );
$stub = m::mock( 'TestUserHasTeamsTraitStub[teams,save,attach,load]' );
$stub->teams = m::mock('stdClass');
$stub->teams->shouldReceive('contains')
->with( $team )
Expand All @@ -217,6 +227,11 @@ public function testAttachTeamDoesNotAttachTeamIdWhenItExists()
$stub->shouldReceive('teams')
->never()
->andReturnSelf();

$stub->shouldReceive('load')
->once()
->with('teams');

$stub->shouldReceive('attach')
->never();

Expand Down

0 comments on commit dc40d01

Please sign in to comment.