Skip to content

Commit 4d01b7e

Browse files
committed
TDD step 9: Login view override + specs
Replaces ActiveAdmin's stock email/password login with an SSO-only button that POSTs to the OmniAuth entry point. The view ships inside the gem's app/views tree and the engine prepends that path onto ActiveAdmin::Devise::SessionsController so the override wins over ActiveAdmin's own template. Button label is configurable; default comes from Configuration::DEFAULT_LOGIN_BUTTON_LABEL.
1 parent 1c2870e commit 4d01b7e

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div id="login">
2+
<h2><%= active_admin_application.site_title(self) %></h2>
3+
4+
<%= button_to ActiveAdmin::Oidc.config.login_button_label,
5+
"/admin/auth/oidc",
6+
method: :post,
7+
class: "activeadmin-oidc-login-button",
8+
data: { turbo: false } %>
9+
</div>

lib/activeadmin/oidc/engine.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ def controllers
4040
end
4141
end
4242
end
43+
44+
# Make sure the gem's login view override wins over ActiveAdmin's
45+
# default. ActiveAdmin's view path is registered when its engine
46+
# initializes; we prepend ours in `to_prepare` so it lands in front
47+
# of ActiveAdmin's Devise::SessionsController view lookup.
48+
initializer "activeadmin_oidc.prepend_view_paths" do |app|
49+
app.config.to_prepare do
50+
require "active_admin/devise"
51+
view_path = File.expand_path("../../../app/views", __dir__)
52+
::ActiveAdmin::Devise::SessionsController.prepend_view_path(view_path)
53+
end
54+
end
4355
end
4456
end
4557
end

spec/requests/login_page_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
# The gem replaces ActiveAdmin's stock email/password login page with an
6+
# SSO-only button. This spec verifies the view override is picked up
7+
# through the engine's view path and that the button label is sourced
8+
# from configuration.
9+
RSpec.describe "Login page", type: :request do
10+
before do
11+
ActiveAdmin::Oidc.configure do |c|
12+
c.issuer = "https://idp.example.com"
13+
c.client_id = "client-abc"
14+
c.on_login = ->(*) { true }
15+
end
16+
end
17+
18+
it "renders the SSO button with the configured label" do
19+
ActiveAdmin::Oidc.config.login_button_label = "Sign in with Corporate SSO"
20+
21+
get "/admin/login"
22+
23+
expect(response).to have_http_status(:ok)
24+
expect(response.body).to include("Sign in with Corporate SSO")
25+
expect(response.body).to include(%(action="/admin/auth/oidc"))
26+
end
27+
28+
it "does not render email or password fields" do
29+
get "/admin/login"
30+
31+
expect(response.body).not_to match(/name="admin_user\[password\]"/)
32+
expect(response.body).not_to match(/name="admin_user\[email\]"/)
33+
end
34+
35+
it "uses the default login button label when not configured" do
36+
get "/admin/login"
37+
38+
expect(response.body).to include(ActiveAdmin::Oidc::Configuration::DEFAULT_LOGIN_BUTTON_LABEL)
39+
end
40+
end

0 commit comments

Comments
 (0)