I've set up Account sharing rules so that if a checkbox field is false, Accounts are Read/Write for All Internal Users. I have a Profile (thisProfile) where all CRUD operations are ticked, but not view/modify all.
This seems to be working within the UI for this particular profile because they can view all relevant Accounts/Contacts, however I also have a class that has 'with sharing' set but access to relevant records is not working. In a simple case, my test class creates 2 Accounts, then using runas(thisProfile) a basic [SELECT Id FROM Account] query returns no results.
If I turn on view all, it then works but this opens up access to a number of records that should not be shared.
Any ideas on how to troubleshoot this, or what could be causing it?