|
2 | 2 | require "support/mock_directory" |
3 | 3 |
|
4 | 4 | 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 | + } |
16 | 15 |
|
17 | 16 | 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) |
21 | 17 | allow(SiteSettings).to receive(:analyse_manifold).and_return(true) |
22 | 18 | end |
23 | 19 |
|
24 | 20 | 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) |
27 | 22 | end |
28 | 23 |
|
29 | 24 | 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) |
32 | 26 | expect(Problem.first.category).to eq "non_manifold" |
33 | 27 | end |
34 | 28 |
|
35 | 29 | 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) |
39 | 32 | end |
40 | 33 |
|
41 | 34 | it "creates a Problem for an inside-out mesh" do # rubocop:todo RSpec/MultipleExpectations |
42 | 35 | 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) |
46 | 37 | expect(Problem.first.category).to eq "inside_out" |
47 | 38 | end |
48 | 39 |
|
49 | 40 | it "removes an inside-out problem if the mesh is OK" do |
50 | 41 | 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) |
54 | 44 | end |
55 | 45 |
|
56 | 46 | it "raises exception if file ID is not found" do |
|
0 commit comments