Skip to content

Commit

Permalink
Test +1/-1 format ratings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Vincent committed Aug 27, 2015
1 parent ee24365 commit 5345b79
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/seeders/PostSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions tests/seeders/RatingsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 24 additions & 0 deletions tests/suite/Post/PostRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 5345b79

Please sign in to comment.