Skip to content

Commit bac5310

Browse files
committed
Add approved scope
1 parent 4167cdf commit bac5310

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/ModerationScope.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ModerationScope implements Scope
2323
'Pending',
2424
'Rejected',
2525
'Postponed',
26+
'Approved',
2627
'Approve',
2728
'Reject',
2829
'Postpone',
@@ -165,6 +166,26 @@ protected function addWithAnyStatus(Builder $builder)
165166
});
166167
}
167168

169+
/**
170+
* Add the Approved extension to the builder.
171+
*
172+
* @param \Illuminate\Database\Eloquent\Builder $builder
173+
*
174+
* @return void
175+
*/
176+
protected function addApproved(Builder $builder)
177+
{
178+
$builder->macro('approved', function (Builder $builder) {
179+
$model = $builder->getModel();
180+
181+
$this->remove($builder, $model);
182+
183+
$builder->where($model->getQualifiedStatusColumn(), '=', Status::APPROVED);
184+
185+
return $builder;
186+
});
187+
}
188+
168189
/**
169190
* Add the Pending extension to the builder.
170191
*

tests/ModerationScopeTest.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,7 @@ public function it_returns_only_pending_stories()
7171
/** @test */
7272
public function it_returns_only_postponed_stories()
7373
{
74-
$this->createPost([$this->status_column => Status::POSTPONED], 5);
75-
76-
$posts = (new Post)->newQueryWithoutScope(new ModerationScope)->postponed()->get();
7774

78-
$this->assertNotEmpty($posts);
79-
80-
foreach ($posts as $post) {
81-
$this->assertEquals(Status::POSTPONED, $post->{$this->status_column});
82-
}
8375
}
8476

8577
/** @test */
@@ -310,4 +302,18 @@ public function it_queries_pending_stories_by_default_when_not_in_strict_mode()
310302
$this->assertTrue(($post->{$this->status_column} == Status::PENDING));
311303
}
312304
}
305+
306+
/** @test */
307+
public function it_queries_approved_stories_when_not_in_strict_mode()
308+
{
309+
$this->createPost([$this->status_column => Status::APPROVED], 5);
310+
311+
$posts = (new Post)->newQueryWithoutScope(new ModerationScope)->approved()->get();
312+
313+
$this->assertNotEmpty($posts);
314+
315+
foreach ($posts as $post) {
316+
$this->assertEquals(Status::APPROVED, $post->{$this->status_column});
317+
}
318+
}
313319
}

0 commit comments

Comments
 (0)