-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from pheeque/version-hidden-fields
Allow versioning of hidden fields in model_data.
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -488,6 +488,31 @@ public function testKeepMaxVersionCount() | |
|
||
$this->assertEquals( $name_v3, $model->name ); | ||
} | ||
|
||
public function testAllowHiddenFields() { | ||
$user = new TestHiddenFieldsUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
$user->password = "12345"; | ||
$user->save(); | ||
sleep(1); | ||
|
||
$user->name = "John"; | ||
$user->email = "[email protected]"; | ||
$user->password = "6789"; | ||
$user->save(); | ||
sleep(1); | ||
|
||
$diff = $user->previousVersion()->diff(); | ||
|
||
$this->assertArrayHasKey('email', $diff); | ||
$this->assertArrayHasKey('password', $diff); | ||
$this->assertEquals( 'John', $diff['name'] ); | ||
$this->assertEquals( '[email protected]', $diff['email'] ); | ||
$this->assertEquals( '6789', $diff['password'] ); | ||
|
||
$this->assertArrayNotHasKey('password', $user->toArray()); | ||
} | ||
|
||
} | ||
|
||
|
@@ -545,3 +570,12 @@ class ModelWithJsonField extends Model | |
protected $casts = ['json_field' => 'array']; | ||
} | ||
|
||
class TestHiddenFieldsUser extends \Illuminate\Foundation\Auth\User { | ||
use \Mpociot\Versionable\VersionableTrait; | ||
|
||
protected $table = "users"; | ||
|
||
protected $hidden = ['email', 'password']; | ||
|
||
protected $versionedHiddenFields = ['email', 'password']; | ||
} |