Skip to content

Commit 54e6ff9

Browse files
committed
Adding test for #272
1 parent 1767b0d commit 54e6ff9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/EmbeddedRelationsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ public function testSaveEmptyModel()
648648
$user = User::create(array('name' => 'John Doe'));
649649
$user->addresses()->save(new Address);
650650
$this->assertNotNull($user->addresses);
651+
$this->assertEquals(1, $user->addresses()->count());
651652
}
652653

653654
}

tests/RelationsTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,23 @@ public function testNestedKeys()
417417
$this->assertEquals('Paris', $address->data['city']);
418418
}
419419

420+
public function testDoubleSave()
421+
{
422+
$author = User::create(array('name' => 'George R. R. Martin'));
423+
$book = Book::create(array('title' => 'A Game of Thrones'));
424+
425+
$author->books()->save($book);
426+
$author->books()->save($book);
427+
$author->save();
428+
$this->assertEquals(1, $author->books()->count());
429+
430+
$author = User::where('name', 'George R. R. Martin')->first();
431+
$this->assertEquals(1, $author->books()->count());
432+
433+
$author->books()->save($book);
434+
$author->books()->save($book);
435+
$author->save();
436+
$this->assertEquals(1, $author->books()->count());
437+
}
438+
420439
}

0 commit comments

Comments
 (0)