Merge pull request #5984 from tchak/tests-for-geojson-validation

Ajout de tests automatisés pour la validation des polygones GeoJSON (#5984)
This commit is contained in:
Pierre de La Morinerie 2021-03-16 12:34:25 +01:00 committed by GitHub
commit 729167b954
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View file

@ -57,6 +57,22 @@ FactoryBot.define do
end end
end end
trait :invalid_right_hand_rule_polygon do
geometry do
{
"type": "Polygon",
"coordinates": [
[
[1.9116157293319704, 49.758172033960115],
[1.9116157293319704, 49.758172033960115],
[1.91162645816803, 49.75818243044436],
[1.9116157293319704, 49.758172033960115]
]
]
}
end
end
trait :polygon_with_extra_coordinate do trait :polygon_with_extra_coordinate do
geometry do geometry do
{ {

View file

@ -52,4 +52,32 @@ RSpec.describe GeoArea, type: :model do
it { expect(geo_area.safe_geometry).to eq(polygon) } it { expect(geo_area.safe_geometry).to eq(polygon) }
end end
end end
describe '#valid?' do
let(:geo_area) { build(:geo_area, :polygon) }
context 'polygon' do
it { expect(geo_area.valid?).to be_truthy }
end
context 'hourglass_polygon' do
let(:geo_area) { build(:geo_area, :hourglass_polygon) }
it { expect(geo_area.valid?).to be_falsey }
end
context 'line_string' do
let(:geo_area) { build(:geo_area, :line_string) }
it { expect(geo_area.valid?).to be_truthy }
end
context 'point' do
let(:geo_area) { build(:geo_area, :point) }
it { expect(geo_area.valid?).to be_truthy }
end
context 'invalid_right_hand_rule_polygon' do
let(:geo_area) { build(:geo_area, :invalid_right_hand_rule_polygon) }
it { expect(geo_area.valid?).to be_falsey }
end
end
end end