Skip to content

Commit 3f5ea91

Browse files
committed
Add test for findOrFail
1 parent 05ee597 commit 3f5ea91

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.2.35] - 21 Feb 2018
8+
### Fixed
9+
- cache key generation for `find()` and `findOrFail()`.
10+
711
## [0.2.33] - 19 Feb 2018
812
### Added
913
- unit test to make sure `Model::all()` returns a collection when only only

tests/Unit/CachedBuilderTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,4 +863,24 @@ public function testSubsequentFindsReturnDifferentModels()
863863
$this->assertEquals($author1->id, 1);
864864
$this->assertEquals($author2->id, 2);
865865
}
866+
867+
public function testFindOrFailCachesModels()
868+
{
869+
$author = (new Author)
870+
->findOrFail(1);
871+
872+
$key = sha1('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor-find_1');
873+
$tags = [
874+
'genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor',
875+
];
876+
877+
$cachedResults = $this->cache()
878+
->tags($tags)
879+
->get($key)['value'];
880+
$liveResults = (new UncachedAuthor)
881+
->findOrFail(1);
882+
883+
$this->assertEquals($cachedResults->toArray(), $author->toArray());
884+
$this->assertEquals($liveResults->toArray(), $author->toArray());
885+
}
866886
}

0 commit comments

Comments
 (0)