Do not save error json in database
This commit is contained in:
parent
49c872fb97
commit
c99ef811b6
2 changed files with 19 additions and 6 deletions
|
@ -30,6 +30,8 @@ class Champs::CarteController < ApplicationController
|
||||||
|
|
||||||
if geo_json.first == ["error", "TooManyPolygons"]
|
if geo_json.first == ["error", "TooManyPolygons"]
|
||||||
@error = true
|
@error = true
|
||||||
|
@champ.value = nil
|
||||||
|
@champ.geo_areas = []
|
||||||
elsif geo_json.present?
|
elsif geo_json.present?
|
||||||
if @champ.cadastres?
|
if @champ.cadastres?
|
||||||
cadastres = ModuleApiCartoService.generate_cadastre(geo_json)
|
cadastres = ModuleApiCartoService.generate_cadastre(geo_json)
|
||||||
|
@ -54,13 +56,13 @@ class Champs::CarteController < ApplicationController
|
||||||
parcelle_agricole
|
parcelle_agricole
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
@champ.geo_areas = geo_areas.map do |geo_area|
|
@champ.geo_areas = geo_areas.map do |geo_area|
|
||||||
GeoArea.new(geo_area)
|
GeoArea.new(geo_area)
|
||||||
end
|
end
|
||||||
|
|
||||||
@champ.value = geo_json.to_json
|
@champ.value = geo_json.to_json
|
||||||
|
end
|
||||||
|
|
||||||
if @champ.persisted?
|
if @champ.persisted?
|
||||||
@champ.save
|
@champ.save
|
||||||
|
|
|
@ -15,10 +15,11 @@ describe Champs::CarteController, type: :controller do
|
||||||
champ_id: champ.id
|
champ_id: champ.id
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
let(:geojson) { [] }
|
||||||
let(:champ) do
|
let(:champ) do
|
||||||
create(:type_de_champ_carte, options: {
|
create(:type_de_champ_carte, options: {
|
||||||
quartiers_prioritaires: true
|
quartiers_prioritaires: true
|
||||||
}).champ.create(dossier: dossier)
|
}).champ.create(dossier: dossier, value: geojson.to_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #show' do
|
describe 'POST #show' do
|
||||||
|
@ -46,5 +47,15 @@ describe Champs::CarteController, type: :controller do
|
||||||
it { expect(response.body).to include('MultiPolygon') }
|
it { expect(response.body).to include('MultiPolygon') }
|
||||||
it { expect(response.body).to include('[2.38715792094576,48.8723062632126]') }
|
it { expect(response.body).to include('[2.38715792094576,48.8723062632126]') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when error' do
|
||||||
|
let(:geojson) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]] }
|
||||||
|
let(:selection) { { error: "TooManyPolygons" } }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(champ.reload.value).to eq(nil)
|
||||||
|
expect(champ.reload.geo_areas).to eq([])
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue