/**
  * @inheritdoc
  */
 public function defaultCriteria()
 {
     $criteria = parent::defaultCriteria();
     if ($this->translated) {
         $criteria->put(CriteriaKey::WITH, new WithRelations($this->translatedWithParameters()));
     }
     return $criteria;
 }
 /**
  * @test
  */
 function it_updates_the_active_state_of_a_record()
 {
     $this->repository->maintenance();
     $modelId = $this->repository->findBy(self::UNIQUE_FIELD, '1337')->id;
     $this->assertNotEmpty($modelId, "Test Model not found");
     // set to inactive
     $this->repository->activateRecord($modelId, false);
     $this->assertFalse($this->repository->findBy(self::UNIQUE_FIELD, '1337')->active, "Model deactivation didn't persist");
     // set to active again
     $this->repository->activateRecord($modelId);
     $this->assertTrue($this->repository->findBy(self::UNIQUE_FIELD, '1337')->active, "Model re-activation didn't persist");
 }
 /**
  * @test
  * @todo rewrite this so that it uses listify method instead
  * @todo and add other useful listify methods?
  */
 function it_updates_the_list_position_of_a_record()
 {
     $this->repository->maintenance();
     // check starting situation
     $changeModel = $this->repository->findBy(self::UNIQUE_FIELD, '1337');
     $this->assertEquals(1, $this->repository->findBy(self::UNIQUE_FIELD, '999')->position, "Starting position for record (999) is incorrect");
     $this->assertEquals(3, $changeModel->position, "Starting position for record (1337) is incorrect");
     // update the position of the last added entry
     $this->repository->updatePosition($changeModel->id, 1);
     // check final positions after update
     $this->assertEquals(2, $this->repository->findBy(self::UNIQUE_FIELD, '999')->position, "Final position for record (999) is incorrect");
     $this->assertEquals(1, $this->repository->findBy(self::UNIQUE_FIELD, '1337')->position, "Final position for moved record (1337) is incorrect");
 }
 /**
  * Applies callback to query for easier elaborate custom queries
  * on find (actually: ->first()) calls.
  *
  * @param Closure $callback must return query/builder compatible
  * @param array   $columns
  * @return Collection
  * @throws InvalidArgumentException
  */
 public function findCallback(Closure $callback, $columns = ['*'])
 {
     return $this->postProcess(parent::findCallback($callback, $columns));
 }