Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,26 @@ jobs:
bundler-cache: true
- name: Run RuboCop
run: bundle exec rubocop

generator-test:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v6

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
bundler-cache: true

- name: Install Rails
run: gem install rails

- name: Install Playwright
run: npx playwright install --with-deps chromium

- name: Run generator test
env:
HEADLESS: 'true'
run: bin/test_generator
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
Gemfile.lock
.playwright-mcp/
log/

# Local development files
plans/
todos/
15 changes: 15 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Exclude:
- 'lib/rails_simple_auth/models/concerns/**/*'
- 'lib/rails_simple_auth/controllers/concerns/**/*'

Metrics/PerceivedComplexity:
Exclude:
Expand All @@ -82,3 +83,17 @@ Rails/ReflectionClassName:

Style/SafeNavigationChainLength:
Enabled: false

# Generator test files use Capybara naming convention
Naming/PredicatePrefix:
Exclude:
- 'test/generator_test_files/**/*'

# Generator test files are templates, not part of gem test suite
Minitest/MultipleAssertions:
Max: 5

# Allow generated test files to have longer files
Metrics/ModuleLength:
Exclude:
- 'test/generator_test_files/**/*'
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **Generator E2E test infrastructure** - CI pipeline now validates that generators produce working views
- `bin/test_generator` script creates fresh Rails app, runs generators, and executes E2E tests
- Reusable Page Object test templates in `test/generator_test_files/`
- GitHub Actions `generator-test` job runs after unit tests pass

### Fixed

- **Session model autoloading** - Moved `RailsSimpleAuth::Session` from `lib/` to `app/models/` for proper Rails engine autoloading

## [1.0.14] - 2026-01-20

### Fixed
Expand Down
30 changes: 26 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,32 @@ Thank you for your interest in contributing!
2. Fork the repository
3. Create a feature branch (`git checkout -b feature/my-feature`)
4. Write tests for your changes
5. Ensure all tests pass (`bundle exec rake test`)
6. Run linter (`bundle exec rubocop`)
7. Update CHANGELOG.md under `[Unreleased]`
8. Submit a pull request
5. **Run local CI before submitting:**
```bash
bin/ci
```
This runs RuboCop and all unit tests.
6. Update CHANGELOG.md under `[Unreleased]`
7. Submit a pull request

### Local Development

```bash
# Install dependencies
bundle install

# Run local CI (linter + tests)
bin/ci

# Run only tests
bundle exec rake test

# Run only linter
bundle exec rubocop

# Run generator E2E tests (optional, requires Rails + Playwright)
bin/test_generator
```

### Code Style

Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
# Exclude generator_test_files - those are template tests for generated apps
t.test_files = FileList['test/**/*_test.rb'].exclude('test/generator_test_files/**/*')
end

task default: :test
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ module RailsSimpleAuth
class Session < ::ApplicationRecord
self.table_name = 'sessions'

# Use lambda to defer class resolution until runtime
belongs_to :user, class_name: -> { RailsSimpleAuth.configuration.user_class_name }
# NOTE: class_name is evaluated at class load time. Users customizing
# user_class_name must configure it before this model loads (e.g., in
# config/application.rb or an early-loading initializer).
belongs_to :user, class_name: RailsSimpleAuth.configuration.user_class_name

scope :recent, -> { order(created_at: :desc) }
scope :active, -> { where(created_at: RailsSimpleAuth.configuration.session_expiry.ago..) }
Expand Down
37 changes: 37 additions & 0 deletions bin/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -e

# Local CI script for rails_simple_auth
# Run this before submitting a pull request

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GEM_DIR="$(dirname "$SCRIPT_DIR")"

cd "$GEM_DIR"

echo "=== rails_simple_auth Local CI ==="
echo ""

# Step 1: Install dependencies
echo "📦 Installing dependencies..."
bundle install --quiet

# Step 2: Run RuboCop
echo ""
echo "🔍 Running RuboCop..."
bundle exec rubocop
echo " ✅ RuboCop passed"

# Step 3: Run unit tests
echo ""
echo "🧪 Running unit tests..."
bundle exec rake test
echo " ✅ Unit tests passed"

echo ""
echo "=== All checks passed! ✅ ==="
echo ""
echo "Your code is ready for a pull request."
echo ""
echo "Optional: Run generator E2E tests (requires Rails and Playwright):"
echo " bin/test_generator"
Loading