/**
  * @test
  */
 function it_leaves_records_with_a_null_scope_out_of_any_list()
 {
     // create a record that should be kept out of lists
     $model = $this->createNewModelWithCallableScope(['scope' => 99]);
     // add it to a list/scope
     $model->scope = 2;
     $model->save();
     $model = $model->fresh();
     $this->assertEquals(2, $model->scope, "New Model should be at position 6 in scope 2");
     $this->assertEquals(6, $model->getListifyPosition(), "New Model should be at position 6 in scope 2");
     $model->delete();
     // also check the reverse: a model with a normal scope first
     $model = $this->createNewModelWithCallableScope(['scope' => 2]);
     // that is then updated with a null-scope
     $model->scope = 99;
     $model->save();
     $model = $model->fresh();
     $this->assertEquals(99, $model->scope, "New Model should not be in a list in scope 99");
     $this->assertFalse($model->isInList(), "New Model should not be in a list in scope 99");
     $model->delete();
     // it should also handle list removal by null-scope assignment correctly
     $model = $this->findStandardModel(3);
     $model->scope = 99;
     $model->save();
     $model = $model->fresh();
     $this->assertNull($model->getListifyPosition(), "New Model should have null position in scope 99");
     $this->assertEquals(1, TestModel::find(1)->getListifyPosition(), "Other record position incorrect (2)");
     $this->assertEquals(2, TestModel::find(2)->getListifyPosition(), "Other record position incorrect (2)");
     $this->assertEquals(3, TestModel::find(4)->getListifyPosition(), "Other record position incorrect (2)");
     $this->assertEquals(4, TestModel::find(5)->getListifyPosition(), "Other record position incorrect (2)");
 }
 /**
  * @test
  */
 function it_leaves_records_with_scoped_null_foreign_key_out_of_any_list()
 {
     // create a record that should be kept out of lists
     $model = $this->createNewStandardModel(['test_related_model_id' => null]);
     $this->assertFalse($model->isInList(), "Model with null foreign key should not be in list");
     // add it to a list/scope
     $model->testRelatedModel()->associate(TestRelatedModel::find(3));
     $model->save();
     $model = $model->fresh();
     $this->assertEquals(6, $model->getListifyPosition(), "New Model should be at position 6");
     $model->delete();
     // also check the reverse: a model with a normal scope first
     $model = $this->createNewStandardModel(['test_related_model_id' => 3]);
     // that is then dissociated from related models
     $model->testRelatedModel()->dissociate();
     $model->save();
     $model = $model->fresh();
     $this->assertFalse($model->isInList(), "New model with empty foreign key should not be in a list");
     $model->delete();
     // it should also handle list removal by null-scope assignment correctly
     $model = $this->findStandardModel(3);
     $model->testRelatedModel()->dissociate();
     $model->save();
     $model = $model->fresh();
     $this->assertNull($model->getListifyPosition(), "New Model should have null position");
     $this->assertEquals(1, TestModel::find(1)->getListifyPosition(), "Other record position incorrect");
     $this->assertEquals(2, TestModel::find(2)->getListifyPosition(), "Other record position incorrect");
     $this->assertEquals(3, TestModel::find(4)->getListifyPosition(), "Other record position incorrect");
     $this->assertEquals(4, TestModel::find(5)->getListifyPosition(), "Other record position incorrect");
 }
 /**
  * @param int $id
  * @return TestModel
  */
 protected function findStandardModel($id)
 {
     return TestModel::find($id);
 }