From a06747f0531d028e13b7fbc82bc826fd2205ce5a Mon Sep 17 00:00:00 2001 From: Dimitrios Savvopoulos Date: Fri, 20 Jun 2014 16:23:43 +0200 Subject: [PATCH] Added more tests for code coverage. --- tests/TestCoreModelExtension.php | 60 ++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/tests/TestCoreModelExtension.php b/tests/TestCoreModelExtension.php index 2da7948..35de291 100644 --- a/tests/TestCoreModelExtension.php +++ b/tests/TestCoreModelExtension.php @@ -12,6 +12,35 @@ class TestCoreModelExtension extends TestsBase { + // Saving + + /** + * @test + */ + public function it_saves_empty_instances() + { + $company = new Company; + $company->save(); + $this->assertGreaterThan(0, $company->id); + + $country = new Continent; + $country->save(); + $this->assertGreaterThan(0, $country->id); + } + + /** + * @test + */ + public function it_saves_translations_when_existing_and_dirty() + { + $country = Country::find(1); + $country->iso = 'make_model_dirty'; + $country->name = 'abc'; + $this->assertTrue($country->save()); + $country = Country::find(1); + $this->assertEquals($country->name, 'abc'); + } + // Failing saving /** @@ -40,7 +69,7 @@ public function it_throws_query_exception_if_saving_and_name_is_null() /** * @test */ - public function it_returns_false_if_parent_save_was_not_successful() + public function it_returns_false_if_exists_and_dirty_and_parent_save_returns_false() { $that = $this; $event = App::make('events'); @@ -54,6 +83,21 @@ public function it_returns_false_if_parent_save_was_not_successful() $this->assertFalse($country->save()); } + /** + * @test + */ + public function it_returns_false_if_does_not_exist_and_parent_save_returns_false() + { + $that = $this; + $event = App::make('events'); + $event->listen('eloquent*', function($model) use ($that) { + return get_class($model) == 'Dimsav\Translatable\Test\Model\Continent' ? false : true; + }); + + $continent = new Continent; + $this->assertFalse($continent->save()); + } + // Filling /** @@ -144,18 +188,4 @@ public function it_passes_the_N_plus_1_problem() $this->assertGreaterThan(2, count($countries)); $this->assertEquals(2, $this->queriesCount); } - - /** - * @test - */ - public function it_saves_empty_instances() - { - $company = new Company; - $company->save(); - $this->assertGreaterThan(0, $company->id); - - $country = new Continent; - $country->save(); - $this->assertGreaterThan(0, $country->id); - } } \ No newline at end of file