Skip to content

Commit 131e00d

Browse files
chore: fix gem version badge and expand test coverage to 100% (#110)
Switch gem version badge from badge.fury.io to shields.io to fix stale version display. Add specs for audit_action_badge_class, AuditController table-missing redirect, with_database_connection routing branches, and resolve_current_actor rescue path. Co-authored-by: Chuck Smith <eclectic-coding@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d13022f commit 131e00d

4 files changed

Lines changed: 86 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SolidStackWeb
22

33
[![CI](https://github.com/eclectic-coding/solid_stack_web/actions/workflows/ci.yml/badge.svg)](https://github.com/eclectic-coding/solid_stack_web/actions/workflows/ci.yml)
4-
[![Gem Version](https://badge.fury.io/rb/solid_stack_web.svg)](https://badge.fury.io/rb/solid_stack_web)
4+
[![Gem Version](https://img.shields.io/gem/v/solid_stack_web.svg)](https://rubygems.org/gems/solid_stack_web)
55
[![Downloads](https://img.shields.io/gem/dt/solid_stack_web.svg)](https://rubygems.org/gems/solid_stack_web)
66
[![Ruby](https://img.shields.io/badge/ruby-%3E%3D%203.3-ruby)](https://www.ruby-lang.org)
77
[![codecov](https://codecov.io/gh/eclectic-coding/solid_stack_web/branch/main/graph/badge.svg)](https://codecov.io/gh/eclectic-coding/solid_stack_web)

spec/helpers/solid_stack_web/application_helper_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,22 @@
4242
expect(helper.format_duration(7200)).to eq("2h 0m")
4343
end
4444
end
45+
46+
describe "#audit_action_badge_class" do
47+
it "returns failed badge class for discard actions" do
48+
expect(helper.audit_action_badge_class("discard")).to eq("sqw-badge--failed")
49+
end
50+
51+
it "returns scheduled badge class for retry actions" do
52+
expect(helper.audit_action_badge_class("retry")).to eq("sqw-badge--scheduled")
53+
end
54+
55+
it "returns blocked badge class for queue_paused" do
56+
expect(helper.audit_action_badge_class("queue_paused")).to eq("sqw-badge--blocked")
57+
end
58+
59+
it "returns ready badge class for queue_resumed" do
60+
expect(helper.audit_action_badge_class("queue_resumed")).to eq("sqw-badge--ready")
61+
end
62+
end
4563
end

spec/requests/solid_stack_web/audit_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ def create_event(action: "job_discarded", actor: nil, job_class: "MyJob", queue_
1010
)
1111
end
1212

13+
describe "GET /audit when table is missing" do
14+
it "redirects to root with an alert" do
15+
allow(SolidStackWeb::AuditEvent).to receive(:table_exists?).and_return(false)
16+
get "#{engine_root}/audit"
17+
expect(response).to redirect_to("#{engine_root}/")
18+
expect(flash[:alert]).to include("rails solid_stack_web:install:migrations")
19+
end
20+
end
21+
1322
describe "GET /audit" do
1423
it "returns 200" do
1524
get "#{engine_root}/audit"
@@ -155,5 +164,24 @@ def create_event(action: "job_discarded", actor: nil, job_class: "MyJob", queue_
155164
expect(SolidStackWeb::AuditEvent.last.action).to eq("queue_paused")
156165
expect(SolidStackWeb::AuditEvent.last.queue_name).to eq("default")
157166
end
167+
168+
context "when current_actor block raises" do
169+
around do |example|
170+
SolidStackWeb.current_actor { raise "actor boom" }
171+
example.run
172+
ensure
173+
SolidStackWeb.instance_variable_set(:@current_actor, nil)
174+
end
175+
176+
it "records the event with a nil actor and does not raise" do
177+
SolidQueue::Job.create!(class_name: "MyJob", queue_name: "default")
178+
179+
expect {
180+
post "#{engine_root}/queues/default/pause"
181+
}.to change(SolidStackWeb::AuditEvent, :count).by(1)
182+
183+
expect(SolidStackWeb::AuditEvent.last.actor).to be_nil
184+
end
185+
end
158186
end
159187
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require "rails_helper"
2+
3+
RSpec.describe "Database connection routing", type: :request do
4+
let(:engine_root) { "/solid_stack" }
5+
6+
around do |example|
7+
original = SolidStackWeb.connects_to
8+
example.run
9+
ensure
10+
SolidStackWeb.instance_variable_set(:@connects_to, original)
11+
end
12+
13+
context "when connects_to has :reading and :writing roles" do
14+
before { SolidStackWeb.connects_to = { reading: :reading, writing: :writing } }
15+
16+
it "uses the reading role for GET requests" do
17+
allow(ActiveRecord::Base).to receive(:connected_to).and_yield
18+
get "#{engine_root}/jobs"
19+
expect(ActiveRecord::Base).to have_received(:connected_to).with(role: :reading)
20+
end
21+
22+
it "uses the writing role for non-GET requests" do
23+
allow(ActiveRecord::Base).to receive(:connected_to).and_yield
24+
SolidQueue::Job.create!(class_name: "MyJob", queue_name: "default")
25+
post "#{engine_root}/queues/default/pause"
26+
expect(ActiveRecord::Base).to have_received(:connected_to).with(role: :writing)
27+
end
28+
end
29+
30+
context "when connects_to has a single arbitrary config" do
31+
before { SolidStackWeb.connects_to = { role: :primary } }
32+
33+
it "splats the config directly into connected_to" do
34+
allow(ActiveRecord::Base).to receive(:connected_to).and_yield
35+
get "#{engine_root}/jobs"
36+
expect(ActiveRecord::Base).to have_received(:connected_to).with(role: :primary)
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)