Comprehensive test suite covering all VPN configuration enhancements including network address auto-calculation, FQDN support, DNS configuration, and dynamic filename generation.
File: spec/models/vpn_configuration_spec.rb
- Attribute Validation: Ensures
wg_fqdn,dns_servers,wg_ip_range, andserver_vpn_ip_addresscan be saved and retrieved - Configuration Creation: Tests
VpnConfiguration.get_vpn_configurationmethod for creating and retrieving configurations - FQDN Functionality: Tests saving, updating, and handling nil/empty FQDN values
- Network Configuration: Tests network range and server IP address persistence
- DNS Configuration: Tests custom DNS servers, multiple formats, and nil handling
- Complete Scenarios: Tests both FQDN-based and IP-only setups
- Associations: Tests relationship with
network_addressesand dependent destruction
# FQDN handling
it 'saves wg_fqdn correctly'
it 'can update wg_fqdn'
it 'allows nil wg_fqdn'
# Network configuration
it 'saves network range correctly'
it 'saves server VPN IP correctly'
# DNS configuration
it 'allows custom DNS servers'
it 'allows multiple DNS formats'File: spec/lib/wireguard_config_generator_spec.rb
- Server Config Generation: Tests default values and key generation
- Client Config Generation: Tests with and without FQDN
- Endpoint Priority: Tests FQDN priority over IP address
- DNS Fallback Logic: Tests custom DNS vs. default fallback
- Network Address Integration: Tests inclusion of additional network routes
- Keep Alive Configuration: Tests optional persistent keep alive settings
- Complete Scenarios: Tests professional FQDN setup vs. basic IP setup
# Endpoint selection
it 'uses FQDN as endpoint'
it 'uses IP address as endpoint'
it 'prioritizes FQDN over IP address'
# DNS handling
it 'uses custom DNS servers'
it 'falls back to default DNS servers'
it 'uses default DNS servers for empty string'
# Complete configurations
it 'generates complete professional configuration'
it 'generates basic IP-based configuration'File: spec/controllers/vpn_devices_controller_spec.rb
- Dynamic Filename Generation: Tests FQDN-based, IP-based, and fallback filenames
- Content Generation: Tests correct configuration content in downloads
- Priority Logic: Tests filename priority (FQDN > IP > default)
- Special Character Handling: Tests dot-to-underscore conversion for IP addresses
- Error Handling: Tests non-existent device handling
- Various Formats: Tests different IP and FQDN formats
# Filename generation
it 'downloads config with FQDN filename'
it 'downloads config with IP-based filename'
it 'falls back to default filename'
# Priority testing
it 'prioritizes FQDN over IP for filename'
# Format handling
it 'replaces dots with underscores in filename'
it 'handles complex FQDN correctly'File: spec/system/network_address_calculation_spec.rb
- IP Calculation Logic: Tests expected behavior for automatic server IP calculation
- Network Address Correction: Tests expected auto-correction logic for invalid network addresses
- CIDR Handling: Tests various subnet sizes (/16, /24, /30, etc.)
- Default Behavior: Tests /24 default when no CIDR specified
- Edge Cases: Tests /31, /32 networks and expected handling
- Logic Validation: Tests the underlying calculation expectations
# Calculation logic
it 'provides correct calculation logic for /24 network'
it 'handles network address correction logic'
it 'defaults to /24 when no CIDR specified'
# Edge cases
it 'handles /31 networks'
it 'handles /32 networks'
it 'validates network correction expectations'# Input: '10.42.5.0/24' → Server IP: '10.42.5.254'
# Input: '10.89.90.9' → Auto-corrected to: '10.89.90.0', Server IP: '10.89.90.254'
# Input: '192.168.1.0/16' → Server IP: '192.168.255.254'# FQDN present: Uses 'vpn.example.com:51820'
# IP only: Uses '203.0.113.10:51820'
# Both present: Prioritizes FQDN# Custom DNS: Uses configured servers
# No DNS: Falls back to '8.8.8.8, 8.8.4.4'
# Empty DNS: Falls back to defaults# FQDN: 'vpn.example.com.conf'
# IP: '192_168_1_100.conf' (dots → underscores)
# None: 'gate_vpn_config.conf' (fallback)# Model tests
bundle exec rspec spec/models/vpn_configuration_spec.rb
# Library tests
bundle exec rspec spec/lib/wireguard_config_generator_spec.rb
# Controller tests
bundle exec rspec spec/controllers/vpn_devices_controller_spec.rb
# Feature tests (logic validation)
bundle exec rspec spec/system/network_address_calculation_spec.rb# Run all VPN-related tests
bundle exec rspec spec/models/vpn_configuration_spec.rb spec/lib/wireguard_config_generator_spec.rb spec/controllers/vpn_devices_controller_spec.rb spec/system/network_address_calculation_spec.rb
# Run with verbose output
bundle exec rspec spec/models/vpn_configuration_spec.rb -vrspec-rails- Rails testing framework
# Ensure test database is set up
RAILS_ENV=test bundle exec rails db:create
RAILS_ENV=test bundle exec rails db:migrate- Database migration must be run to add
wg_fqdncolumn - VPN configuration must exist for some tests
- User authentication mocking for controller tests
- ✅ Attribute saving and retrieval
- ✅ FQDN handling (nil, empty, valid values)
- ✅ Network configuration persistence
- ✅ DNS configuration flexibility
- ✅ Association behavior
- ✅ Correct endpoint selection logic
- ✅ DNS fallback behavior
- ✅ Configuration completeness
- ✅ Network address inclusion
- ✅ Dynamic filename generation
- ✅ Priority logic (FQDN > IP > default)
- ✅ Content correctness
- ✅ Special character handling
- ✅ Network calculation logic validation
- ✅ CIDR handling expectations
- ✅ Edge case logic verification
- ✅ Expected behavior validation
- Database Connection: Ensure test database is created and migrated
- Authentication: Controller tests mock authentication - ensure mocking is correct
- Missing Gems: Install required testing gems
- Run individual test files to isolate issues
- Check test database schema includes
wg_fqdncolumn - Verify authentication helper methods are available
The test suite provides comprehensive coverage of:
- ✅ Model Layer: VPN configuration persistence and validation
- ✅ Business Logic: WireGuard configuration generation
- ✅ Controller Layer: Download functionality and filename generation
- ✅ Logic Validation: Network calculation and auto-correction expectations
- ✅ Integration: Expected behavior and edge case handling
This ensures all features work correctly individually and together as a complete system.