Merge pull request #5647 from betagouv/dev

2020-09-29-01
This commit is contained in:
Keirua 2020-09-29 14:28:59 +02:00 committed by GitHub
commit 05391be93a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 135 additions and 126 deletions

View file

@ -289,7 +289,7 @@ Layout/SpaceInsideReferenceBrackets:
Layout/SpaceInsideStringInterpolation: Layout/SpaceInsideStringInterpolation:
Enabled: true Enabled: true
Layout/Tab: Layout/IndentationStyle:
Enabled: true Enabled: true
Layout/TrailingEmptyLines: Layout/TrailingEmptyLines:
@ -506,7 +506,7 @@ Lint/UselessAssignment:
Exclude: Exclude:
- "spec/**/*" - "spec/**/*"
Lint/UselessComparison: Lint/BinaryOperatorWithIdenticalOperands:
Enabled: true Enabled: true
Lint/UselessElseWithoutRescue: Lint/UselessElseWithoutRescue:
@ -1045,7 +1045,7 @@ Style/MethodCalledOnDoEndBlock:
Style/MethodDefParentheses: Style/MethodDefParentheses:
Enabled: true Enabled: true
Style/MethodMissingSuper: Lint/MissingSuper:
Enabled: false Enabled: false
Style/MinMax: Style/MinMax:
@ -1315,3 +1315,34 @@ Style/YodaCondition:
Style/ZeroLengthPredicate: Style/ZeroLengthPredicate:
Enabled: true Enabled: true
Rails/ActiveRecordCallbacksOrder:
Enabled: false
Rails/AfterCommitOverride:
Enabled: true
Rails/FindById:
Enabled: true
Rails/Inquiry:
Enabled: true
Rails/MailerName:
Enabled: true
Rails/MatchRoute:
Enabled: true
Rails/NegateInclude:
Enabled: false
Rails/Pluck:
Enabled: false
Rails/PluckInWhere:
Enabled: true
Rails/RenderInline:
Enabled: true
Rails/RenderPlainText:
Enabled: true
Rails/ShortI18n:
Enabled: true
Rails/SquishedSQLHeredocs:
Enabled: true
Rails/WhereExists:
Enabled: true
Rails/WhereNot:
Enabled: true

View file

@ -3,8 +3,8 @@ source 'https://rubygems.org'
gem 'aasm' gem 'aasm'
gem 'active_link_to' # Automatically set a class on active links gem 'active_link_to' # Automatically set a class on active links
gem 'active_model_serializers' gem 'active_model_serializers'
gem 'active_storage_validations'
gem 'activestorage-openstack' gem 'activestorage-openstack'
gem 'active_storage_validations'
gem 'administrate' gem 'administrate'
gem 'after_party' gem 'after_party'
gem 'anchored' gem 'anchored'
@ -31,13 +31,13 @@ gem 'flipper-active_record'
gem 'flipper-ui' gem 'flipper-ui'
gem 'font-awesome-rails' gem 'font-awesome-rails'
gem 'fugit' gem 'fugit'
gem 'geo_coord', require: "geo/coord"
gem 'geocoder' gem 'geocoder'
gem 'geo_coord', require: "geo/coord"
gem 'gon' gem 'gon'
gem 'graphql' gem 'graphql'
gem 'graphql-batch' gem 'graphql-batch'
gem 'graphql-rails_logger'
gem 'graphql_playground-rails' gem 'graphql_playground-rails'
gem 'graphql-rails_logger'
gem 'groupdate' gem 'groupdate'
gem 'haml-rails' gem 'haml-rails'
gem 'hashie' gem 'hashie'
@ -118,8 +118,8 @@ group :development, :test do
gem 'graphql-schema_comparator' gem 'graphql-schema_comparator'
gem 'mina', git: 'https://github.com/mina-deploy/mina.git', require: false # Deploy gem 'mina', git: 'https://github.com/mina-deploy/mina.git', require: false # Deploy
gem 'pry-byebug' gem 'pry-byebug'
gem 'rspec-rails'
gem 'rspec_junit_formatter', require: false gem 'rspec_junit_formatter', require: false
gem 'rspec-rails'
gem 'ruby-debug-ide', require: false gem 'ruby-debug-ide', require: false
gem 'simple_xlsx_reader' gem 'simple_xlsx_reader'
gem 'spring' # Spring speeds up development by keeping your application running in the background gem 'spring' # Spring speeds up development by keeping your application running in the background

