2020-04-15 15:43:38 +02:00
|
|
|
|
RSpec.describe GeoArea, type: :model do
|
|
|
|
|
describe '#area' do
|
2021-10-19 18:13:44 +02:00
|
|
|
|
let(:geo_area) { build(:geo_area, :polygon, champ: nil) }
|
2020-04-15 15:43:38 +02:00
|
|
|
|
|
2020-10-01 11:32:56 +02:00
|
|
|
|
it { expect(geo_area.area).to eq(103.6) }
|
2020-04-15 15:43:38 +02:00
|
|
|
|
end
|
|
|
|
|
|
2020-09-23 14:37:07 +02:00
|
|
|
|
describe '#area (hourglass polygon)' do
|
2021-10-19 18:13:44 +02:00
|
|
|
|
let(:geo_area) { build(:geo_area, :hourglass_polygon, champ: nil) }
|
2020-09-23 14:37:07 +02:00
|
|
|
|
|
2020-10-01 11:32:56 +02:00
|
|
|
|
it { expect(geo_area.area).to eq(32.4) }
|
2020-09-23 14:37:07 +02:00
|
|
|
|
end
|
|
|
|
|
|
2020-04-15 15:43:38 +02:00
|
|
|
|
describe '#length' do
|
2021-10-19 18:13:44 +02:00
|
|
|
|
let(:geo_area) { build(:geo_area, :line_string, champ: nil) }
|
2020-04-15 15:43:38 +02:00
|
|
|
|
|
2020-10-01 11:33:15 +02:00
|
|
|
|
it { expect(geo_area.length).to eq(21.2) }
|
2020-04-15 15:43:38 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#location' do
|
2021-10-19 18:13:44 +02:00
|
|
|
|
let(:geo_area) { build(:geo_area, :point, champ: nil) }
|
2020-04-15 15:43:38 +02:00
|
|
|
|
|
2020-09-23 11:34:10 +02:00
|
|
|
|
it { expect(geo_area.location).to eq("46°32'19\"N 2°25'42\"E") }
|
2020-04-15 15:43:38 +02:00
|
|
|
|
end
|
2020-05-05 10:26:13 +02:00
|
|
|
|
|
2021-10-19 18:13:44 +02:00
|
|
|
|
describe 'validations' do
|
|
|
|
|
context 'geometry' do
|
|
|
|
|
subject! { geo_area.validate }
|
2021-03-16 10:38:56 +01:00
|
|
|
|
|
2021-10-19 18:13:44 +02:00
|
|
|
|
context 'polygon' do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :polygon, champ: nil) }
|
|
|
|
|
it { expect(geo_area.errors).not_to have_key(:geometry) }
|
|
|
|
|
end
|
2021-03-16 10:38:56 +01:00
|
|
|
|
|
2021-10-19 18:13:44 +02:00
|
|
|
|
context 'line_string' do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :line_string, champ: nil) }
|
|
|
|
|
it { expect(geo_area.errors).not_to have_key(:geometry) }
|
|
|
|
|
end
|
2021-03-16 10:38:56 +01:00
|
|
|
|
|
2021-10-19 18:13:44 +02:00
|
|
|
|
context 'point' do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :point, champ: nil) }
|
|
|
|
|
it { expect(geo_area.errors).not_to have_key(:geometry) }
|
|
|
|
|
end
|
2021-03-16 10:38:56 +01:00
|
|
|
|
|
2023-04-07 15:24:28 +02:00
|
|
|
|
context "allow empty {}" do
|
|
|
|
|
let(:geo_area) { build(:geo_area, geometry: {}) }
|
|
|
|
|
it { expect(geo_area.errors).not_to have_key(:geometry) }
|
2021-10-19 18:13:44 +02:00
|
|
|
|
end
|
2023-04-21 17:26:28 +02:00
|
|
|
|
|
|
|
|
|
context "nil" do
|
|
|
|
|
let(:geo_area) { build(:geo_area, geometry: nil) }
|
|
|
|
|
it { expect(geo_area.errors).to have_key(:geometry) }
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-07 15:24:28 +02:00
|
|
|
|
context 'invalid point' do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :invalid_point, champ: nil) }
|
|
|
|
|
it { expect(geo_area.errors).to have_key(:geometry) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context.skip 'invalid_right_hand_rule_polygon' do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :invalid_right_hand_rule_polygon, champ: nil) }
|
|
|
|
|
it { expect(geo_area.errors).to have_key(:geometry) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context.skip 'hourglass_polygon' do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :hourglass_polygon, champ: nil) }
|
|
|
|
|
it { expect(geo_area.errors).to have_key(:geometry) }
|
2023-04-21 17:26:28 +02:00
|
|
|
|
end
|
2021-03-16 10:38:56 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2021-05-13 12:46:42 +02:00
|
|
|
|
|
|
|
|
|
describe "cadastre properties" do
|
2021-10-19 18:13:44 +02:00
|
|
|
|
let(:geo_area) { build(:geo_area, :cadastre, champ: nil) }
|
|
|
|
|
let(:legacy_geo_area) { build(:geo_area, :legacy_cadastre, champ: nil) }
|
2021-05-13 12:46:42 +02:00
|
|
|
|
|
|
|
|
|
it "should be backward compatible" do
|
|
|
|
|
expect("#{geo_area.code_dep}#{geo_area.code_com}").to eq(geo_area.commune)
|
|
|
|
|
expect(geo_area.code_arr).to eq(geo_area.prefixe)
|
|
|
|
|
expect(geo_area.surface_parcelle).to eq(geo_area.surface)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "(legacy)" do
|
|
|
|
|
it "should be forward compatible" do
|
|
|
|
|
expect("#{legacy_geo_area.code_dep}#{legacy_geo_area.code_com}").to eq(legacy_geo_area.commune)
|
|
|
|
|
expect(legacy_geo_area.code_arr).to eq(legacy_geo_area.prefixe)
|
|
|
|
|
expect(legacy_geo_area.surface_parcelle).to eq(legacy_geo_area.surface)
|
|
|
|
|
expect(legacy_geo_area.cid).to eq(geo_area.cid)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-05-26 12:22:35 +02:00
|
|
|
|
|
|
|
|
|
describe 'description' do
|
|
|
|
|
context 'when properties is nil' do
|
2021-10-19 18:13:44 +02:00
|
|
|
|
let(:geo_area) { build(:geo_area, properties: nil, champ: nil) }
|
2021-05-26 12:22:35 +02:00
|
|
|
|
|
|
|
|
|
it { expect(geo_area.description).to be_nil }
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-08-31 13:09:00 +02:00
|
|
|
|
|
|
|
|
|
describe "#label" do
|
|
|
|
|
context "when geo is a line" do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :selection_utilisateur, :line_string, champ: nil) }
|
|
|
|
|
it "should return the label" do
|
|
|
|
|
expect(geo_area.label).to eq("Une ligne longue de 21,2 m")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should return unknown length" do
|
|
|
|
|
geo_area.geometry["coordinates"] = []
|
|
|
|
|
expect(geo_area.label).to eq("Une ligne de longueur inconnue")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when geo is a polygon" do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :selection_utilisateur, :polygon, champ: nil) }
|
|
|
|
|
it "should return the label" do
|
|
|
|
|
expect(geo_area.label).to eq("Une aire de surface 103,6 m²")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should return unknown surface" do
|
|
|
|
|
geo_area.geometry["coordinates"] = []
|
|
|
|
|
expect(geo_area.label).to eq("Une aire de surface inconnue")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-12 14:56:41 +02:00
|
|
|
|
context "when geo is a point" do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :selection_utilisateur, :point, champ: nil) }
|
|
|
|
|
it "should return the label" do
|
|
|
|
|
expect(geo_area.label).to eq("Un point situé à 46°32'19\"N 2°25'42\"E")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when geo is a point with elevation" do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :selection_utilisateur, :point_with_z, champ: nil) }
|
|
|
|
|
it "should return the label" do
|
|
|
|
|
expect(geo_area.label).to eq("Un point situé à 46°32'19\"N 2°25'42\"E")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-31 13:09:00 +02:00
|
|
|
|
context "when geo is a cadastre parcelle" do
|
|
|
|
|
let(:geo_area) { build(:geo_area, :selection_utilisateur, :cadastre, champ: nil) }
|
|
|
|
|
it "should return the label" do
|
2022-09-16 15:50:50 +02:00
|
|
|
|
expect(geo_area.label).to eq("Parcelle n° 42 - Feuille 000 A11 - 123 m² – commune 75127")
|
2022-08-31 13:09:00 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-04-15 15:43:38 +02:00
|
|
|
|
end
|