Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Permission Test Improvements
We've made significant improvements to the permissions testing framework:
Implemented Solutions
Database Cleaner
- Added database_cleaner-active_record gem
- Set up transaction strategy for fast cleaning between tests
- Properly reset data between tests to avoid state leakage
Tenant Handling
- Created TenantHelper to properly set/reset tenant between tests
- Added support for controller tests with proper tenant context
- Fixed issues with tenancy in authentication tests
Permission Testing Helpers
- Created PermissionTestHelper with methods for setting up permissions
- Added support for both local (project) and global (role) permissions
- Improved test data setup with proper reloading of associations
Job Mocking
- Created JobsHelper to mock background jobs like OpenaiResponseJob
- Prevented Redis errors in tests without requiring Redis to be running
- Stubbed all background job methods for test stability
Flash Messages
- Added FlashHelper for checking authorization errors consistently
- Replaced specific message checks with more general error checks
- Made tests more resilient to UI text changes
Model Factory Fixes
- Fixed the Chat factory to handle the actual model schema (no title field)
- Added chatpost creation to Chat factory for valid instances
- Updated test assertions to match the model structure
Remaining Issues
Some tests are still failing due to the following issues:
Authorization Logic
- The ProjectAccessService may not be properly respecting read/write permissions
- Permission checks may need debugging in the controller or model
- Consider adding extra debugging to the roles & permissions system
Controller Actions
- Some controller actions are redirecting when they should return success
- Actions like create and update may not properly handle test data
Next Steps
Debug ProjectAccessService
# Add to the AccessCheck::ProjectAccessService class def debug_permissions(action, area) Rails.logger.debug "==== PERMISSION DEBUG ====" Rails.logger.debug "User: #{user.inspect}" Rails.logger.debug "Project: #{project.inspect}" Rails.logger.debug "Action: #{action}, Area: #{area}" # Print local permissions perm = ProjectPermission.find_by(user: user, project: project) Rails.logger.debug "Local permission: #{perm.inspect}" if perm # Print role permissions role = user.role_in_organisation(project.organisation) if role read_perm = role.has_permission?('projects', "read_access_#{area}_all_projects") write_perm = role.has_permission?('projects', "write_access_#{area}_all_projects") Rails.logger.debug "Role: #{role.inspect}" Rails.logger.debug "Read permission: #{read_perm}, Write permission: #{write_perm}" end Rails.logger.debug "=====================" endConsider Simplified Testing Strategy
- Use integration tests for permission workflow verification
- Limit controller tests to basic functionality
- Add unit tests for the permission service directly
Fix Remaining Specific Issues
- Missing create functionality for test users with write permission
- Incorrect authorization checks for admin users
- Possible issues with the Chat model validation
Run with RSpec's --backtrace
bundle exec rspec spec/controllers/chats_controller_spec.rb --backtraceto get detailed error information about where tests are failing.
These solutions should make your permissions testing more reliable and maintainable.