2018-10-22 15:00:52 +02:00
|
|
|
describe Champs::CarteController, type: :controller do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:procedure) { create(:procedure, :published) }
|
|
|
|
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
dossier: {
|
|
|
|
champs_attributes: {
|
2018-11-27 12:15:36 +01:00
|
|
|
'1' => { value: value }
|
2018-10-22 15:00:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
position: '1',
|
|
|
|
champ_id: champ.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:champ) do
|
|
|
|
create(:type_de_champ_carte, options: {
|
2020-04-09 19:08:18 +02:00
|
|
|
cadastres: true
|
2020-04-09 17:32:20 +02:00
|
|
|
}).champ.create(dossier: dossier)
|
2018-10-22 15:00:52 +02:00
|
|
|
end
|
2020-05-14 11:21:33 +02:00
|
|
|
|
2020-05-05 15:09:29 +02:00
|
|
|
describe 'features' do
|
|
|
|
let(:feature) { attributes_for(:geo_area, :polygon) }
|
|
|
|
let(:geo_area) { create(:geo_area, :selection_utilisateur, :polygon, champ: champ) }
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
champ_id: champ.id,
|
2021-05-06 18:50:06 +02:00
|
|
|
feature: feature,
|
|
|
|
source: GeoArea.sources.fetch(:selection_utilisateur)
|
2020-05-05 15:09:29 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
request.accept = "application/json"
|
|
|
|
request.content_type = "application/json"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
before do
|
|
|
|
post :create, params: params
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.status).to eq 201 }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH #update' do
|
|
|
|
before do
|
|
|
|
patch :update, params: params
|
|
|
|
end
|
|
|
|
|
2020-06-04 11:32:59 +02:00
|
|
|
context 'update geometry' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
champ_id: champ.id,
|
|
|
|
id: geo_area.id,
|
|
|
|
feature: feature
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.status).to eq 204 }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'update description' do
|
|
|
|
let(:feature) do
|
|
|
|
{
|
|
|
|
properties: {
|
|
|
|
description: 'un point'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
champ_id: champ.id,
|
|
|
|
id: geo_area.id,
|
|
|
|
feature: feature
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it {
|
|
|
|
expect(response.status).to eq 204
|
|
|
|
expect(geo_area.reload.description).to eq('un point')
|
|
|
|
}
|
|
|
|
end
|
2020-05-05 15:09:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE #destroy' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
champ_id: champ.id,
|
|
|
|
id: geo_area.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
delete :destroy, params: params
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.status).to eq 204 }
|
|
|
|
end
|
|
|
|
|
2021-05-06 18:50:06 +02:00
|
|
|
describe 'GET #index' do
|
2020-05-07 12:06:42 +02:00
|
|
|
render_views
|
|
|
|
|
|
|
|
let(:params) do
|
2021-05-06 18:50:06 +02:00
|
|
|
{ champ_id: champ.id }
|
2020-05-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2020-05-05 15:09:29 +02:00
|
|
|
before do
|
|
|
|
request.accept = "application/javascript"
|
|
|
|
request.content_type = "application/javascript"
|
2021-05-06 18:50:06 +02:00
|
|
|
get :index, params: params
|
2020-05-05 15:09:29 +02:00
|
|
|
end
|
|
|
|
|
2021-05-06 18:50:06 +02:00
|
|
|
context "update list" do
|
2020-05-05 15:09:29 +02:00
|
|
|
it {
|
2021-05-06 18:50:06 +02:00
|
|
|
expect(response.body).not_to include("DS.fire('map:feature:focus'")
|
2020-05-05 15:09:29 +02:00
|
|
|
expect(response.status).to eq 200
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-05-06 18:50:06 +02:00
|
|
|
context "update list and focus" do
|
2020-05-05 15:09:29 +02:00
|
|
|
let(:params) do
|
|
|
|
{
|
2021-05-06 18:50:06 +02:00
|
|
|
champ_id: champ.id,
|
|
|
|
focus: true
|
2020-05-05 15:09:29 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it {
|
2021-05-06 18:50:06 +02:00
|
|
|
expect(response.body).to include("DS.fire('map:feature:focus'")
|
2020-05-05 15:09:29 +02:00
|
|
|
expect(response.status).to eq 200
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-10-22 15:00:52 +02:00
|
|
|
end
|