Skip to content

Commit

Permalink
Add approved scope
Browse files Browse the repository at this point in the history
  • Loading branch information
hootlex committed Feb 12, 2017
1 parent 4167cdf commit bac5310
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
21 changes: 21 additions & 0 deletions src/ModerationScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ModerationScope implements Scope
'Pending',
'Rejected',
'Postponed',
'Approved',
'Approve',
'Reject',
'Postpone',
Expand Down Expand Up @@ -165,6 +166,26 @@ protected function addWithAnyStatus(Builder $builder)
});
}

/**
* Add the Approved extension to the builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
*
* @return void
*/
protected function addApproved(Builder $builder)
{
$builder->macro('approved', function (Builder $builder) {
$model = $builder->getModel();

$this->remove($builder, $model);

$builder->where($model->getQualifiedStatusColumn(), '=', Status::APPROVED);

return $builder;
});
}

/**
* Add the Pending extension to the builder.
*
Expand Down
22 changes: 14 additions & 8 deletions tests/ModerationScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ public function it_returns_only_pending_stories()
/** @test */
public function it_returns_only_postponed_stories()
{
$this->createPost([$this->status_column => Status::POSTPONED], 5);

$posts = (new Post)->newQueryWithoutScope(new ModerationScope)->postponed()->get();

$this->assertNotEmpty($posts);

foreach ($posts as $post) {
$this->assertEquals(Status::POSTPONED, $post->{$this->status_column});
}
}

/** @test */
Expand Down Expand Up @@ -310,4 +302,18 @@ public function it_queries_pending_stories_by_default_when_not_in_strict_mode()
$this->assertTrue(($post->{$this->status_column} == Status::PENDING));
}
}

/** @test */
public function it_queries_approved_stories_when_not_in_strict_mode()
{
$this->createPost([$this->status_column => Status::APPROVED], 5);

$posts = (new Post)->newQueryWithoutScope(new ModerationScope)->approved()->get();

$this->assertNotEmpty($posts);

foreach ($posts as $post) {
$this->assertEquals(Status::APPROVED, $post->{$this->status_column});
}
}
}

0 comments on commit bac5310

Please sign in to comment.