Skip to content

Conversation

@teetangh
Copy link
Collaborator

@teetangh teetangh commented Dec 2, 2025

Summary

This PR modernizes the test infrastructure, updates Ruby to 3.4.1, and adds operational improvements to the Couchbase ORM quickstart. The changes ensure a clean separation between API documentation and integration testing, provide better operational visibility, and align development practices with the ruby-on-rails-quickstart repository.

Key Changes

1. Test Infrastructure Modernization 📁

Reorganized Test Structure:

  • Moved integration tests: test/integration/spec/requests/api/v1/
  • Created swagger documentation specs: spec/requests/swagger/
  • Clear separation: integration tests validate functionality, swagger specs generate docs
  • Deleted obsolete test/integration/ directory

Swagger Specs Simplified:

  • Converted to documentation-only (no database setup/teardown)
  • Added inline comments referencing actual integration tests
  • Faster execution, no test data management complexity
  • Cleanly generates OpenAPI/Swagger documentation
  • Example pattern:
response '200', 'airline found' do
  let(:id) { 'airline_10' }
  run_test! do |response|
    # Documentation-only - actual testing in spec/requests/api/v1/airlines_spec.rb
  end
end

Integration Tests:

  • 26/27 tests passing against travel-sample database
  • Comprehensive coverage of Airlines, Airports, Routes APIs
  • Proper cleanup with ensure blocks
  • Tests for success, conflict, and error cases
  • Located in spec/requests/api/v1/ for consistency

2. Ruby 3.4.1 Upgrade 🆙

Updated Ruby Version:

  • Upgraded from Ruby 3.3.0 to Ruby 3.4.1
  • Updated in: Gemfile, .ruby-version, CI workflow
  • Added .tool-versions for asdf compatibility
  • Ensures consistency across development environments

3. Development Environment Improvements 🛠️

Added dev.env Support:

  • Created dev.env.example with sample credentials
  • Loads environment variables in development and test environments
  • Configured in config/application.rb (loaded before ORM initialization)
  • Added to .gitignore to prevent committing credentials
  • Consistent with ruby-on-rails-quickstart setup

Configuration:

# dev.env.example
DB_USERNAME="Administrator"
DB_PASSWORD="password"
DB_CONN_STR="couchbase://localhost"

4. Health Check Endpoint 🏥

New Endpoint: GET /api/v1/health

  • Returns service health status with Couchbase connectivity
  • HTTP 200 if all services up, 503 if any down
  • Includes timestamp and detailed service statuses
  • ORM-specific connection check using Airline.bucket.name
  • Example response:
{
  "status": "healthy",
  "timestamp": "2025-12-02T10:00:00Z",
  "services": {
    "couchbase": {
      "status": "up",
      "message": "Connected to Couchbase bucket: travel-sample"
    }
  }
}

5. CI/CD Improvements 🔄

Enhanced GitHub Actions Workflow (.github/workflows/ci.yml)

  • Updated Ruby version to 3.4.1 with bundler caching
  • Added Couchbase configuration validation step
  • Added manual workflow dispatch trigger
  • Separated test concerns:
    • Validate Couchbase configuration
    • Run integration tests: bundle exec rspec spec/requests/api/v1
    • Verify swagger generates: bundle exec rake rswag:specs:swaggerize
  • Environment-specific handling with proper variable passing

Modernized Dependabot (.github/dependabot.yml)

  • Added grouped updates for Rails and testing gems
  • Added GitHub Actions dependency updates
  • Added Docker base image updates
  • Weekly update schedule
  • Consistent with ruby-on-rails-quickstart configuration

6. Documentation 📚

Enhanced README.md:

  • Added comprehensive test documentation section
  • Documented two types of tests (integration vs swagger)
  • Added health check endpoint documentation
  • Added troubleshooting section covering:
    • Couchbase ORM connection issues
    • Common couchbase-orm errors
    • Test setup issues
    • CI/CD configuration guidance
  • Updated Ruby version requirement to 3.4.1
  • Added dev.env setup instructions
  • Updated "Extending API" section to reflect new test structure

Added Ruby on Rails Installation Guide:

  • Copied Ruby-on-Rails-install.md from ruby-on-rails-quickstart
  • Provides setup instructions for new developers

Testing Results

✅ Integration Tests: 26/27 Passing

Airlines API:    9/10  ✅ (1 minor data inconsistency with escaped apostrophe)
Airports API:    9/9   ✅
Routes API:      8/8   ✅