View file

@ -127,7 +127,7 @@ GEM
bootstrap-wysihtml5-rails (0.3.3.8) bootstrap-wysihtml5-rails (0.3.3.8)
railties (>= 3.0) railties (>= 3.0)
brakeman (4.9.1) brakeman (4.9.1)
browser (4.2.0) browser (5.0.0)
builder (3.2.4) builder (3.2.4)
byebug (11.1.3) byebug (11.1.3)
capybara (3.33.0) capybara (3.33.0)
@ -265,7 +265,7 @@ GEM
et-orbi (~> 1.1, >= 1.1.8) et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.1) raabro (~> 1.1)
geo_coord (0.1.0) geo_coord (0.1.0)
geocoder (1.6.2) geocoder (1.6.3)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
gon (6.3.2) gon (6.3.2)
@ -344,7 +344,6 @@ GEM
iban-tools (1.1.0) iban-tools (1.1.0)
ice_nine (0.11.2) ice_nine (0.11.2)
ipaddress (0.8.3) ipaddress (0.8.3)
jaro_winkler (1.5.4)
jquery-rails (4.4.0) jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3) rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0) railties (>= 4.2.0)
@ -354,7 +353,7 @@ GEM
aes_key_wrap aes_key_wrap
bindata bindata
jsonapi-renderer (0.2.2) jsonapi-renderer (0.2.2)
jwt (2.2.1) jwt (2.2.2)
kaminari (1.2.1) kaminari (1.2.1)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1) kaminari-actionview (= 1.2.1)
@ -450,7 +449,7 @@ GEM
webfinger (>= 1.0.1) webfinger (>= 1.0.1)
orm_adapter (0.5.0) orm_adapter (0.5.0)
parallel (1.19.2) parallel (1.19.2)
parser (2.7.1.4) parser (2.7.1.5)
ast (~> 2.4.1) ast (~> 2.4.1)
pdf-core (0.7.0) pdf-core (0.7.0)
pg (1.2.3) pg (1.2.3)
@ -554,7 +553,7 @@ GEM
execjs execjs
railties (>= 3.2) railties (>= 3.2)
tilt tilt
regexp_parser (1.7.1) regexp_parser (1.8.0)
request_store (1.5.0) request_store (1.5.0)
rack (>= 1.4) rack (>= 1.4)
responders (3.0.1) responders (3.0.1)
@ -597,23 +596,28 @@ GEM
rspec-support (3.9.3) rspec-support (3.9.3)
rspec_junit_formatter (0.4.1) rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0) rspec-core (>= 2, < 4, != 2.12.0)
rubocop (0.81.0) rubocop (0.92.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.7.0.1) parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml rexml
rubocop-ast (>= 0.5.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0) unicode-display_width (>= 1.4.0, < 2.0)
rubocop-performance (1.5.2) rubocop-ast (0.7.0)
rubocop (>= 0.71.0) parser (>= 2.7.1.5)
rubocop-rails (2.5.2) strscan (>= 1.0.0)
activesupport rubocop-performance (1.8.1)
rubocop (>= 0.87.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.8.1)
activesupport (>= 4.2.0)
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 0.72.0) rubocop (>= 0.87.0)
rubocop-rails_config (0.10.0) rubocop-rails_config (0.12.6)
railties (>= 5.0) railties (>= 5.0)
rubocop (~> 0.80) rubocop (~> 0.82)
rubocop-performance (~> 1.3) rubocop-performance (~> 1.3)
rubocop-rails (~> 2.0) rubocop-rails (~> 2.0)
rubocop-rspec-focused (1.0.0) rubocop-rspec-focused (1.0.0)
@ -685,6 +689,7 @@ GEM
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
strscan (1.0.3)
swd (1.1.2) swd (1.1.2)
activesupport (>= 3) activesupport (>= 3)
attr_required (>= 0.0.5) attr_required (>= 0.0.5)

View file

