Agent skill
test-auth-helpers
Implement authentication testing patterns with RSpec, FactoryBot, and test helpers for Rails applications. Use when writing controller specs, system tests, or request specs that require authenticated users and multi-tenant account context.
Install this agent skill to your Project
npx add-skill https://github.com/rbarazi/agent-skills/tree/main/skills/test-auth-helpers
SKILL.md
Test Authentication Helpers Pattern
Testing patterns for authentication in Rails applications using RSpec and FactoryBot.
When to Use
- Writing controller specs with authenticated users
- Creating system tests with login flows
- Building request specs with session authentication
- Testing multi-tenant account scoping
Quick Start
1. Authentication Helper Module
# spec/support/authentication_helpers.rb
module AuthenticationHelpers
# For controller and request specs
def setup_authenticated_user(user = nil)
account = create(:account)
user ||= create(:user, account: account)
session = create(:session, user: user)
if respond_to?(:cookies)
cookies.signed[:session_id] = session.id
end
[account, user, session]
end
# For system tests - performs actual login
def login_user(user)
visit new_session_path
fill_in I18n.t('sessions.form.email'), with: user.email_address
fill_in I18n.t('sessions.form.password'), with: "password"
click_button I18n.t('sessions.form.sign_in')
expect(page).not_to have_current_path(new_session_path, wait: 10)
end
# For API specs with Bearer token
def auth_headers_for(user)
session = create(:session, user: user)
{ "Authorization" => "Bearer #{session.id}" }
end
end
RSpec.configure do |config|
config.include AuthenticationHelpers
end
2. Usage in Controller Specs
RSpec.describe AgentsController, type: :controller do
let(:account) { create(:account) }
let(:user) { create(:user, account: account) }
before { setup_authenticated_user(user) }
it 'returns success' do
get :index
expect(response).to be_successful
end
end
3. Usage in System Tests
RSpec.describe 'Agent Management', type: :system, js: true do
let(:account) { create(:account) }
let(:user) { create(:user, account: account) }
before { login_user(user) }
it 'shows agents page' do
visit agents_path
expect(page).to have_content(I18n.t('agents.index.title'))
end
end
Key Patterns
- Controller specs: Use
setup_authenticated_userwith cookie injection - System tests: Use
login_userwith actual form submission - API specs: Use
auth_headers_forwith Bearer token - Always use I18n: Never hardcode button/label text
Reference Files
For complete implementation details:
- factories.md - Account, User, Session factories
- helpers.md - Full AuthenticationHelpers module
- controller-specs.md - Controller testing patterns
- system-specs.md - System test patterns
- request-specs.md - API and request spec patterns
- best-practices.md - Do's, don'ts, debugging tips
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
multi-tenant-accounts
Implement multi-tenant architecture using an Account model as the tenant boundary. Use when building SaaS applications, team-based apps, or any system where data must be isolated between organizations/accounts.
user-management
Implement user CRUD operations within an account with permission controls and feature flags. Use when building team member management, user administration, or account user settings in multi-tenant Rails applications.
oauth21-provider
Implement an RFC-compliant OAuth 2.1 authorization server in Rails applications. Use when building apps that need to authorize third-party clients (like MCP clients, API consumers, or external integrations) using industry-standard OAuth flows with PKCE, dynamic client registration, and token management.
password-reset-flow
Implement secure password reset with Rails 8's built-in token generation. Use when building "forgot password" functionality with email verification and time-limited reset tokens.
code-pattern-extraction
Extract reusable design and implementation patterns from codebases into Skills. Use when asked to analyze code for patterns, document architectural decisions, create transferrable implementation guides, or extract knowledge into Skills. Transforms working implementations into comprehensive, reusable Skills that can be applied to new projects.
slack-mcp-server
Create MCP servers that interact with Slack APIs. Use when building agent tools for Slack canvases, posting messages, or other Slack operations via Model Context Protocol.
Didn't find tool you were looking for?