@@ -156,6 +156,83 @@ public function testGlobalScopesWhenSwitchingContextUsingGetMethod()
156156 $ this ->assertEquals ("B " , $ authorsB ->first ());
157157 }
158158
159+ public function testGlobalScopesAreNotCachedWhenUsingWithoutGlobalScopes ()
160+ {
161+ $ user = factory (User::class)->create (["name " => "Abernathy Kings " ]);
162+ $ this ->actingAs ($ user );
163+ $ author = factory (UncachedAuthor::class, 1 )
164+ ->create (['name ' => 'Alois ' ])
165+ ->first ();
166+ $ authors = (new AuthorBeginsWithScoped )
167+ ->withoutGlobalScopes ()
168+ ->get ();
169+ $ key = sha1 ("genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthorbeginswithscoped " );
170+ $ tags = ["genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthorbeginswithscoped " ];
171+
172+ $ cachedResults = $ this ->cache ()
173+ ->tags ($ tags )
174+ ->get ($ key )['value ' ];
175+ $ liveResults = (new UncachedAuthor )
176+ ->nameStartsWith ("A " )
177+ ->get ();
178+
179+ $ this ->assertTrue ($ authors ->contains ($ author ));
180+ $ this ->assertTrue ($ cachedResults ->contains ($ author ));
181+ $ this ->assertTrue ($ liveResults ->contains ($ author ));
182+ }
183+
184+ public function testWithoutGlobalScopes ()
185+ {
186+ factory (Author::class, 200 )->create ();
187+ $ user = factory (User::class)->create (["name " => "Andrew Junior " ]);
188+ $ this ->actingAs ($ user );
189+ $ authorsA = (new AuthorBeginsWithScoped )
190+ ->withoutGlobalScopes ()
191+ ->get ()
192+ ->map (function ($ author ) {
193+ return (new Str )->substr ($ author ->name , 0 , 1 );
194+ })
195+ ->unique ();
196+ $ user = factory (User::class)->create (["name " => "Barry Barry Barry " ]);
197+ $ this ->actingAs ($ user );
198+ $ authorsB = (new AuthorBeginsWithScoped )
199+ ->withoutGlobalScopes (['GeneaLabs\LaravelModelCaching\Tests\Fixtures\Scopes\NameBeginsWith ' ])
200+ ->get ()
201+ ->map (function ($ author ) {
202+ return (new Str )->substr ($ author ->name , 0 , 1 );
203+ })
204+ ->unique ();
205+
206+ $ this ->assertGreaterThan (1 , count ($ authorsA ));
207+ $ this ->assertGreaterThan (1 , count ($ authorsB ));
208+ }
209+
210+ public function testWithoutGlobalScope ()
211+ {
212+ factory (Author::class, 200 )->create ();
213+ $ user = factory (User::class)->create (["name " => "Andrew Junior " ]);
214+ $ this ->actingAs ($ user );
215+ $ authorsA = (new AuthorBeginsWithScoped )
216+ ->withoutGlobalScope ('GeneaLabs\LaravelModelCaching\Tests\Fixtures\Scopes\NameBeginsWith ' )
217+ ->get ()
218+ ->map (function ($ author ) {
219+ return (new Str )->substr ($ author ->name , 0 , 1 );
220+ })
221+ ->unique ();
222+ $ user = factory (User::class)->create (["name " => "Barry Barry Barry " ]);
223+ $ this ->actingAs ($ user );
224+ $ authorsB = (new AuthorBeginsWithScoped )
225+ ->withoutGlobalScope ('GeneaLabs\LaravelModelCaching\Tests\Fixtures\Scopes\NameBeginsWith ' )
226+ ->get ()
227+ ->map (function ($ author ) {
228+ return (new Str )->substr ($ author ->name , 0 , 1 );
229+ })
230+ ->unique ();
231+
232+ $ this ->assertGreaterThan (1 , count ($ authorsA ));
233+ $ this ->assertGreaterThan (1 , count ($ authorsB ));
234+ }
235+
159236 public function testLocalScopesInRelationship ()
160237 {
161238 $ first = "A " ;
0 commit comments