@ -360,7 +360,7 @@ class StatsController < ApplicationController
if weekly_dossiers_count == 0 if weekly_dossiers_count == 0
result = 0 result = 0
else else
weekly_dossier_with_avis_count = weekly_dossiers.filter { |dossier| dossier.avis.present? }.count weekly_dossier_with_avis_count = weekly_dossiers.count { |dossier| dossier.avis.present? }
result = percentage(weekly_dossier_with_avis_count, weekly_dossiers_count) result = percentage(weekly_dossier_with_avis_count, weekly_dossiers_count)
end end

View file

@ -37,7 +37,7 @@ module ChampHelper
when GeoArea.sources.fetch(:cadastre) when GeoArea.sources.fetch(:cadastre)
capture do capture do
concat "Parcelle n° #{geo_area.numero} - Feuille #{geo_area.code_arr} #{geo_area.section} #{geo_area.feuille} - #{geo_area.surface_parcelle.round} m" concat "Parcelle n° #{geo_area.numero} - Feuille #{geo_area.code_arr} #{geo_area.section} #{geo_area.feuille} - #{geo_area.surface_parcelle.round} m"
concat content_tag(:sup, "2") concat tag.sup("2")
end end
when GeoArea.sources.fetch(:quartier_prioritaire) when GeoArea.sources.fetch(:quartier_prioritaire)
"#{geo_area.commune} : #{geo_area.nom}" "#{geo_area.commune} : #{geo_area.nom}"
@ -48,7 +48,7 @@ module ChampHelper
if geo_area.area.present? if geo_area.area.present?
capture do capture do
concat "Une aire de surface #{geo_area.area} m" concat "Une aire de surface #{geo_area.area} m"
concat content_tag(:sup, "2") concat tag.sup("2")
end end
else else
"Une aire de surface inconnue" "Une aire de surface inconnue"

View file

@ -75,7 +75,7 @@ module DossierHelper
def status_badge(state) def status_badge(state)
status_text = dossier_display_state(state, lower: true) status_text = dossier_display_state(state, lower: true)
status_class = state.tr('_', '-') status_class = state.tr('_', '-')
content_tag(:span, status_text, class: "label #{status_class} ") tag.span(status_text, class: "label #{status_class} ")
end end
def deletion_reason_badge(reason) def deletion_reason_badge(reason)
@ -87,7 +87,7 @@ module DossierHelper
status_class = 'unknown' status_class = 'unknown'
end end
content_tag(:span, status_text, class: "label #{status_class} ") tag.span(status_text, class: "label #{status_class} ")
end end
def demandeur_dossier(dossier) def demandeur_dossier(dossier)

View file

@ -8,7 +8,7 @@ module ProcedureHelper
end end
def procedure_libelle(procedure) def procedure_libelle(procedure)
parts = procedure.brouillon? ? [content_tag(:span, 'démarche en test', class: 'badge')] : [] parts = procedure.brouillon? ? [tag.span('démarche en test', class: 'badge')] : []
parts << procedure.libelle parts << procedure.libelle
safe_join(parts, ' ') safe_join(parts, ' ')
end end

View file

@ -3,6 +3,10 @@ class ApiEntreprise::Job < ApplicationJob
DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5 DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5
# If by the time the job runs the Etablissement has been deleted
# (it can happen through EtablissementUpdateJob for instance), ignore the job
discard_on ActiveRecord::RecordNotFound
rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception| rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
error(self, exception) error(self, exception)
end end

View file

@ -9,7 +9,7 @@ class ApplicationMailer < ActionMailer::Base
end end
rescue_from Net::SMTPServerBusy do |error| rescue_from Net::SMTPServerBusy do |error|
if error.message =~ /unexpected recipients/ if /unexpected recipients/.match?(error.message)
message.perform_deliveries = false message.perform_deliveries = false
end end
end end

View file

@ -10,7 +10,7 @@ class DeviseUserMailer < Devise::Mailer
end end
rescue_from Net::SMTPServerBusy do |error| rescue_from Net::SMTPServerBusy do |error|
if error.message =~ /unexpected recipients/ if /unexpected recipients/.match?(error.message)
message.perform_deliveries = false message.perform_deliveries = false
end end
end end

View file

