diff --git a/app/Gift.php b/app/Gift.php index 01b324795..a4f0183d1 100644 --- a/app/Gift.php +++ b/app/Gift.php @@ -109,14 +109,12 @@ class Gift extends Model /** * Set the recipient for the gift. * - * @param string $recipient - * @return static + * @param int $value + * @return string */ - public function forRecipient($recipient) + public function setIsForAttribute($value) { - $this->is_for = $recipient; - - return $this; + $this->attributes['is_for'] = $value; } /** diff --git a/app/Http/Controllers/Contacts/GiftsController.php b/app/Http/Controllers/Contacts/GiftsController.php index 68a99ff96..40bd943f7 100644 --- a/app/Http/Controllers/Contacts/GiftsController.php +++ b/app/Http/Controllers/Contacts/GiftsController.php @@ -96,7 +96,8 @@ class GiftsController extends Controller ); if ($request->get('has_recipient')) { - $gift->forRecipient($request->get('recipient'))->save(); + $gift->is_for = $request->get('recipient'); + $gift->save(); } $contact->logEvent('gift', $gift->id, 'create'); @@ -144,7 +145,8 @@ class GiftsController extends Controller ); if ($request->get('has_recipient')) { - $gift->forRecipient($request->get('recipient'))->save(); + $gift->is_for = $request->get('recipient'); + $gift->save(); } $contact->logEvent('gift', $gift->id, 'update'); diff --git a/tests/Unit/GiftTest.php b/tests/Unit/GiftTest.php index 73ac70788..590cb38a4 100644 --- a/tests/Unit/GiftTest.php +++ b/tests/Unit/GiftTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit; use App\Gift; +use App\Contact; use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -53,4 +54,94 @@ class GiftTest extends TestCase $gift->has_been_received ); } + + public function test_has_particular_recipient_returns_false_if_it_s_for_no_specific_recipient() + { + $gift = new Gift; + + $this->assertEquals( + false, + $gift->hasParticularRecipient() + ); + } + + public function test_has_particular_recipient_returns_true_if_it_s_for_a_specific_recipient() + { + $gift = new Gift; + $gift->is_for = 1; + + $this->assertEquals( + true, + $gift->hasParticularRecipient() + ); + } + + public function test_it_sets_is_for_attribute() + { + $gift = new Gift; + $gift->is_for = 1; + + $this->assertEquals( + 1, + $gift->is_for + ); + } + + public function test_it_gets_the_recipient_name() + { + $gift = new Gift; + $gift->is_for = 1; + $gift->contact_id = 1; + + $contact = factory(Contact::class)->create(['id' => 1, 'first_name' => 'Regis']); + + $this->assertEquals( + 'Regis', + $gift->recipient_name + ); + } + + public function test_it_gets_the_gift_name() + { + $gift = new Gift; + $gift->name = 'Maison de folie'; + + $this->assertEquals( + 'Maison de folie', + $gift->name + ); + } + + public function test_it_gets_the_gift_url() + { + $gift = new Gift; + $gift->url = 'https://facebook.com'; + + $this->assertEquals( + 'https://facebook.com', + $gift->url + ); + } + + public function test_it_gets_the_comment() + { + $gift = new Gift; + $gift->comment = 'This is just a comment'; + + $this->assertEquals( + 'This is just a comment', + $gift->comment + ); + } + + public function test_it_gets_the_value() + { + $gift = new Gift; + $gift->value = '100$'; + + $this->assertEquals( + '100$', + $gift->value + ); + } }