Skip to content

Commit

Permalink
Updated relation name for article images
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Aug 28, 2015
1 parent 65e1bb7 commit 8048023
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/ArticleImageController.php
Expand Up @@ -7,7 +7,7 @@

class ArticleImageController extends ChildEntityController
{
protected $relationName = 'imagesPivot';
protected $relationName = 'articleImages';

public function __construct(Article $parentModel, EloquentModelTransformer $transformer)
{
Expand Down
2 changes: 1 addition & 1 deletion api/app/Models/Article.php
Expand Up @@ -185,7 +185,7 @@ public function images()
return $this->belongsToMany(Image::class, 'image_article');
}

public function imagesPivot()
public function articleImages()
{
return $this->hasMany(ArticleImage::class);
}
Expand Down
14 changes: 7 additions & 7 deletions api/tests/integration/ArticleImageTest.php
Expand Up @@ -92,14 +92,14 @@ public function testPutManyNew()
return $this->prepareEntity($entity);
}, $articleImages);

$childCount = \App\Models\Article::find($article->article_id)->imagesPivot->count();
$childCount = \App\Models\Article::find($article->article_id)->articleImages->count();

$this->putJson('/articles/'.$article->article_id.'/article-images', $images);

$object = json_decode($this->response->getContent());

$this->assertResponseStatus(201);
$this->assertEquals($childCount + 5, \App\Models\Article::find($article->article_id)->imagesPivot->count());
$this->assertEquals($childCount + 5, \App\Models\Article::find($article->article_id)->articleImages->count());
$this->assertTrue(is_array($object));
$this->assertCount(5, $object);
}
Expand All @@ -126,15 +126,15 @@ public function testPutManyNewInvalid()
unset($image['articleId']);
}

$childCount = \App\Models\Article::find($article->article_id)->imagesPivot->count();
$childCount = \App\Models\Article::find($article->article_id)->articleImages->count();

$this->putJson('/articles/'.$article->article_id.'/article-images', $images);

$object = json_decode($this->response->getContent());

$this->assertCount(5, $object->invalid);
$this->assertObjectHasAttribute('articleId', $object->invalid[0]);
$this->assertEquals($childCount, \App\Models\Article::find($article->article_id)->imagesPivot->count());
$this->assertEquals($childCount, \App\Models\Article::find($article->article_id)->articleImages->count());
}


Expand All @@ -145,16 +145,16 @@ public function testDeleteMany()
$article = factory(App\Models\Article::class)->create();
$this->addImagesToArticle($article);

$childCount = \App\Models\Article::find($article->article_id)->imagesPivot->count();
$childCount = \App\Models\Article::find($article->article_id)->articleImages->count();

$images = array_map(function ($entity) {
return $this->prepareEntity($entity);
}, $article->imagesPivot->all());
}, $article->articleImages->all());

$this->deleteJson('/articles/'.$article->article_id.'/article-images', $images);

$this->assertResponseStatus(204);
$this->assertResponseHasNoContent();
$this->assertEquals($childCount - 5, \App\Models\Article::find($article->article_id)->imagesPivot->count());
$this->assertEquals($childCount - 5, \App\Models\Article::find($article->article_id)->articleImages->count());
}
}

0 comments on commit 8048023

Please sign in to comment.