@ -17,30 +17,9 @@
class Champs::PieceJustificativeChamp < Champ class Champs::PieceJustificativeChamp < Champ
MAX_SIZE = 200.megabytes MAX_SIZE = 200.megabytes
ACCEPTED_FORMATS = [ validates :piece_justificative_file,
"text/plain", size: { less_than: MAX_SIZE },
"application/pdf", if: -> { !type_de_champ.skip_pj_validation }
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.presentation",
"application/vnd.oasis.opendocument.spreadsheet",
"image/png",
"image/jpeg"
]
# TODO: once we're running on Rails 6, re-enable this validation.
# See https://github.com/betagouv/demarches-simplifiees.fr/issues/4926
#
# validates :piece_justificative_file,
# content_type: ACCEPTED_FORMATS,
# size: { less_than: MAX_SIZE }
before_save :update_skip_pj_validation
def main_value_name def main_value_name
:piece_justificative_file :piece_justificative_file
@ -63,8 +42,4 @@ class Champs::PieceJustificativeChamp < Champ
piece_justificative_file.service_url piece_justificative_file.service_url
end end
end end
def update_skip_pj_validation
type_de_champ.update(skip_pj_validation: true)
end
end end

View file

@ -8,7 +8,7 @@
# updated_at :datetime not null # updated_at :datetime not null
# #
class Export < ApplicationRecord class Export < ApplicationRecord
MAX_DUREE_CONSERVATION_EXPORT = 15.minutes MAX_DUREE_CONSERVATION_EXPORT = 1.hour
enum format: { enum format: {
csv: 'csv', csv: 'csv',
@ -24,7 +24,7 @@ class Export < ApplicationRecord
scope :stale, -> { where('updated_at < ?', (Time.zone.now - MAX_DUREE_CONSERVATION_EXPORT)) } scope :stale, -> { where('updated_at < ?', (Time.zone.now - MAX_DUREE_CONSERVATION_EXPORT)) }
after_save_commit :compute_async after_create_commit :compute_async
def compute_async def compute_async
ExportJob.perform_later(self) ExportJob.perform_later(self)

View file

@ -295,8 +295,7 @@ class ProcedurePresentation < ApplicationRecord
def valid_columns_for_table(table) def valid_columns_for_table(table)
@column_whitelist ||= fields @column_whitelist ||= fields
.group_by { |field| field['table'] } .group_by { |field| field['table'] }
.map { |table, fields| [table, Set.new(fields.pluck('column'))] } .transform_values { |fields| Set.new(fields.pluck('column')) }
.to_h
@column_whitelist[table] || [] @column_whitelist[table] || []
end end

View file

@ -27,7 +27,7 @@ class AdministrateurUsageStatisticsService
nb_dossiers_roi = nb_dossiers_by_procedure_id.reject { |procedure_id, _count| is_brouillon(procedure_id) }.map { |_procedure_id, count| count }.sum nb_dossiers_roi = nb_dossiers_by_procedure_id.reject { |procedure_id, _count| is_brouillon(procedure_id) }.map { |_procedure_id, count| count }.sum
result = { result = {
ds_sign_in_count: administrateur.user.sign_in_count, ds_sign_in_count: administrateur&.user&.sign_in_count,
ds_created_at: administrateur.created_at, ds_created_at: administrateur.created_at,
ds_active: administrateur.user.active?, ds_active: administrateur.user.active?,
ds_id: administrateur.id, ds_id: administrateur.id,
@ -62,11 +62,11 @@ class AdministrateurUsageStatisticsService
admin_roi_high: nb_dossiers_roi * 17 admin_roi_high: nb_dossiers_roi * 17
} }
if administrateur.user.current_sign_in_at.present? if administrateur&.user&.current_sign_in_at.present?
result[:ds_current_sign_in_at] = administrateur.user.current_sign_in_at result[:ds_current_sign_in_at] = administrateur.user.current_sign_in_at
end end
if administrateur.user.last_sign_in_at.present? if administrateur&.user&.last_sign_in_at.present?
result[:ds_last_sign_in_at] = administrateur.user.last_sign_in_at result[:ds_last_sign_in_at] = administrateur.user.last_sign_in_at
end end
@ -81,16 +81,12 @@ class AdministrateurUsageStatisticsService
with_default( with_default(
0, 0,
nb_dossiers_by_administrateur_id_and_procedure_id_and_synthetic_state[administrateur_id] nb_dossiers_by_administrateur_id_and_procedure_id_and_synthetic_state[administrateur_id]
.map do |procedure_id, nb_dossiers_by_synthetic_state| .transform_values do |nb_dossiers_by_synthetic_state|
[
procedure_id,
nb_dossiers_by_synthetic_state nb_dossiers_by_synthetic_state
.reject { |synthetic_state, _count| ['brouillon', 'archive'].include?(synthetic_state) } .reject { |synthetic_state, _count| ['brouillon', 'archive'].include?(synthetic_state) }
.map { |_synthetic_state, count| count } .map { |_synthetic_state, count| count }
.sum .sum
]
end end
.to_h
) )
end end
@ -105,8 +101,7 @@ class AdministrateurUsageStatisticsService
.reject { |procedure_id, _nb_dossiers_by_synthetic_state| is_brouillon(procedure_id) } .reject { |procedure_id, _nb_dossiers_by_synthetic_state| is_brouillon(procedure_id) }
.flat_map { |_procedure_id, nb_dossiers_by_synthetic_state| nb_dossiers_by_synthetic_state.to_a } .flat_map { |_procedure_id, nb_dossiers_by_synthetic_state| nb_dossiers_by_synthetic_state.to_a }
.group_by { |synthetic_state, _count| synthetic_state } .group_by { |synthetic_state, _count| synthetic_state }
.map { |synthetic_state, synthetic_states_and_counts| [synthetic_state, synthetic_states_and_counts.map { |_synthetic_state, count| count }.sum] } .transform_values { |synthetic_states_and_counts| synthetic_states_and_counts.map { |_synthetic_state, count| count }.sum }
.to_h
) )
end end

View file

@ -73,7 +73,11 @@ class ProcedureExportService
{ instances: table.last, sheet_name: table.first } { instances: table.last, sheet_name: table.first }
end.merge(DEFAULT_STYLES) end.merge(DEFAULT_STYLES)
options[:sheet_name] = options[:sheet_name].truncate(30) # transliterate: convert to ASCII characteres
# to ensure truncate respects 30 bytes
options[:sheet_name] = I18n.transliterate(options[:sheet_name], '')
.truncate(30, omission: '')
options options
end end
end end

View file

@ -1,5 +1,5 @@
# This file is used by Rack-based servers to start the application. # This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__) require ::File.expand_path('config/environment', __dir__)
run Rails.application run Rails.application

View file

@ -2,3 +2,4 @@ fr:
errors: errors:
messages: messages:
content_type_invalid: nest pas dun type accepté content_type_invalid: nest pas dun type accepté
file_size_out_of_range: "est trop lourde, elle doit faire au plus 200 Mo."

View file

@ -213,8 +213,7 @@ feature 'The routing', js: true do
def register_instructeur_and_log_in(email) def register_instructeur_and_log_in(email)
confirmation_email = emails_sent_to(email) confirmation_email = emails_sent_to(email)
.filter { |m| m.subject == 'Activez votre compte instructeur' } .find { |m| m.subject == 'Activez votre compte instructeur' }
.first
token_params = confirmation_email.body.match(/token=[^"]+/) token_params = confirmation_email.body.match(/token=[^"]+/)
visit "users/activate?#{token_params}" visit "users/activate?#{token_params}"

View file

@ -176,6 +176,13 @@ feature 'The user' do
create(:procedure, :published, :for_individual, types_de_champ: tdcs) create(:procedure, :published, :for_individual, types_de_champ: tdcs)
end end
let(:old_procedure_with_disabled_pj_validation) do
tdcs = [
create(:type_de_champ_piece_justificative, mandatory: true, libelle: 'Pièce justificative 1', order_place: 1, skip_pj_validation: true)
]
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
end
scenario 'add an attachment', js: true do scenario 'add an attachment', js: true do
log_in(user, procedure_with_pjs) log_in(user, procedure_with_pjs)
fill_individual fill_individual
@ -200,25 +207,14 @@ feature 'The user' do
expect(page).to have_text('RIB.pdf') expect(page).to have_text('RIB.pdf')
end end
# TODO: once we're running on Rails 6, re-enable the validator on PieceJustificativeChamp, scenario 'add an invalid attachment on an old procedure where pj validation is disabled', js: true do
# and unmark this spec as pending. log_in(user, old_procedure_with_disabled_pj_validation)
#
# See piece_justificative_champ.rb
# See https://github.com/betagouv/demarches-simplifiees.fr/issues/4926
scenario 'add an invalid attachment', js: true, pending: true do
log_in(user, procedure_with_pjs)
fill_individual fill_individual
# Test invalid file type # Test invalid file type
attach_file('Pièce justificative 1', Rails.root + 'spec/fixtures/files/invalid_file_format.json') attach_file('Pièce justificative 1', Rails.root + 'spec/fixtures/files/invalid_file_format.json')
expect(page).to have_text('La pièce justificative nest pas dun type accepté')
expect(page).to have_no_button('Ré-essayer', visible: true)
# Replace the file by another with a valid type
attach_file('Pièce justificative 1', Rails.root + 'spec/fixtures/files/piece_justificative_0.pdf')
expect(page).to have_no_text('La pièce justificative nest pas dun type accepté') expect(page).to have_no_text('La pièce justificative nest pas dun type accepté')
expect(page).to have_text('analyse antivirus en cours') expect(page).to have_text('analyse antivirus en cours', count: 1)
expect(page).to have_text('piece_justificative_0.pdf')
end end
scenario 'retry on transcient upload error', js: true do scenario 'retry on transcient upload error', js: true do

View file

@ -18,4 +18,14 @@ RSpec.describe ApiEntreprise::AssociationJob, type: :job do
subject subject
expect(Etablissement.find(etablissement.id).association_rna).to eq('W595001988') expect(Etablissement.find(etablissement.id).association_rna).to eq('W595001988')
end end
context "when the etablissement has been deleted" do
before do
allow_any_instance_of(Etablissement).to receive(:find) { raise ActiveRecord::RecordNotFound }
end
it "ignores the error" do
expect { subject }.not_to raise_error
end
end
end end

View file

@ -151,13 +151,11 @@ describe AttestationTemplate, type: :model do
context 'and their value in the dossier are not nil' do context 'and their value in the dossier are not nil' do
before do before do
dossier.champs dossier.champs
.filter { |champ| champ.libelle == 'libelleA' } .find { |champ| champ.libelle == 'libelleA' }
.first
.update(value: 'libelle1') .update(value: 'libelle1')
dossier.champs dossier.champs
.filter { |champ| champ.libelle == 'libelleB' } .find { |champ| champ.libelle == 'libelleB' }
.first
.update(value: 'libelle2') .update(value: 'libelle2')
end end

View file

@ -3,7 +3,7 @@ require 'active_storage_validations/matchers'
describe Champs::PieceJustificativeChamp do describe Champs::PieceJustificativeChamp do
include ActiveStorageValidations::Matchers include ActiveStorageValidations::Matchers
describe "update_skip_validation" do describe "skip_validation is not set anymore" do
subject { champ_pj.type_de_champ.skip_pj_validation } subject { champ_pj.type_de_champ.skip_pj_validation }
context 'before_save' do context 'before_save' do
@ -12,19 +12,24 @@ describe Champs::PieceJustificativeChamp do
end end
context 'after_save' do context 'after_save' do
let(:champ_pj) { create (:champ_piece_justificative) } let(:champ_pj) { create (:champ_piece_justificative) }
it { is_expected.to be_truthy } it { is_expected.to be_falsy }
end end
end end
# TODO: once we're running on Rails 6, re-enable the PieceJustificativeChamp validator, describe "validations" do
# and re-enable this spec. let(:champ_pj) { create(:champ_piece_justificative) }
# subject { champ_pj }
# See https://github.com/betagouv/demarches-simplifiees.fr/issues/4926
describe "validations", pending: true do
subject(:champ_pj) { build(:champ_piece_justificative) }
context "by default" do
it { is_expected.to validate_size_of(:piece_justificative_file).less_than(Champs::PieceJustificativeChamp::MAX_SIZE) } it { is_expected.to validate_size_of(:piece_justificative_file).less_than(Champs::PieceJustificativeChamp::MAX_SIZE) }
it { is_expected.to validate_content_type_of(:piece_justificative_file).allowing(Champs::PieceJustificativeChamp::ACCEPTED_FORMATS) } it { expect(champ_pj.type_de_champ.skip_pj_validation).to be_falsy }
end
context "when validation is disabled" do
before { champ_pj.type_de_champ.update(skip_pj_validation: true) }
it { is_expected.not_to validate_size_of(:piece_justificative_file).less_than(Champs::PieceJustificativeChamp::MAX_SIZE) }
end
end end
describe "#for_export" do describe "#for_export" do

View file

@ -123,13 +123,11 @@ describe TagsSubstitutionConcern, type: :model do
context 'and their value in the dossier are not nil' do context 'and their value in the dossier are not nil' do
before do before do
dossier.champs dossier.champs
.filter { |champ| champ.libelle == 'libelleA' } .find { |champ| champ.libelle == 'libelleA' }
.first
.update(value: 'libelle1') .update(value: 'libelle1')
dossier.champs dossier.champs
.filter { |champ| champ.libelle == 'libelleB' } .find { |champ| champ.libelle == 'libelleB' }
.first
.update(value: 'libelle2') .update(value: 'libelle2')
end end
@ -151,8 +149,7 @@ describe TagsSubstitutionConcern, type: :model do
context 'and their value in the dossier are not nil' do context 'and their value in the dossier are not nil' do
before do before do
dossier.champs dossier.champs
.filter { |champ| champ.libelle == "Intitulé de l'‘«\"évènement\"»’" } .find { |champ| champ.libelle == "Intitulé de l'‘«\"évènement\"»’" }
.first
.update(value: 'ceci est mon évènement') .update(value: 'ceci est mon évènement')
end end
@ -302,13 +299,11 @@ describe TagsSubstitutionConcern, type: :model do
context 'and its value in the dossier are not nil' do context 'and its value in the dossier are not nil' do
before do before do
dossier.champs dossier.champs
.filter { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:date) } .find { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:date) }
.first
.update(value: '2017-04-15') .update(value: '2017-04-15')
dossier.champs dossier.champs
.filter { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } .find { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) }
.first
.update(value: '2017-09-13 09:00') .update(value: '2017-09-13 09:00')
end end

View file

@ -4,16 +4,8 @@ describe ChampSerializer do
let(:serializable_object) { champ } let(:serializable_object) { champ }
context 'when type champ is piece justificative' do context 'when type champ is piece justificative' do
include Rails.application.routes.url_helpers
let(:champ) { create(:champ_piece_justificative) } let(:champ) { create(:champ_piece_justificative) }
before do
champ.piece_justificative_file.attach({ filename: __FILE__, io: File.open(__FILE__) })
champ.piece_justificative_file.blob.send(:enqueue_virus_scan)
end
after { champ.piece_justificative_file.purge }
it { expect(subject[:value]).to match('/rails/active_storage/disk/') } it { expect(subject[:value]).to match('/rails/active_storage/disk/') }
end end

View file

@ -356,10 +356,10 @@ describe ProcedureExportService do
end end
end end
context 'with long libelle' do context 'with long libelle composed of utf8 characteres' do
before do before do
procedure.types_de_champ.each do |c| procedure.types_de_champ.each do |c|
c.update!(libelle: "#{c.id} - Quam rem nam maiores numquam dolorem nesciunt. Cum et possimus et aut. Fugit voluptas qui qui.") c.update!(libelle: "#{c.id} - éééé ééé ééé ééééééé ééééééé ééééééé éééééééé. ééé éé éééééééé éé ééé. ééééé éééééééé ééé ééé.")
end end
champ_repetition.champs.each do |c| champ_repetition.champs.each do |c|
c.type_de_champ.update!(libelle: "#{c.id} - Quam rem nam maiores numquam dolorem nesciunt. Cum et possimus et aut. Fugit voluptas qui qui.") c.type_de_champ.update!(libelle: "#{c.id} - Quam rem nam maiores numquam dolorem nesciunt. Cum et possimus et aut. Fugit voluptas qui qui.")