-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Implement robust Couchbase error handling and modernize test infrastructure #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Improved Couchbase initialization with error handling for misconfigurations. - Added new API endpoints for hotel autocomplete and filtering in Swagger documentation. - Updated Swagger server URL to a more generic format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @teetangh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request primarily focuses on enhancing the robustness of Couchbase initialization and expanding the API documentation within Swagger. It introduces error handling for Couchbase connection issues and adds new endpoints for hotel search functionalities, while also simplifying the Swagger server URL configuration.
Highlights
- Improved Couchbase Initialization: The Couchbase connection logic is now wrapped in a begin...rescue block, allowing the Rails application to boot even if Couchbase is unreachable or misconfigured. Uninitialized constants will be set to nil in such cases.
- New Hotel API Endpoints in Swagger: Two new API endpoints, /api/v1/hotels/autocomplete (GET) and /api/v1/hotels/filter (POST), have been added to the Swagger documentation, enabling hotel search and filtering capabilities.
- Simplified Swagger Server URL: The Swagger server URL configuration has been streamlined from a dynamic http://{defaultHost} to a more generic and relative /.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
Fixes 4 valid issues identified in PR #8 code review: 1. HIGH PRIORITY - Fixed constant re-assignment in couchbase.rb - Changed DB_USERNAME, DB_PASSWORD, DB_CONN_STR to local variables - Eliminates Ruby "already initialized constant" warnings - Constants at top of file remain for CI environment - Local variables used only in dev environment 2. Fixed rswag spec grammar (line 5) - Changed "Retrieve suggestion" → "Retrieve suggestions" - Matches plural array return type 3. Fixed misleading response description (line 22) - Changed "No suggestion" → "List of hotel name suggestions" - 200 status should describe success case, not edge case 4. Fixed incorrect response descriptions (lines 73 & 93) - Changed "only one Hotels found" → "List of hotels matching the filter criteria" - Fixed grammar and made description generic for filter endpoint Note: Rejected Gemini's metaprogramming suggestion for search index assignment as it adds unnecessary complexity without benefit. Regenerated swagger.yaml from updated rswag specs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Allows developers to manually trigger the CI workflow from the GitHub Actions UI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…andling This commit addresses the failing integration tests and implements a robust error handling strategy for Couchbase connections. ## Problem Fixed - 25 out of 27 integration tests were failing with "NoMethodError: undefined method 'get' for nil" - Couchbase collection constants (AIRLINE_COLLECTION, AIRPORT_COLLECTION, ROUTE_COLLECTION) were nil due to silent initialization failures ## Changes Made ### Core Fixes - Created CouchbaseConnection concern for centralized connection checking - Updated all models (Airline, Airport, Route, Hotel) to use ensure_couchbase! - Changed ApplicationController to inherit from ActionController::API - Improved Couchbase initializer with environment-specific error handling and retry logic for transient failures - Removed skip_before_action :verify_authenticity_token from all API controllers (not needed for ActionController::API) ### Code Organization - Renamed HotelSearch model to Hotel for consistency with other models - Reorganized test files following RSpec conventions: * spec/requests/swagger/ - Swagger/rswag documentation specs * spec/requests/api/v1/ - Integration test specs * Removed test/integration/ directory ### New Features - Added health check endpoint (GET /api/v1/health) for monitoring Couchbase connectivity - Added retry logic for CI to handle transient network failures - Added comprehensive troubleshooting documentation in README.md ### CI/CD Improvements - Updated CI workflow to validate Couchbase configuration before running tests - Added connection test step to verify database availability - Updated test paths to use spec/requests instead of test/integration ## Test Results - All 27 integration tests now pass (0 failures) - Swagger documentation regenerated successfully (64 examples) - Health endpoint verified working ## Files Modified - Models: airline.rb, airport.rb, route.rb, hotel.rb (renamed from hotel_search.rb) - Controllers: airlines, airports, routes, hotels, health (new), application - Config: couchbase.rb initializer, routes.rb, ci.yml - Tests: Reorganized from test/integration/ to spec/requests/api/v1/ - Docs: README.md with troubleshooting guide 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Simplified swagger specs to focus on API documentation generation rather than duplicating integration testing. This change improves maintainability and test execution speed. Changes: - Converted all swagger specs (airlines, airports, routes, hotels) to documentation-only mode - Removed database setup/teardown logic from swagger specs - Added inline comments indicating actual testing is in spec/requests/api/v1/ - Updated CI workflow to: - Run only integration tests from spec/requests/api/v1/ - Verify swagger documentation generates without errors - Skip redundant swagger spec testing - Regenerated swagger.yaml with simplified specs Benefits: - Faster swagger documentation generation (64 examples, 0 failures) - Clear separation of concerns: swagger for docs, integration tests for testing - Reduced CI execution time - Eliminated complex test data management in swagger specs - Integration tests in spec/requests/api/v1/ provide actual API validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Summary
This PR implements comprehensive improvements to Couchbase integration, error handling, test infrastructure, and API documentation. The changes ensure the application handles database failures gracefully, provides clear operational visibility, and maintains a clean separation between testing and documentation.
Key Changes
1. Graceful Degradation & Error Handling ✅
New
CouchbaseConnectionConcern (app/models/concerns/couchbase_connection.rb)ensure_couchbase!method validates connection before operationsCouchbaseUnavailableErrorinstead of cryptic NoMethodErrorAirline,Airport,Route,HotelmodelsEnhanced
ApplicationControllerCouchbaseUnavailableErrorImproved Couchbase Initializer (
config/initializers/couchbase.rb)2. Health Check Endpoint 🏥
New Endpoint:
GET /api/v1/health{ "status": "healthy", "timestamp": "2025-12-02T10:00:00Z", "services": { "couchbase": { "status": "up", "message": "Connected to travel-sample bucket" } } }3. Test Infrastructure Modernization 📁
Reorganized Test Structure:
test/integration/→spec/requests/api/v1/spec/requests/swagger/test/integration/directorySwagger Specs Simplified:
Integration Tests:
4. Model Consistency 🏗️
Renamed
HotelSearch→Hotel5. CI/CD Improvements 🔄
Updated GitHub Actions Workflow (
.github/workflows/ci.yml)rspec spec/requests/api/v1rake rswag:specs:swaggerize6. Documentation 📚
Enhanced README.md:
Regenerated Swagger Documentation:
Testing Results
✅ All Tests Passing
Integration Tests: 27/27 passing
Swagger Generation: 64/64 passing
Test Coverage
Benefits
Operational
Development
Maintenance
CouchbaseConnectionconcernMigration Notes
No breaking changes to API contracts. All endpoints maintain same behavior.
For Developers
GET /api/v1/healthendpoint available for monitoringspec/requests/api/v1/bundle exec rspec spec/requests/api/v1bundle exec rake rswag:specs:swaggerizeFor CI/CD
DB_CONN_STR,DB_USERNAME,DB_PASSWORDRelated
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]