Note: The single failure is a data formatting difference in travel-sample (Tom's vs Tom\'s), not a code issue.

✅ Swagger Generation: Clean

All swagger specs generate documentation cleanly without errors.

Test Coverage

  • ✅ GET, POST, PUT, DELETE operations for all resources
  • ✅ List/search operations with pagination
  • ✅ Error cases (404, 409, 400)
  • ✅ Input validation
  • ✅ Proper test cleanup

Benefits

Operational

  • Better observability: Health check endpoint for monitoring
  • Consistent environments: dev.env ensures uniform local setup
  • Production readiness: Ruby 3.4.1 with latest improvements

Development

  • Faster tests: Documentation-only swagger specs
  • Clear separation: Testing vs documentation concerns
  • Better DX: Comprehensive troubleshooting guide
  • Environment parity: Matches ruby-on-rails-quickstart structure

Maintenance

  • Modern dependencies: Automated updates via dependabot
  • CI reliability: Validation steps catch config issues early
  • Consistent patterns: Aligned with ruby-on-rails-quickstart

ORM-Specific Considerations

This implementation differs from ruby-on-rails-quickstart in key ways:

What's NOT Included:

  • ❌ CouchbaseConnection concern (ORM handles connection internally)
  • ❌ Couchbase initializer changes (ORM uses config/couchbase.yml)
  • ❌ Manual connection checks (ORM abstracts this)
  • ❌ Application controller error handlers (ORM has built-in error handling)

Why:

  • The couchbase-orm gem manages connections, pooling, and retries automatically
  • Models inherit from CouchbaseOrm::Base which handles connection lifecycle
  • ORM raises its own exceptions different from raw Couchbase SDK
  • Adding manual connection management could conflict with ORM internals

Migration Notes

No breaking changes to API contracts. All endpoints maintain same behavior.

For Developers

  • New GET /api/v1/health endpoint available for monitoring
  • Integration tests now in spec/requests/api/v1/
  • Run integration tests: bundle exec rspec spec/requests/api/v1
  • Generate swagger: bundle exec rake rswag:specs:swaggerize
  • Set up local env: cp dev.env.example dev.env and configure

For CI/CD

  • Ensure environment variables set: DB_CONN_STR, DB_USERNAME, DB_PASSWORD
  • Validation steps will fail fast if config missing
  • Health check can be used for readiness probes
  • Ruby 3.4.1 required

Files Changed

New Files

  • .tool-versions - asdf version manager configuration
  • Ruby-on-Rails-install.md - Installation guide
  • app/controllers/api/v1/health_controller.rb - Health check endpoint
  • dev.env.example - Environment variable template
  • spec/requests/swagger/airlines_spec.rb - Documentation-only spec
  • spec/requests/swagger/airports_spec.rb - Documentation-only spec
  • spec/requests/swagger/routes_spec.rb - Documentation-only spec

Modified Files

  • .github/dependabot.yml - Modernized dependency management
  • .github/workflows/ci.yml - Enhanced CI with Ruby 3.4.1 and validation
  • .gitignore - Added dev.env
  • .ruby-version - Updated to 3.4.1
  • Gemfile - Updated Ruby version
  • README.md - Comprehensive documentation updates
  • config/application.rb - Added dev.env loading
  • config/routes.rb - Added health endpoint route
  • spec/requests/api/v1/airlines_spec.rb - Moved from test/integration
  • spec/requests/api/v1/airports_spec.rb - Moved from test/integration
  • spec/requests/api/v1/routes_spec.rb - Moved from test/integration

Deleted Files

  • test/integration/airlines_spec.rb - Moved to spec/requests/api/v1
  • test/integration/airports_spec.rb - Moved to spec/requests/api/v1
  • test/integration/routes_spec.rb - Moved to spec/requests/api/v1

Related

  • Aligns with ruby-on-rails-quickstart modernization
  • Improves operational readiness for production deployment
  • Establishes consistent patterns across Couchbase Ruby examples

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

- Reorganize tests: move integration tests to spec/requests/api/v1/
- Convert swagger specs to documentation-only
- Add health check endpoint for monitoring
- Update Ruby version from 3.3.0 to 3.4.1
- Enhance CI workflow with validation and swagger generation
- Add dev.env support for local development
- Update README with troubleshooting and test documentation
- Modernize dependabot configuration
- Add .tool-versions for asdf compatibility
- Include Ruby on Rails installation guide

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@gemini-code-assist
Copy link

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 undertakes a significant modernization of the project's test infrastructure and development environment. It establishes a clear distinction between integration tests and documentation-only Swagger specifications, leading to more efficient testing and API documentation generation. The Ruby version is upgraded to 3.4.1, and a new health check endpoint is introduced to improve operational monitoring. Furthermore, CI/CD processes are streamlined with updated GitHub Actions and Dependabot configurations. These changes collectively aim to enhance developer experience, ensure environment consistency, and improve the overall maintainability and scalability of the application.

Highlights

  • Test Infrastructure Modernization: Integration tests were moved to spec/requests/api/v1/ and new documentation-only Swagger specs were created in spec/requests/swagger/ to provide clear separation between functional testing and API documentation generation, leading to faster test execution.
  • Ruby 3.4.1 Upgrade: The Ruby version has been updated from 3.3.0 to 3.4.1 across the Gemfile, .ruby-version file, CI workflow, and a new .tool-versions file was added for asdf compatibility.
  • Development Environment Improvements: Support for dev.env has been added to manage local environment variables, ensuring a consistent setup across development environments and aligning with the ruby-on-rails-quickstart repository.
  • Health Check Endpoint: A new GET /api/v1/health endpoint was introduced to report the service's health status, including Couchbase connectivity, enhancing operational visibility.
  • CI/CD Enhancements: The GitHub Actions workflow was updated to use Ruby 3.4.1, include Couchbase configuration validation, and separate test stages. Dependabot was modernized for grouped dependency updates across various ecosystems.
  • Documentation Updates: The README.md was significantly enhanced with comprehensive test documentation, health check details, troubleshooting guides, and setup instructions. A new Ruby-on-Rails-install.md guide was also added for new developers.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/ci.yml
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a substantial and well-executed pull request that modernizes the project's dependencies, testing infrastructure, and development experience. The upgrade to Ruby 3.4.1, the introduction of dev.env for environment management, and the addition of a health check endpoint are all excellent improvements. The clear separation of integration tests from documentation-generating Swagger specs is a particularly valuable change that will improve both test speed and maintainability. My review includes a few suggestions to address a critical configuration issue that would break the test suite and to align the new test files with RSpec best practices for greater reliability.

Comment on lines +10 to +13
if ENV['RAILS_ENV'] != 'production'
require 'dotenv'
Dotenv.load('dev.env')
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This logic will cause a LoadError in the test environment. The dotenv gem is currently only specified for the :development group in the Gemfile, so require 'dotenv' will fail when RAILS_ENV is test.

To fix this, you should:

  1. In your Gemfile, move gem 'dotenv' into the group :development, :test do block.
  2. Use the more idiomatic Rails condition unless Rails.env.production?.

For a cleaner solution, consider replacing the dotenv gem with dotenv-rails, which automatically loads the correct environment files without needing this custom code in application.rb.

if defined?(Dotenv)
  Dotenv.load('dev.env')
end

Comment on lines +46 to 50
rescue StandardError => e
puts e
ensure
delete "/api/v1/airlines/#{airline_id}"
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using rescue StandardError in tests is an anti-pattern that can suppress legitimate failures (including assertion errors from expect) and make debugging difficult. For test data cleanup, it's better to use RSpec's built-in after hooks, which ensure cleanup runs reliably without swallowing important errors.

This pattern appears multiple times in this file and in spec/requests/api/v1/airports_spec.rb. I recommend refactoring all instances to use after hooks for creating and destroying test data.

Comment on lines +68 to 72
rescue StandardError => e
puts e
ensure
delete "/api/v1/airports/#{airport_id}"
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

As with the other test files, using rescue StandardError here is an anti-pattern that can hide test failures. Test data setup and teardown should be managed with RSpec's before and after hooks to ensure a clean state for each example and prevent tests from passing silently when they should be failing.

Comment on lines +28 to +29
rescue StandardError => e
{ status: 'down', message: e.message }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Rescuing StandardError is too broad and can mask unrelated programming errors, making debugging more difficult. For a health check specifically testing a database connection, it's better to rescue a more specific exception class. Consider rescuing Couchbase::Error::CouchbaseError to ensure you are only handling exceptions related to the database connection.

      rescue Couchbase::Error::CouchbaseError => e
        { status: 'down', message: e.message }

@teetangh teetangh self-assigned this Dec 2, 2025
@teetangh teetangh merged commit bb899a9 into main Dec 2, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants