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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SolidStackWeb

[![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)
[![Gem Version](https://badge.fury.io/rb/solid_stack_web.svg)](https://badge.fury.io/rb/solid_stack_web)
[![Gem Version](https://img.shields.io/gem/v/solid_stack_web.svg)](https://rubygems.org/gems/solid_stack_web)
[![Downloads](https://img.shields.io/gem/dt/solid_stack_web.svg)](https://rubygems.org/gems/solid_stack_web)
[![Ruby](https://img.shields.io/badge/ruby-%3E%3D%203.3-ruby)](https://www.ruby-lang.org)
[![codecov](https://codecov.io/gh/eclectic-coding/solid_stack_web/branch/main/graph/badge.svg)](https://codecov.io/gh/eclectic-coding/solid_stack_web)
Expand Down
18 changes: 18 additions & 0 deletions spec/helpers/solid_stack_web/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,22 @@
expect(helper.format_duration(7200)).to eq("2h 0m")
end
end

describe "#audit_action_badge_class" do
it "returns failed badge class for discard actions" do
expect(helper.audit_action_badge_class("discard")).to eq("sqw-badge--failed")
end

it "returns scheduled badge class for retry actions" do
expect(helper.audit_action_badge_class("retry")).to eq("sqw-badge--scheduled")
end

it "returns blocked badge class for queue_paused" do
expect(helper.audit_action_badge_class("queue_paused")).to eq("sqw-badge--blocked")
end

it "returns ready badge class for queue_resumed" do
expect(helper.audit_action_badge_class("queue_resumed")).to eq("sqw-badge--ready")
end
end
end
28 changes: 28 additions & 0 deletions spec/requests/solid_stack_web/audit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ def create_event(action: "job_discarded", actor: nil, job_class: "MyJob", queue_
)
end

describe "GET /audit when table is missing" do
it "redirects to root with an alert" do
allow(SolidStackWeb::AuditEvent).to receive(:table_exists?).and_return(false)
get "#{engine_root}/audit"
expect(response).to redirect_to("#{engine_root}/")
expect(flash[:alert]).to include("rails solid_stack_web:install:migrations")
end
end

describe "GET /audit" do
it "returns 200" do
get "#{engine_root}/audit"
Expand Down Expand Up @@ -155,5 +164,24 @@ def create_event(action: "job_discarded", actor: nil, job_class: "MyJob", queue_
expect(SolidStackWeb::AuditEvent.last.action).to eq("queue_paused")
expect(SolidStackWeb::AuditEvent.last.queue_name).to eq("default")
end

context "when current_actor block raises" do
around do |example|
SolidStackWeb.current_actor { raise "actor boom" }
example.run
ensure
SolidStackWeb.instance_variable_set(:@current_actor, nil)
end

it "records the event with a nil actor and does not raise" do
SolidQueue::Job.create!(class_name: "MyJob", queue_name: "default")

expect {
post "#{engine_root}/queues/default/pause"
}.to change(SolidStackWeb::AuditEvent, :count).by(1)

expect(SolidStackWeb::AuditEvent.last.actor).to be_nil
end
end
end
end
39 changes: 39 additions & 0 deletions spec/requests/solid_stack_web/database_connection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "rails_helper"

RSpec.describe "Database connection routing", type: :request do
let(:engine_root) { "/solid_stack" }

around do |example|
original = SolidStackWeb.connects_to
example.run
ensure
SolidStackWeb.instance_variable_set(:@connects_to, original)
end

context "when connects_to has :reading and :writing roles" do
before { SolidStackWeb.connects_to = { reading: :reading, writing: :writing } }

it "uses the reading role for GET requests" do
allow(ActiveRecord::Base).to receive(:connected_to).and_yield
get "#{engine_root}/jobs"
expect(ActiveRecord::Base).to have_received(:connected_to).with(role: :reading)
end

it "uses the writing role for non-GET requests" do
allow(ActiveRecord::Base).to receive(:connected_to).and_yield
SolidQueue::Job.create!(class_name: "MyJob", queue_name: "default")
post "#{engine_root}/queues/default/pause"
expect(ActiveRecord::Base).to have_received(:connected_to).with(role: :writing)
end
end

context "when connects_to has a single arbitrary config" do
before { SolidStackWeb.connects_to = { role: :primary } }

it "splats the config directly into connected_to" do
allow(ActiveRecord::Base).to receive(:connected_to).and_yield
get "#{engine_root}/jobs"
expect(ActiveRecord::Base).to have_received(:connected_to).with(role: :primary)
end
end
end