refactor and fix resource.view and add tests for it