← Back to list

test-auth-helpers
by rbarazi
⭐ 0🍴 0📅 Jan 13, 2026
SKILL.md
name: test-auth-helpers description: 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.
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
Score
Total Score
50/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon