Skip to content

Commit

Permalink
Merge pull request #69 from spira/hotfix/elastic-search-update
Browse files Browse the repository at this point in the history
Replacing updateIndex with addToIndex.
  • Loading branch information
Jeremy Sik authored Aug 31, 2016
2 parents 876fa8a + 0d91e3a commit 4059e75
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Model/Model/ElasticSearchIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function reindexOne($model, array $relations = null)
$this->reindexMany($this->getRelationItems($model, $relation), []);
}

return $model->updateIndex();
return $model->addToIndex();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Model/Model/IndexedModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function (IndexedModel $model) {

static::updated(
function (IndexedModel $model) {
$model->updateIndex();
$model->addToIndex();

return true;
}, PHP_INT_MAX
Expand Down
14 changes: 7 additions & 7 deletions tests/ElasticSearchIndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ public function testReindexOneWithAllRelations()

/** @var IndexedModel $related */
$related = \Mockery::mock(IndexedModel::class)->makePartial();
$related->shouldReceive('updateIndex')->twice();
$related->shouldReceive('addToIndex')->twice();

$relation = \Mockery::mock(Relation::class)->makePartial();
$relation->shouldReceive('getResults')->once()->andReturn([$related]); // Relation returns collection
$relation->shouldReceive('getResults')->once()->andReturn($related); // Relation returns one item

$entity = $this->makeEntityMock();

$entity->shouldReceive('updateIndex')->once()->andReturn([]);
$entity->shouldReceive('addToIndex')->once()->andReturn([]);
$entity->shouldReceive('secondTestEntities')->once()->andReturn($relation);
$entity->shouldReceive('testMany')->once()->andReturn($relation);

$this->assertIsArray($esi->reindexOne($entity)); // Assert method returns result of $entity->updateIndex()
$this->assertIsArray($esi->reindexOne($entity)); // Assert method returns result of $entity->addToIndex()
}

public function testReindexOneWithSpecifiedRelations()
Expand All @@ -56,7 +56,7 @@ public function testReindexOneWithSpecifiedRelations()
$relation = \Mockery::mock(Relation::class)->makePartial();
$relation->shouldReceive('getResults')->once()->andReturn([]);

$entity->shouldReceive('updateIndex')->once();
$entity->shouldReceive('addToIndex')->once();
$entity->shouldReceive('secondTestEntities')->once()->andReturn($relation);

$esi->reindexOne($entity, ['secondTestEntities', 'nonexistantRelation']);
Expand All @@ -67,7 +67,7 @@ public function testReindexOneWithDisabledRelations()
$esi = $this->makeIndexer();

$entity = $this->makeEntityMock();
$entity->shouldReceive('updateIndex')->once();
$entity->shouldReceive('addToIndex')->once();

$esi->reindexOne($entity, []);
}
Expand All @@ -84,7 +84,7 @@ public function testReindexOneNotInConfig()
$esi = new ElasticSearchIndexer([]);

$entity = $this->makeEntityMock();
$entity->shouldReceive('updateIndex')->once();
$entity->shouldReceive('addToIndex')->once();

$esi->reindexOne($entity);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public function testDeleteOne()
$esi = $this->makeIndexer();

$related = $this->makeEntityMock();
$related->shouldReceive('updateIndex')->once();
$related->shouldReceive('addToIndex')->once();

$relation = \Mockery::mock(Relation::class);
$relation->shouldReceive('getResults')->once()->andReturn([$related]);
Expand Down

0 comments on commit 4059e75

Please sign in to comment.