Skip to content

Commit

Permalink
Adds a spec to cover the 'embed' option on entity array export.
Browse files Browse the repository at this point in the history
  • Loading branch information
jails committed Jan 15, 2016
1 parent 69fda08 commit cd4230d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/Suite/EntitySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Chaos\Spec\Fixture\Model\Gallery;
use Chaos\Spec\Fixture\Model\Image;
use Chaos\Spec\Fixture\Model\Tag;

describe("Entity", function() {

Expand Down Expand Up @@ -887,6 +888,39 @@

});

it("supports the `'embed'` option", function() {

$image = Image::create([
'title' => 'Amiga 1200'
]);
$image->tags[] = ['name' => 'Computer'];
$image->tags[] = ['name' => 'Science'];

$image->gallery = ['name' => 'Gallery 1'];

expect($image->to('array', ['embed' => true]))->toBe([
'title' => 'Amiga 1200',
'tags' => [
['name' => 'Computer'],
['name' => 'Science']
],
'images_tags' => [
['tag' => ['name' => 'Computer']],
['tag' => ['name' => 'Science']]
],
'gallery' => ['name' => 'Gallery 1']
]);

expect($image->to('array', ['embed' => ['gallery']]))->toBe([
'title' => 'Amiga 1200',
'gallery' => ['name' => 'Gallery 1']
]);

expect($image->to('array', ['embed' => false]))->toBe([
'title' => 'Amiga 1200'
]);
});

});

describe("->__toString()", function() {
Expand Down

0 comments on commit cd4230d

Please sign in to comment.