Skip to content

Commit

Permalink
Add raw_url attribute to serialization (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixlive committed May 17, 2019
1 parent d3452a1 commit 6276c59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Models/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Monitor extends Model

protected $guarded = [];

protected $appends = ['raw_url'];

protected $dates = [
'uptime_last_check_date',
'uptime_status_last_change_date',
Expand Down Expand Up @@ -62,6 +64,14 @@ public function getUrlAttribute()
return Url::fromString($this->attributes['url']);
}

/**
* @return string
*/
public function getRawUrlAttribute()
{
return (string) $this->url;
}

public static function boot()
{
parent::boot();
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/Models/MonitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@ public function it_can_disable_and_enable_itself_for_an_http_url()
//it will not enable the certificate check for a non-https site.
$this->assertFalse($this->monitor->certificate_check_enabled);
}

/** @test */
public function raw_url_is_appended_during_serialization()
{
$this->assertEquals(
'http://mysite.com',
$this->monitor->toArray()['raw_url']
);
}
}

0 comments on commit 6276c59

Please sign in to comment.