Merge pull request #3186 from betagouv/remove-dead-code

Remove dead code
This commit is contained in:
gregoirenovel 2018-12-19 15:27:18 +01:00 committed by GitHub
commit 3977294613
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 2 additions and 317 deletions

View file

@ -439,19 +439,6 @@ $cta-panel-button-border-size: 2px;
}
}
.tour-de-france-banner {
padding-top: 15px;
padding-bottom: 15px;
background-color: $blue;
color: #FFFFFF;
text-align: center;
a {
color: #FFFFFF;
text-decoration: underline;
}
}
.half {
width: 45%;
float: left;

View file

@ -18,20 +18,4 @@ class ChampDecorator < Draper::Decorator
object.value
end
end
def date_for_input
if object.value.present?
if type_champ == TypeDeChamp.type_champs.fetch(:date)
object.value
elsif type_champ == TypeDeChamp.type_champs.fetch(:datetime) && object.value != ' 00:00'
Time.zone.strptime(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d")
end
end
end
def description_with_links
if description
description.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>')
end
end
end

View file

@ -90,13 +90,6 @@ module ApplicationHelper
end
end
def ensure_safe_json(json)
json.present? ? JSON.parse(json).to_json : '[]'
rescue Exception => e
Raven.capture_exception(e)
{}
end
def sentry_config
sentry = Rails.application.secrets.sentry
if sentry

View file

@ -1,24 +1,12 @@
class Champs::DatetimeChamp < Champ
before_save :format_before_save
def same_hour?(num)
same_date?(num, '%H')
end
def same_minute?(num)
same_date?(num, '%M')
end
def search_terms
# Text search is pretty useless for datetimes so were not including these champs
end
private
def same_date?(num, compare)
return value.present? && value.to_datetime.strftime(compare) == num
end
def format_before_save
if (value =~ /=>/).present?
self.value =

View file

@ -152,22 +152,10 @@ class Dossier < ApplicationRecord
update_columns(autorisation_donnees: false)
end
def total_follow
follows.size
end
def read_only?
en_instruction? || accepte? || refuse? || sans_suite?
end
def invite_for_user(user)
invites.find_by(user_id: user.id)
end
def can_be_en_construction?
!(procedure.archivee? && brouillon?)
end
def can_transition_to_en_construction?
!procedure.archivee? && brouillon?
end

View file

@ -22,11 +22,6 @@ class Gestionnaire < ApplicationRecord
procedures.merge(Procedure.avec_lien.or(Procedure.archivees))
end
def can_view_dossier?(dossier_id)
avis.where(dossier_id: dossier_id).any? ||
dossiers.where(id: dossier_id).any?
end
def follow(dossier)
if follow?(dossier)
return
@ -43,10 +38,6 @@ class Gestionnaire < ApplicationRecord
followed_dossiers.include?(dossier)
end
def assigned_on_procedure?(procedure_id)
procedures.find_by(id: procedure_id).present?
end
def assign_to_procedure(procedure)
begin
procedures << procedure

View file

@ -164,10 +164,6 @@ class Procedure < ApplicationRecord
types_de_champ_private.order(:order_place)
end
def all_types_de_champ
types_de_champ + types_de_champ_private
end
def self.active(id)
publiees.find(id)
end

View file

@ -28,21 +28,6 @@ class User < ApplicationRecord
link_invites!
end
def self.find_for_france_connect(email, siret)
user = User.find_by(email: email)
if user.nil?
User.create(email: email, password: Devise.friendly_token[0, 20], siret: siret)
else
user.update(siret: siret)
user
end
end
def loged_in_with_france_connect?
loged_in_with_france_connect.present?
end
def owns?(dossier)
dossier.user_id == id
end

View file

@ -1,48 +0,0 @@
class ChampsService
class << self
def save_champs(champs, params)
fill_champs(champs, params)
champs.select(&:changed?).each(&:save)
end
def build_error_messages(champs)
champs.select(&:mandatory_and_blank?)
.map { |c| "Le champ #{c.libelle.truncate(200)} doit être rempli." }
end
def check_piece_justificative_files(champs)
champs.select do |champ|
champ.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative)
end.map(&:piece_justificative_file_errors).flatten
end
private
def fill_champs(champs, h)
datetimes, not_datetimes = champs.partition { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:datetime) }
not_datetimes.each do |c|
if c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) && h["champs"]["'#{c.id}'"].present?
c.piece_justificative_file.attach(h["champs"]["'#{c.id}'"])
else
c.value = h[:champs]["'#{c.id}'"]
end
end
datetimes.each { |c| c.value = parse_datetime(c.id, h) }
end
def parse_datetime(champ_id, h)
"#{h[:champs]["'#{champ_id}'"]} #{extract_hour(champ_id, h)}:#{extract_minute(champ_id, h)}"
end
def extract_hour(champ_id, h)
h[:time_hour]["'#{champ_id}'"]
end
def extract_minute(champ_id, h)
h[:time_minute]["'#{champ_id}'"]
end
end
end

View file

@ -15,23 +15,6 @@ class PiecesJustificativesService
.compact()
end
def self.upload_one!(dossier, user, params)
content = params[:piece_justificative][:content]
if ClamavService.safe_file?(content.path)
pj = PieceJustificative.new(content: content,
dossier: dossier,
type_de_piece_justificative: nil,
user: user)
pj.save
else
pj = PieceJustificative.new
pj.errors.add(:content, "#{content.original_filename} : <b>Virus détecté !!</b>")
end
pj
end
def self.save_pj(content, dossier, tpj, user)
pj = PieceJustificative.new(content: content,
dossier: dossier,

View file

@ -17,7 +17,7 @@ describe Users::SessionsController, type: :controller do
user.reload
end
subject { user.loged_in_with_france_connect? }
subject { user.loged_in_with_france_connect.present? }
it { is_expected.to be_falsey }
end
@ -141,7 +141,7 @@ describe Users::SessionsController, type: :controller do
it 'loged_in_with_france_connect current_user attribut is nil' do
user.reload
expect(user.loged_in_with_france_connect?).to be_falsey
expect(user.loged_in_with_france_connect.present?).to be_falsey
end
context 'when user is connect with france connect particulier' do

View file

@ -62,36 +62,4 @@ describe ChampDecorator do
end
end
end
describe '#date_for_input' do
subject { decorator.date_for_input }
describe "for a date" do
let(:type_de_champ) { create(:type_de_champ_date) }
context "when value is an ISO date" do
before { champ.update value: "2017-12-31" }
it { is_expected.to eq "2017-12-31" }
end
context "when value is empty" do
before { champ.update value: nil }
it { is_expected.to eq nil }
end
end
describe "for a datetime" do
let(:type_de_champ) { create(:type_de_champ_date) }
context "when value is an formatted datetime" do
before { champ.update value: "2017-12-30 23:17" }
it { is_expected.to eq "2017-12-30" }
end
context "when value is empty" do
before { champ.update value: nil }
it { is_expected.to eq nil }
end
end
end
end

View file

@ -17,18 +17,4 @@ 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

View file

@ -235,29 +235,6 @@ describe Dossier do
it { expect(dossier.champs_private.pluck(:libelle)).to match(['l1', 'l2', 'l3']) }
end
describe '#total_follow' do
let(:dossier) { create(:dossier, :with_entreprise, user: user) }
let(:dossier2) { create(:dossier, :with_entreprise, user: user) }
subject { dossier.total_follow }
context 'when no body follow dossier' do
it { expect(subject).to eq 0 }
end
context 'when 2 people follow dossier' do
before do
create :follow, dossier_id: dossier.id, gestionnaire_id: (create :gestionnaire).id
create :follow, dossier_id: dossier.id, gestionnaire_id: (create :gestionnaire).id
create :follow, dossier_id: dossier2.id, gestionnaire_id: (create :gestionnaire).id
create :follow, dossier_id: dossier2.id, gestionnaire_id: (create :gestionnaire).id
end
it { expect(subject).to eq 2 }
end
end
describe "#text_summary" do
let(:procedure) { create(:procedure, libelle: "Démarche", organisation: "Organisme") }

View file

@ -199,29 +199,6 @@ describe Gestionnaire, type: :model do
end
end
describe '#can_view_dossier?' do
subject{ gestionnaire.can_view_dossier?(dossier.id) }
context 'when gestionnaire is assigned on dossier' do
let!(:dossier){ create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
it { expect(subject).to be true }
end
context 'when gestionnaire is invited on dossier' do
let(:dossier){ create(:dossier) }
let!(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire) }
it { expect(subject).to be true }
end
context 'when gestionnaire is neither assigned nor invited on dossier' do
let(:dossier){ create(:dossier) }
it { expect(subject).to be false }
end
end
describe "procedure_presentation_and_errors_for_procedure_id" do
let(:procedure_presentation_and_errors) { gestionnaire.procedure_presentation_and_errors_for_procedure_id(procedure_id) }
let(:procedure_presentation) { procedure_presentation_and_errors.first }

View file

@ -20,36 +20,6 @@ describe User, type: :model do
end
end
describe '#find_for_france_connect' do
let(:siret) { '00000000000000' }
context 'when user exist' do
let!(:user) { create(:user) }
subject { described_class.find_for_france_connect(user.email, siret) }
it 'retrieves user' do
expect(subject).to eq(user)
end
it 'saves siret in user' do
expect(subject.siret).to eq(siret)
end
it 'does not create new user' do
expect { subject }.not_to change(User, :count)
end
end
context 'when user does not exist' do
let(:email) { 'super-m@n.com' }
subject { described_class.find_for_france_connect(email, siret) }
it 'returns user' do
expect(subject).to be_an_instance_of(User)
end
it 'creates new user' do
expect { subject }.to change(User, :count).by(1)
end
it 'saves siret' do
expect(subject.siret).to eq(siret)
end
end
end
describe '#owns?' do
let(:owner) { create(:user) }
let(:dossier) { create(:dossier, user: owner) }

View file

@ -1,40 +0,0 @@
require 'spec_helper'
describe ChampsService do
let(:type_de_champ) { create(:type_de_champ) }
let(:type_de_champ_mandatory) { create(:type_de_champ, libelle: 'mandatory', mandatory: true) }
let(:type_de_champ_datetime) { create(:type_de_champ_datetime) }
let!(:champ) { type_de_champ.champ.create(value: 'toto') }
let!(:champ_mandatory_empty) { type_de_champ_mandatory.champ.create }
let!(:champ_datetime) { type_de_champ_datetime.champ.create }
let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] }
describe 'save_champs' do
before :each do
params_hash = {
champs: {
"'#{champ.id}'" => 'yop',
"'#{champ_datetime.id}'" => 'd'
},
time_hour: { "'#{champ_datetime.id}'" => '12' },
time_minute: { "'#{champ_datetime.id}'" => '24' }
}
ChampsService.save_champs(champs, params_hash)
champs.each(&:reload)
end
it 'saves the changed champ' do
expect(champ.value).to eq('yop')
end
it 'parses and save the date' do
expect(champ_datetime.value).to eq(nil)
end
end
describe 'build_error_message' do
it 'adds error for the missing mandatory champ' do
expect(ChampsService.build_error_messages(champs)).to match(['Le champ mandatory doit être rempli.'])
end
end
end