commit
235dfc0ab1
4 changed files with 51 additions and 3 deletions
|
@ -30,4 +30,11 @@ module ApplicationHelper
|
|||
root_path
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_safe_json(json)
|
||||
JSON.parse(json).to_json
|
||||
rescue Exception => e
|
||||
Raven.capture_exception(e)
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,6 @@
|
|||
|
||||
:javascript
|
||||
var getPositionUrl = "#{position_gestionnaire_dossier_path(dossier.procedure, dossier)}";
|
||||
var dossierJsonLatLngs = #{dossier.json_latlngs};
|
||||
var dossierCadastres = #{dossier.cadastres.to_json};
|
||||
var dossierQuartiersPrioritaires = #{dossier.quartier_prioritaires.to_json};
|
||||
var dossierJsonLatLngs = #{raw(ensure_safe_json(dossier.json_latlngs))};
|
||||
var dossierCadastres = #{raw(ensure_safe_json(dossier.cadastres.to_json))};
|
||||
var dossierQuartiersPrioritaires = #{raw(ensure_safe_json(dossier.quartier_prioritaires.to_json))};
|
||||
|
|
|
@ -17,4 +17,18 @@ describe ApplicationHelper do
|
|||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ensure_safe_json" do
|
||||
subject { ensure_safe_json(json) }
|
||||
|
||||
context "with a dirty json" do
|
||||
let(:json) { "alert('haha');" }
|
||||
it { is_expected.to eq({}) }
|
||||
end
|
||||
|
||||
context 'with a correct json' do
|
||||
let(:json) { '[[{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}], [{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}]]' }
|
||||
it { is_expected.to eq("[[{\"lat\":2.0,\"lng\":102.0},{\"lat\":3.0,\"lng\":103.0},{\"lat\":2.0,\"lng\":102.0}],[{\"lat\":2.0,\"lng\":102.0},{\"lat\":3.0,\"lng\":103.0},{\"lat\":2.0,\"lng\":102.0}]]") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
27
spec/views/new_gestionnaire/dossiers/_map_spec.rb
Normal file
27
spec/views/new_gestionnaire/dossiers/_map_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'new_gestionnaire/dossiers/_map.html.haml', type: :view do
|
||||
subject do
|
||||
render(partial: 'new_gestionnaire/dossiers/map.html.haml', locals: { dossier: dossier })
|
||||
end
|
||||
|
||||
describe "javascript variables printing" do
|
||||
let(:dossier) { create(:dossier, :with_entreprise, json_latlngs: json_latlngs) }
|
||||
|
||||
context 'with a correct json' do
|
||||
let(:json_latlngs) { "[[{\"lat\":50.659255436656736,\"lng\":3.080635070800781},{\"lat\":50.659255436656736,\"lng\":3.079690933227539},{\"lat\":50.659962770886516,\"lng\":3.0800342559814453},{\"lat\":50.659962770886516,\"lng\":3.0811500549316406},{\"lat\":50.659255436656736,\"lng\":3.080635070800781}]]" }
|
||||
|
||||
before { subject }
|
||||
|
||||
it { expect(rendered).to have_content('var dossierJsonLatLngs = [[{"lat":50.659255436656736,"lng":3.080635070800781},{"lat":50.659255436656736,"lng":3.079690933227539},{"lat":50.659962770886516,"lng":3.0800342559814453},{"lat":50.659962770886516,"lng":3.0811500549316406},{"lat":50.659255436656736,"lng":3.080635070800781}]];') }
|
||||
end
|
||||
|
||||
context 'without a correct json' do
|
||||
let(:json_latlngs) { "dossier" }
|
||||
|
||||
before { subject }
|
||||
|
||||
it { expect(rendered).to have_content('var dossierJsonLatLngs = {};') }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue