Merge pull request #3024 from betagouv/dev

MEP 2018-11-21-01
This commit is contained in:
Mathieu Magnin 2018-11-21 16:53:23 +01:00 committed by GitHub
commit 289daf04a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 61 additions and 14 deletions

View file

@ -14,7 +14,7 @@ class Champs::CarteController < ApplicationController
@champ = Champ
.joins(:dossier)
.where(dossiers: { user_id: logged_user_ids })
.find_by(id: params[:champ_id])
.find(params[:champ_id])
else
@champ = Champs::CarteChamp.new(type_de_champ: TypeDeChamp.new(
type_champ: TypeDeChamp.type_champs.fetch(:carte),
@ -30,6 +30,8 @@ class Champs::CarteController < ApplicationController
if geo_json.first == ["error", "TooManyPolygons"]
@error = true
@champ.value = nil
@champ.geo_areas = []
elsif geo_json.present?
if @champ.cadastres?
cadastres = ModuleApiCartoService.generate_cadastre(geo_json)
@ -54,13 +56,13 @@ class Champs::CarteController < ApplicationController
parcelle_agricole
end
end
end
@champ.geo_areas = geo_areas.map do |geo_area|
GeoArea.new(geo_area)
end
@champ.geo_areas = geo_areas.map do |geo_area|
GeoArea.new(geo_area)
end
@champ.value = geo_json.to_json
@champ.value = geo_json.to_json
end
if @champ.persisted?
@champ.save

View file

@ -17,5 +17,12 @@ module Manager
end
redirect_to manager_procedure_path(procedure)
end
def hide
procedure = Procedure.find(params[:id])
procedure.hide!
flash[:notice] = "La démarche a bien été supprimée, en cas d'erreur contactez un développeur."
redirect_to manager_procedure_path(procedure)
end
end
end

View file

@ -25,9 +25,9 @@ class PieceJustificativeUploader < BaseUploader
def filename
if original_filename.present? || model.content_secure_token
if Flipflop.remote_storage?
filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension.downcase}"
filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension&.downcase}"
else
filename = "#{model.class.to_s.underscore}.#{file.extension.downcase}"
filename = "#{model.class.to_s.underscore}.#{file.extension&.downcase}"
end
end
filename

View file

@ -1,7 +1,7 @@
%strong Sujet
%pre
%pre{ style: "white-space: pre-wrap;" }
= field.data.subject
%strong Corps
%pre
%pre{ style: "white-space: pre-wrap;" }
= field.data.body

View file

@ -40,6 +40,8 @@ as well as a link to its edit page.
<% if procedure.publiee? && procedure.dossiers.empty? %>
<%= link_to 'passer en brouillon', draft_manager_procedure_path(procedure), method: :post, class: 'button' %>
<% end %>
<%= link_to 'supprimer la démarche', hide_manager_procedure_path(procedure), method: :post, class: 'button', data: { confirm: "Confirmez-vous la suppression de la démarche ?" } %>
<div>
</header>

View file

@ -46,6 +46,13 @@ Rails.application.configure do
# Action Mailer settings
config.action_mailer.delivery_method = :letter_opener_web
# Configure default root URL for generating URLs to routes
config.action_mailer.default_url_options = {
host: 'localhost',
port: 3000
}
# Configure default root URL for email assets
config.action_mailer.asset_host = "http://" + ENV['APP_HOST']
Rails.application.routes.default_url_options = {
host: 'localhost',

View file

@ -81,10 +81,13 @@ Rails.application.configure do
config.action_mailer.delivery_method = :mailjet
end
# Configure default root URL for generating URLs to routes
config.action_mailer.default_url_options = {
protocol: :https,
host: ENV['APP_HOST']
}
# Configure default root URL for email assets
config.action_mailer.asset_host = "https://" + ENV['APP_HOST']
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).

View file

@ -9,6 +9,7 @@ Rails.application.routes.draw do
resources :procedures, only: [:index, :show] do
post 'whitelist', on: :member
post 'draft', on: :member
post 'hide', on: :member
end
resources :dossiers, only: [:index, :show] do

View file

@ -1,5 +1,5 @@
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-agent: *
# Disallow: /
User-agent: *
Disallow: /commencer*

View file

@ -15,10 +15,11 @@ describe Champs::CarteController, type: :controller do
champ_id: champ.id
}
end
let(:geojson) { [] }
let(:champ) do
create(:type_de_champ_carte, options: {
quartiers_prioritaires: true
}).champ.create(dossier: dossier)
}).champ.create(dossier: dossier, value: geojson.to_json)
end
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('[2.38715792094576,48.8723062632126]') }
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

View file

@ -9,7 +9,7 @@ RSpec.describe DossierMailer, type: :mailer do
subject { described_class.notify_new_draft(dossier) }
it { expect(subject.subject).to include("brouillon") }
it { expect(subject.subject).to include(dossier.id.to_s) }
it { expect(subject.subject).to include(dossier.procedure.libelle) }
it { expect(subject.body).to include(dossier.procedure.libelle) }
it { expect(subject.body).to include(dossier_url(dossier)) }
end

View file

@ -0,0 +1,14 @@
require 'spec_helper'
describe PieceJustificativeUploader do
let(:pj) { create(:piece_justificative, :rib) }
it { expect(pj.content.filename).to eq 'piece_justificative.pdf' }
context 'when extension is nil' do
it do
expect(pj.content.file).to receive(:extension).and_return(nil)
expect(pj.content.filename).to eq 'piece_justificative.'
end
end
end