diff --git a/tests/seeders/PostSeeder.php b/tests/seeders/PostSeeder.php index 9679bce..5dba34d 100644 --- a/tests/seeders/PostSeeder.php +++ b/tests/seeders/PostSeeder.php @@ -10,6 +10,7 @@ public function run() Post::unguard(); Post::create(['id' => 1, 'title' => 'First post', 'body' => 'This is the first post!']); Post::create(['id' => 2, 'title' => 'Second post', 'body' => 'This is the second post!']); + Post::create(['id' => 3, 'title' => 'Third post', 'body' => 'This is the third post!']); Post::reguard(); } diff --git a/tests/seeders/RatingsSeeder.php b/tests/seeders/RatingsSeeder.php index f6b4ab4..7ecd6a5 100644 --- a/tests/seeders/RatingsSeeder.php +++ b/tests/seeders/RatingsSeeder.php @@ -12,6 +12,7 @@ public function run() $post1 = Post::find(1); $post2 = Post::find(2); + $post3 = Post::find(3); $user1 = User::find(1); $user2 = User::find(2); diff --git a/tests/suite/Post/PostRelationsTest.php b/tests/suite/Post/PostRelationsTest.php index 4eae8e5..0960534 100644 --- a/tests/suite/Post/PostRelationsTest.php +++ b/tests/suite/Post/PostRelationsTest.php @@ -46,4 +46,28 @@ public function testRatingsRatingPercent() // should drop to 30% $this->assertEquals(30, $post2->ratingPercent(10)); } + + public function testPlusOneStyleRatings() + { + $post = Post::find(3); + + $this->assertEquals(0, $post->sumRating); + $this->assertEquals(0, $post->sumRating()); + + $rating = new willvincent\Rateable\Rating; + $rating->rating = 1; + $rating->user_id = 1; + $post->ratings()->save($rating); + + $this->assertEquals(1, $post->sumRating); + $this->assertEquals(1, $post->sumRating()); + + $rating = new willvincent\Rateable\Rating; + $rating->rating = -1; + $rating->user_id = 2; + $post->ratings()->save($rating); + + $this->assertEquals(0, $post->sumRating); + $this->assertEquals(0, $post->sumRating()); + } }