Finished phase005
CI / scan_ruby (push) Failing after 1m5s
CI / scan_js (push) Failing after 6s
CI / lint (push) Failing after 1m29s

This commit is contained in:
2026-09-16 15:34:50 -06:00
parent a3a65c24ed
commit 0826d267f2
38 changed files with 1596 additions and 9 deletions
+53
View File
@@ -0,0 +1,53 @@
require "rails_helper"
RSpec.describe AccessKey do
it "creates a current access key when one does not exist" do
expect { described_class.current }.to change(described_class, :count).by(1)
expect(described_class.current.raw_key).to be_present
end
it "matches the submitted raw key" do
access_key = described_class.current
expect(access_key.matches?(access_key.raw_key)).to be(true)
expect(access_key.matches?("wrong-key")).to be(false)
end
it "rotates the key and invalidates user sessions" do
old_key = described_class.current
user = create(:user)
UserSession.create_for!(user)
expect do
described_class.rotate!
end.to change(described_class, :count).by(1).and change(UserSession, :count).to(0)
expect(described_class.current.raw_key).not_to eq(old_key.raw_key)
end
it "does not auto-rotate when auto rotation is disabled" do
access_key = described_class.current
access_key.update!(generated_at: 31.days.ago)
access_key.disable_auto_rotation!
expect do
described_class.rotate_if_needed!
end.not_to change(described_class, :count)
end
it "auto-rotates when enabled and expired" do
access_key = described_class.current
access_key.update!(generated_at: 31.days.ago)
expect do
described_class.rotate_if_needed!
end.to change(described_class, :count).by(1)
end
it "uses the configured auto rotation frequency" do
access_key = described_class.current
access_key.update!(generated_at: 10.days.ago, auto_rotation_frequency_days: 7)
expect(access_key).to be_expired
end
end
+22
View File
@@ -35,4 +35,26 @@ RSpec.describe FuelEntry do
expect(entry).not_to be_valid
expect(entry.errors[:date]).to be_present
end
it "rejects odometer readings below the vehicle current odometer" do
vehicle = build(:vehicle, current_odometer: 10_000)
entry = build(:fuel_entry, vehicle: vehicle, odometer: 9_999)
expect(entry).not_to be_valid
expect(entry.errors[:odometer]).to be_present
end
it "allows odometer readings equal to the vehicle current odometer" do
vehicle = build(:vehicle, current_odometer: 10_000)
entry = build(:fuel_entry, vehicle: vehicle, odometer: 10_000)
expect(entry).to be_valid
end
it "allows odometer readings above the vehicle current odometer" do
vehicle = build(:vehicle, current_odometer: 10_000)
entry = build(:fuel_entry, vehicle: vehicle, odometer: 10_001)
expect(entry).to be_valid
end
end
+21
View File
@@ -0,0 +1,21 @@
require "rails_helper"
RSpec.describe UserSession do
it "creates a session for a user and returns the raw token" do
user = create(:user)
user_session, raw_token = described_class.create_for!(user)
expect(user_session.user).to eq(user)
expect(raw_token).to be_present
expect(user_session.token_digest).not_to eq(raw_token)
end
it "finds sessions by raw token" do
user = create(:user)
user_session, raw_token = described_class.create_for!(user)
expect(described_class.find_by_token(raw_token)).to eq(user_session)
expect(described_class.find_by_token("wrong-token")).to be_nil
end
end
+8
View File
@@ -45,6 +45,14 @@ RSpec.describe Vehicle do
expect(vehicle.vin).to eq("ABC123")
end
it "normalizes licence plate to uppercase" do
vehicle = build(:vehicle, licence_plate: "kj7cyt")
vehicle.valid?
expect(vehicle.licence_plate).to eq("KJ7CYT")
end
it "requires VIN to be unique after normalization" do
create(:vehicle, vin: "ABC123")