@@ -79,6 +79,7 @@ module Ability
7979 end
8080 end
8181
82+
8283 it 'should throw an exception when the collection doesn\'t exist' do
8384 expect { dummy_class . is_crud_authorized? ( 'browse' , user , String ) } . to raise_error ( ForestLiana ::Errors ::ExpectedError , 'The collection String doesn\'t exist' )
8485 end
@@ -163,6 +164,53 @@ module Ability
163164 expect ( dummy_class . is_crud_authorized? ( 'browse' , user , Island ) ) . to equal true
164165 end
165166
167+ it 'should re-fetch the permission once when collection_name doesn\'t exist' do
168+ Rails . cache . write (
169+ 'forest.collections' ,
170+ {
171+ "collections" => {
172+ "Fake_collection_name" => {
173+ "collection" => {
174+ "browseEnabled" => { "roles" => [ 1 ] } ,
175+ "readEnabled" => { "roles" => [ 1 ] } ,
176+ "editEnabled" => { "roles" => [ 1 ] } ,
177+ "addEnabled" => { "roles" => [ 1 ] } ,
178+ "deleteEnabled" => { "roles" => [ 1 ] } ,
179+ "exportEnabled" => { "roles" => [ 1 ] }
180+ } ,
181+ "actions" => {
182+
183+ }
184+ }
185+ }
186+ }
187+ )
188+
189+ allow_any_instance_of ( ForestLiana ::Ability ::Fetch )
190+ . to receive ( :get_permissions )
191+ . and_return (
192+ {
193+ "collections" => {
194+ "Island" => {
195+ "collection" => {
196+ "browseEnabled" => { "roles" => [ 1 ] } ,
197+ "readEnabled" => { "roles" => [ 1 ] } ,
198+ "editEnabled" => { "roles" => [ 1 ] } ,
199+ "addEnabled" => { "roles" => [ 1 ] } ,
200+ "deleteEnabled" => { "roles" => [ 1 ] } ,
201+ "exportEnabled" => { "roles" => [ 1 ] }
202+ } ,
203+ "actions" => {
204+
205+ }
206+ }
207+ }
208+ }
209+ )
210+
211+ expect ( dummy_class . is_crud_authorized? ( 'browse' , user , Island ) ) . to equal true
212+ end
213+
166214 it 'should return false when user permission is not allowed' do
167215 Rails . cache . delete ( 'forest.users' )
168216
0 commit comments