Skip to content

Commit 7b63b40

Browse files
committed
test manifold check using real files
1 parent fee5b60 commit 7b63b40

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed
3.19 MB
Binary file not shown.
3.31 MB
Binary file not shown.

spec/jobs/analysis/geometric_analysis_job_spec.rb

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,45 @@
22
require "support/mock_directory"
33

44
RSpec.describe Analysis::GeometricAnalysisJob do
5-
let(:file) { create(:model_file, filename: "test.stl") }
6-
let(:sphere) do
7-
m = Mittsu::Mesh.new(Mittsu::SphereGeometry.new(2.0, 32, 16))
8-
m.geometry.merge_vertices
9-
m
10-
end
11-
let(:plane) do
12-
m = Mittsu::Mesh.new(Mittsu::PlaneGeometry.new(2.0, 2.0, 16, 16))
13-
m.geometry.merge_vertices
14-
m
15-
end
5+
let(:library) { create(:library, path: Rails.root.join("spec/fixtures")) }
6+
let(:model) { create(:model, library: library, path: "geometric_analysis_job_spec") }
7+
let(:manifold_mesh) {
8+
create(:model_file, model: model, filename: "manifold.stl",
9+
attachment: ModelFileUploader.upload(File.open("spec/fixtures/geometric_analysis_job_spec/manifold.stl"), :cache))
10+
}
11+
let(:non_manifold_mesh) {
12+
create(:model_file, model: model, filename: "non_manifold.stl",
13+
attachment: ModelFileUploader.upload(File.open("spec/fixtures/geometric_analysis_job_spec/non_manifold.stl"), :cache))
14+
}
1615

1716
before do
18-
allow(described_class).to receive(:load_mesh).with(file).and_return(sphere)
19-
allow(ModelFile).to receive(:find).and_call_original
20-
allow(ModelFile).to receive(:find).with(file.id).and_return(file)
2117
allow(SiteSettings).to receive(:analyse_manifold).and_return(true)
2218
end
2319

2420
it "does not create Problems for a good mesh" do
25-
allow(described_class).to receive(:load_mesh).with(file).and_return(sphere)
26-
expect { described_class.perform_now(file.id) }.not_to change(Problem, :count)
21+
expect { described_class.perform_now(manifold_mesh.id) }.not_to change(Problem, :count)
2722
end
2823

2924
it "creates a Problem for a non-manifold mesh" do # rubocop:todo RSpec/MultipleExpectations
30-
allow(described_class).to receive(:load_mesh).with(file).and_return(plane)
31-
expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(0).to(1)
25+
expect { described_class.perform_now(non_manifold_mesh.id) }.to change(Problem, :count).from(0).to(1)
3226
expect(Problem.first.category).to eq "non_manifold"
3327
end
3428

3529
it "removes a manifold problem if the mesh is OK" do
36-
allow(described_class).to receive(:load_mesh).with(file).and_return(sphere)
37-
create(:problem, problematic: file, category: :non_manifold)
38-
expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(1).to(0)
30+
create(:problem, problematic: manifold_mesh, category: :non_manifold)
31+
expect { described_class.perform_now(manifold_mesh.id) }.to change(Problem, :count).from(1).to(0)
3932
end
4033

4134
it "creates a Problem for an inside-out mesh" do # rubocop:todo RSpec/MultipleExpectations
4235
pending "not currently working reliably"
43-
allow(mesh).to receive(:solid?).and_return(false)
44-
allow(described_class).to receive(:load_mesh).with(file).and_return(mesh)
45-
expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(0).to(1)
36+
expect { described_class.perform_now(flipped_mesh.id) }.to change(Problem, :count).from(0).to(1)
4637
expect(Problem.first.category).to eq "inside_out"
4738
end
4839

4940
it "removes an inside-out problem if the mesh is OK" do
5041
pending "not currently working reliably"
51-
allow(described_class).to receive(:load_mesh).with(file).and_return(mesh)
52-
create(:problem, problematic: file, category: :inside_out)
53-
expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(1).to(0)
42+
create(:problem, problematic: manifold_mesh, category: :inside_out)
43+
expect { described_class.perform_now(manifold_mesh.id) }.to change(Problem, :count).from(1).to(0)
5444
end
5545

5646
it "raises exception if file ID is not found" do

0 commit comments

Comments
 (0)