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
1 change: 0 additions & 1 deletion app/models/assessments/slide_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def required_runout_length
)
end


sig { returns(T::Boolean) }
def meets_wall_height_requirements?
return false unless slide_platform_height.present? &&
Expand Down
54 changes: 27 additions & 27 deletions spec/controllers/guides_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
controller = GuidesController.new
test_guides = [{title: "Test Guide", path: "test"}]
allow(controller).to receive(:collect_guides).and_return(test_guides)

# Simulate what the index action does
controller.index
expect(controller.instance_variable_get(:@guides)).to eq(test_guides)
end
end

describe "#collect_guides" do
it "collects and sorts guides from metadata files" do
controller = GuidesController.new

# Mock file system
allow(Dir).to receive(:glob).and_return([
"/path/zebra_guide/metadata.json",
"/path/alpha_guide/metadata.json"
])

metadata = {
"screenshots" => [{"filename" => "test.png", "caption" => "Test"}],
"updated_at" => "2024-01-15T10:00:00Z"
}
allow(File).to receive(:read).and_return(metadata.to_json)

# Mock Pathname operations - first path is zebra, second is alpha
# But they should be sorted alphabetically after collection
allow_any_instance_of(Pathname).to receive(:relative_path_from) do |path|
Expand All @@ -39,41 +39,41 @@
instance_double(Pathname, dirname: instance_double(Pathname, to_s: "alpha_guide"))
end
end

guides = controller.send(:collect_guides)
expect(guides.length).to eq(2)
# After sorting by title, alpha should come first
expect(guides.first[:title]).to eq("Alpha guide")
expect(guides.last[:title]).to eq("Zebra guide")
end

it "returns empty array when no guides exist" do
controller = GuidesController.new
allow(Dir).to receive(:glob).and_return([])

guides = controller.send(:collect_guides)
expect(guides).to eq([])
end
end

describe "GET #show" do
let(:guide_path) { "test_guide" }

before do
# Skip n_plus_one_detection and stub render/redirect to avoid template rendering issues
allow(controller).to receive(:n_plus_one_detection).and_yield
allow(controller).to receive(:render)
allow(controller).to receive(:redirect_to)
end

context "when metadata file exists" do
let(:metadata) do
{
"screenshots" => [{"filename" => "test.png", "caption" => "Test"}],
"updated_at" => "2024-01-15T10:00:00Z"
}
end

before do
metadata_file = instance_double(Pathname)
allow(metadata_file).to receive(:exist?).and_return(true)
Expand All @@ -82,23 +82,23 @@
instance_double(Pathname, join: metadata_file)
)
end

it "assigns guide data when metadata exists" do
get :show, params: { path: guide_path }
get :show, params: {path: guide_path}
expect(assigns(:guide_data)).to eq(metadata)
end

it "assigns guide path" do
get :show, params: { path: guide_path }
get :show, params: {path: guide_path}
expect(assigns(:guide_path)).to eq(guide_path)
end

it "assigns humanized guide title" do
get :show, params: { path: guide_path }
get :show, params: {path: guide_path}
expect(assigns(:guide_title)).to eq("Test guide")
end
end

context "when metadata file does not exist" do
before do
metadata_file = instance_double(Pathname)
Expand All @@ -109,21 +109,21 @@
# Don't stub redirect_to for these tests
allow(controller).to receive(:render)
end

it "redirects to guides path when metadata doesn't exist" do
allow(controller).to receive(:redirect_to).and_call_original
get :show, params: { path: guide_path }
get :show, params: {path: guide_path}
expect(response).to redirect_to(guides_path)
end

it "sets flash alert when guide not found" do
allow(controller).to receive(:redirect_to).and_call_original
get :show, params: { path: guide_path }
get :show, params: {path: guide_path}
expect(flash[:alert]).to eq(I18n.t("guides.messages.not_found"))
end
end
end

describe "private methods" do
describe "#guide_screenshots_root" do
it "returns the correct path" do
Expand All @@ -132,17 +132,17 @@
expect(controller.send(:guide_screenshots_root)).to eq(expected_path)
end
end

describe "#humanize_guide_title" do
it "removes _spec suffix and humanizes" do
controller = GuidesController.new
expect(controller.send(:humanize_guide_title, "test_workflow_spec")).to eq("Test workflow")
end

it "handles nested paths" do
controller = GuidesController.new
expect(controller.send(:humanize_guide_title, "features/admin/user_management")).to eq("User management")
end
end
end
end
end
4 changes: 2 additions & 2 deletions spec/models/assessments/slide_assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
.once
expect(EN14960::Calculators::SlideCalculator).not_to receive(:meets_height_requirements?)
.with(3.0, 1.2, 0.5, false)

slide_assessment.meets_wall_height_requirements?
end
end
Expand Down Expand Up @@ -406,4 +406,4 @@
expect(described_class.primary_key).to eq("inspection_id")
end
end
end
end
26 changes: 13 additions & 13 deletions spec/models/inspection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@
it "handles end date correctly with DateTime fields" do
# Date ranges with DateTime columns only include times before midnight of end date + 1
on_end_early = create(:inspection, inspection_date: Time.zone.local(2024, 1, 30, 23, 59, 59))
after_end = create(:inspection, inspection_date: Time.zone.local(2024, 1, 31, 0, 0, 1))
create(:inspection, inspection_date: Time.zone.local(2024, 1, 31, 0, 0, 1))

result = Inspection.filter_by_date_range(start_date, end_date)
expect(result).to include(on_end_early)
# Note: Rails Date ranges exclude times on the end date itself for DateTime fields
Expand Down Expand Up @@ -427,19 +427,19 @@
describe "#each_applicable_assessment" do
it "yields each applicable assessment with key, class, and instance" do
yielded_assessments = []

inspection.each_applicable_assessment do |key, klass, assessment|
yielded_assessments << [key, klass, assessment]
end

# Should yield all applicable assessments for a castle
expect(yielded_assessments.map(&:first)).to include(
:user_height_assessment,
:structure_assessment,
:materials_assessment,
:fan_assessment
)

# Each yielded assessment should have the correct class
yielded_assessments.each do |key, klass, assessment|
expect(assessment).to be_a(klass)
Expand All @@ -449,20 +449,20 @@
it "only yields slide assessment when has_slide is true" do
inspection.has_slide = false
yielded_keys = []

inspection.each_applicable_assessment do |key, _, _|
yielded_keys << key
end

expect(yielded_keys).not_to include(:slide_assessment)

inspection.has_slide = true
yielded_keys = []

inspection.each_applicable_assessment do |key, _, _|
yielded_keys << key
end

expect(yielded_keys).to include(:slide_assessment)
end

Expand All @@ -487,14 +487,14 @@
it "includes incomplete field information for each tab" do
inspection.user_height_assessment.update(containing_wall_height: nil)
errors = inspection.completion_errors

expect(errors.any? { |e| e.include?(I18n.t("forms.user_height.header")) }).to be true
end

it "formats errors with tab name and field labels" do
inspection.passed = nil
errors = inspection.completion_errors

expect(errors.any? { |e| e.include?(I18n.t("forms.results.header")) }).to be true
end
end
Expand All @@ -507,7 +507,7 @@
resource: inspection,
details: "Test details"
)

inspection.log_audit_action("test_action", user, "Test details")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/errors_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@
end
end
end
end
end
Loading