diff --git a/spec/fixtures/geometric_analysis_job_spec/manifold.stl b/spec/fixtures/geometric_analysis_job_spec/manifold.stl new file mode 100644 index 000000000..f27cb7e64 Binary files /dev/null and b/spec/fixtures/geometric_analysis_job_spec/manifold.stl differ diff --git a/spec/fixtures/geometric_analysis_job_spec/non_manifold.stl b/spec/fixtures/geometric_analysis_job_spec/non_manifold.stl new file mode 100644 index 000000000..9ab89b44c Binary files /dev/null and b/spec/fixtures/geometric_analysis_job_spec/non_manifold.stl differ diff --git a/spec/jobs/analysis/geometric_analysis_job_spec.rb b/spec/jobs/analysis/geometric_analysis_job_spec.rb index 765ef0a76..febc8d02d 100644 --- a/spec/jobs/analysis/geometric_analysis_job_spec.rb +++ b/spec/jobs/analysis/geometric_analysis_job_spec.rb @@ -2,55 +2,45 @@ require "support/mock_directory" RSpec.describe Analysis::GeometricAnalysisJob do - let(:file) { create(:model_file, filename: "test.stl") } - let(:sphere) do - m = Mittsu::Mesh.new(Mittsu::SphereGeometry.new(2.0, 32, 16)) - m.geometry.merge_vertices - m - end - let(:plane) do - m = Mittsu::Mesh.new(Mittsu::PlaneGeometry.new(2.0, 2.0, 16, 16)) - m.geometry.merge_vertices - m - end + let(:library) { create(:library, path: Rails.root.join("spec/fixtures")) } + let(:model) { create(:model, library: library, path: "geometric_analysis_job_spec") } + let(:manifold_mesh) { + create(:model_file, model: model, filename: "manifold.stl", + attachment: ModelFileUploader.upload(File.open("spec/fixtures/geometric_analysis_job_spec/manifold.stl"), :cache)) + } + let(:non_manifold_mesh) { + create(:model_file, model: model, filename: "non_manifold.stl", + attachment: ModelFileUploader.upload(File.open("spec/fixtures/geometric_analysis_job_spec/non_manifold.stl"), :cache)) + } before do - allow(described_class).to receive(:load_mesh).with(file).and_return(sphere) - allow(ModelFile).to receive(:find).and_call_original - allow(ModelFile).to receive(:find).with(file.id).and_return(file) allow(SiteSettings).to receive(:analyse_manifold).and_return(true) end it "does not create Problems for a good mesh" do - allow(described_class).to receive(:load_mesh).with(file).and_return(sphere) - expect { described_class.perform_now(file.id) }.not_to change(Problem, :count) + expect { described_class.perform_now(manifold_mesh.id) }.not_to change(Problem, :count) end it "creates a Problem for a non-manifold mesh" do # rubocop:todo RSpec/MultipleExpectations - allow(described_class).to receive(:load_mesh).with(file).and_return(plane) - expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(0).to(1) + expect { described_class.perform_now(non_manifold_mesh.id) }.to change(Problem, :count).from(0).to(1) expect(Problem.first.category).to eq "non_manifold" end it "removes a manifold problem if the mesh is OK" do - allow(described_class).to receive(:load_mesh).with(file).and_return(sphere) - create(:problem, problematic: file, category: :non_manifold) - expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(1).to(0) + create(:problem, problematic: manifold_mesh, category: :non_manifold) + expect { described_class.perform_now(manifold_mesh.id) }.to change(Problem, :count).from(1).to(0) end it "creates a Problem for an inside-out mesh" do # rubocop:todo RSpec/MultipleExpectations pending "not currently working reliably" - allow(mesh).to receive(:solid?).and_return(false) - allow(described_class).to receive(:load_mesh).with(file).and_return(mesh) - expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(0).to(1) + expect { described_class.perform_now(flipped_mesh.id) }.to change(Problem, :count).from(0).to(1) expect(Problem.first.category).to eq "inside_out" end it "removes an inside-out problem if the mesh is OK" do pending "not currently working reliably" - allow(described_class).to receive(:load_mesh).with(file).and_return(mesh) - create(:problem, problematic: file, category: :inside_out) - expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(1).to(0) + create(:problem, problematic: manifold_mesh, category: :inside_out) + expect { described_class.perform_now(manifold_mesh.id) }.to change(Problem, :count).from(1).to(0) end it "raises exception if file ID is not found" do