Merge branch 'dev'

This commit is contained in:
Mathieu Magnin 2017-08-28 11:56:41 +02:00
commit 791cfbe161
16 changed files with 99 additions and 112 deletions

View file

@ -40,8 +40,23 @@ Les informations nécessaire à l'initialisation de la base doivent être pré-c
Afin de générer la BDD de l'application, il est nécessaire d'éxécuter les commandes suivantes :
rake db:create db:schema:load db:migrate
rake db:create db:schema:load db:migrate RAILS_ENV=test
# Create and load the schema for both databases
rake db:create db:schema:load
# Migrate the development database and then the test database
rake db:migrate
rake db:migrate RAILS_ENV=test
## Création des comptes initiaux
rails c
> email = "<votre email>"
> password = "<votre mot de passe>"
> Administration.create(email: email, password: password)
> Administrateur.create(email: email, password: password)
> Gestionnaire.create(email: email, password: password)
> User.create(email: email, password: password)
## Lancement de l'application
@ -78,6 +93,11 @@ Pour exécuter les tests de l'application, plusieurs possibilités :
- Linter les fichiers HAML : `bundle exec haml-lint app/views/`
- Linter les fichiers SCSS : `bundle exec scss-lint app/assets/stylesheets/`
## Déploiement
- Tout nouveau commit ajouté à la branche `dev` est automatiquement déployé [en intégration](https://tps-dev.apientreprise.fr/)
- Tout nouveau commit ajouté à la branche `master` est automatiquement déployé [en production](https://tps.apientreprise.fr/)
## Régénérer les binstubs
bundle binstub railties --force

View file

@ -190,7 +190,7 @@ class StatsController < ApplicationController
average = Avis.with_answer
.where(created_at: min_date..max_date)
.average("EXTRACT(EPOCH FROM updated_at - created_at) / 86400")
.average("EXTRACT(EPOCH FROM avis.updated_at - avis.created_at) / 86400")
result = average ? average.to_f.round(2) : 0

View file

@ -6,6 +6,7 @@ class Avis < ApplicationRecord
before_create :try_to_assign_gestionnaire
after_create :notify_gestionnaire
default_scope { joins(:dossier) }
scope :with_answer, -> { where.not(answer: nil) }
scope :without_answer, -> { where(answer: nil) }
scope :for_dossier, ->(dossier_id) { where(dossier_id: dossier_id) }

View file

@ -117,11 +117,11 @@ class Dossier < ActiveRecord::Base
end
def ordered_champs
champs.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
champs.includes(:type_de_champ).order('types_de_champ.order_place')
end
def ordered_champs_private
champs_private.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
champs_private.includes(:type_de_champ).order('types_de_champ.order_place')
end
def ordered_pieces_justificatives

View file

@ -3,6 +3,7 @@ class DossierSerializer < ActiveModel::Serializer
:created_at,
:updated_at,
:archived,
:email,
:mandataire_social,
:state,
:simplified_state,
@ -22,6 +23,10 @@ class DossierSerializer < ActiveModel::Serializer
has_many :pieces_justificatives
has_many :types_de_piece_justificative
def email
object.user.try(:email)
end
def simplified_state
object.decorate.display_state
end

View file

@ -3,6 +3,7 @@ class DossierTableExportSerializer < ActiveModel::Serializer
:created_at,
:updated_at,
:archived,
:email,
:mandataire_social,
:state,
:initiated_at,
@ -17,6 +18,10 @@ class DossierTableExportSerializer < ActiveModel::Serializer
:individual_nom,
:individual_birthdate
def email
object.user.try(:email)
end
def individual_prenom
object.individual.try(:prenom)
end

View file

@ -0,0 +1,5 @@
class AddIdToAssignTo < ActiveRecord::Migration[5.0]
def change
add_column :assign_tos, :id, :primary_key
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170713151123) do
ActiveRecord::Schema.define(version: 20170801083632) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -64,7 +64,7 @@ ActiveRecord::Schema.define(version: 20170713151123) do
t.datetime "updated_at", null: false
end
create_table "assign_tos", id: false, force: :cascade do |t|
create_table "assign_tos", force: :cascade do |t|
t.integer "gestionnaire_id"
t.integer "procedure_id"
t.index ["gestionnaire_id"], name: "index_assign_tos_on_gestionnaire_id", using: :btree
@ -384,9 +384,9 @@ ActiveRecord::Schema.define(version: 20170713151123) do
t.boolean "individual_with_siret", default: false
t.date "auto_archive_on"
t.datetime "hidden_at"
t.index ["hidden_at"], name: "index_procedures_on_hidden_at", using: :btree
t.datetime "published_at"
t.datetime "archived_at"
t.index ["hidden_at"], name: "index_procedures_on_hidden_at", using: :btree
end
create_table "quartier_prioritaires", force: :cascade do |t|

View file

@ -5,12 +5,3 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].sort.each { |seed| load seed }
# puts "create links"
# TypePieceJointe.find_each do |type_piece_jointe|
# forms = Formulaire.find_by_demarche_id(type_piece_jointe.CERFA)
# type_piece_jointe.update_attributes(formulaire_id: forms.id) unless forms.nil?
# end
# puts "end links creation"

View file

@ -1,7 +0,0 @@
begin
Administration.create!(email: SUPERADMIN.email, password: SUPERADMIN.password)
rescue ActiveRecord::RecordInvalid
admin = Administration.find_by_email(SUPERADMIN.email)
admin.password = SUPERADMIN.password
admin.save
end

View file

@ -0,0 +1,12 @@
namespace :'2017_08_01_clean_assign_to' do
task clean: :environment do
duplicates = AssignTo.group(:gestionnaire_id, :procedure_id).count.select{ |_gestionnaire_id_procedure_id, count| count > 1 }.keys
duplicate_ids = duplicates.map { |gestionnaire_id, procedure_id| AssignTo.where(gestionnaire_id: gestionnaire_id, procedure_id: procedure_id).pluck(:id) }
duplicate_ids.each do |ids|
ids.pop
AssignTo.where(id: ids).destroy_all
end
end
end

View file

@ -114,7 +114,7 @@ describe API::V1::DossiersController do
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure, motivation: "Motivation") } }
let(:dossier_id) { dossier.id }
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :accompagnateurs, :invites] }
let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :email, :accompagnateurs, :invites] }
subject { body[:dossier] }
it 'return REST code 200', :show_in_doc do

View file

@ -333,8 +333,6 @@ describe Backoffice::DossiersController, type: :controller do
end
context 'when the dossier has an attestation' do
let(:emailable) { false }
before do
attestation = Attestation.new
allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes))
@ -350,6 +348,8 @@ describe Backoffice::DossiersController, type: :controller do
it 'Notification email is sent with the attestation' do
subject
is_expected.to redirect_to backoffice_dossier_path(id: dossier.id)
end
end
@ -361,10 +361,10 @@ describe Backoffice::DossiersController, type: :controller do
expect(controller).to receive(:capture_message)
subject
is_expected.to redirect_to backoffice_dossier_path(id: dossier.id)
end
end
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
end
end
end

View file

@ -58,6 +58,17 @@ describe BackofficeController, type: :controller do
it { expect(response.body).to include("1 avis rendu") }
it { expect(response.body).to include(dossier.procedure.libelle) }
end
context 'when dossier linked to avis is hidden' do
before do
dossier.update_attributes(hidden_at: Time.now)
get :invitations
end
it { expect(response.status).to eq(200) }
it { expect(response.body).to include("0 avis à rendre") }
it { expect(response.body).to include("0 avis rendu") }
end
end
end
end

View file

@ -482,18 +482,19 @@ describe Dossier do
it { expect(subject[1]).to be_a_kind_of(Time) }
it { expect(subject[2]).to be_a_kind_of(Time) }
it { expect(subject[3]).to be_in([true, false]) }
it { expect(subject[4]).to be_in([true, false]) }
it { expect(subject[5]).to eq("draft") }
it { expect(subject[6]).to eq(date1) }
it { expect(subject[7]).to eq(date2) }
it { expect(subject[8]).to eq(date3) }
it { expect(subject[9]).to be_a_kind_of(String) }
it { expect(subject[4]).to eq(dossier.user.email) }
it { expect(subject[5]).to be_in([true, false]) }
it { expect(subject[6]).to eq("draft") }
it { expect(subject[7]).to eq(date1) }
it { expect(subject[8]).to eq(date2) }
it { expect(subject[9]).to eq(date3) }
it { expect(subject[10]).to be_a_kind_of(String) }
it { expect(subject[11]).to be_nil }
it { expect(subject[11]).to be_a_kind_of(String) }
it { expect(subject[12]).to be_nil }
it { expect(subject[13]).to be_nil }
it { expect(subject[14]).to be_nil }
it { expect(subject[15]).to be_nil }
it { expect(subject[16]).to be_nil }
it { expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count +
dossier.procedure.types_de_champ.count +
dossier.procedure.types_de_champ_private.count +
@ -505,10 +506,10 @@ describe Dossier do
subject { dossier_with_individual.data_with_champs }
it { expect(subject[11]).to eq(dossier_with_individual.individual.gender) }
it { expect(subject[12]).to eq(dossier_with_individual.individual.prenom) }
it { expect(subject[13]).to eq(dossier_with_individual.individual.nom) }
it { expect(subject[14]).to eq(dossier_with_individual.individual.birthdate) }
it { expect(subject[12]).to eq(dossier_with_individual.individual.gender) }
it { expect(subject[13]).to eq(dossier_with_individual.individual.prenom) }
it { expect(subject[14]).to eq(dossier_with_individual.individual.nom) }
it { expect(subject[15]).to eq(dossier_with_individual.individual.birthdate) }
end
end
@ -519,6 +520,7 @@ describe Dossier do
dossier.created_at,
dossier.updated_at,
"false",
dossier.user.email,
"false",
"draft",
dossier.initiated_at,
@ -598,87 +600,29 @@ describe Dossier do
end
describe '#ordered_champs' do
let!(:procedure_1) { create :procedure }
let!(:procedure_2) { create :procedure }
let(:dossier_1) { Dossier.new(id: 0, procedure: procedure_1) }
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
let(:procedure) { create(:procedure) }
let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) }
before do
create :type_de_champ_public, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
create :type_de_champ_public, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure
create :type_de_champ_public, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure
create :type_de_champ_public, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure
create :type_de_champ_public, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure
dossier_1.build_default_champs
dossier_2.build_default_champs
create(:type_de_champ_public, libelle: 'l1', order_place: 1, procedure: procedure)
create(:type_de_champ_public, libelle: 'l3', order_place: 3, procedure: procedure)
create(:type_de_champ_public, libelle: 'l2', order_place: 2, procedure: procedure)
end
subject { dossier.ordered_champs }
it { expect(ChampPublic.where(dossier_id: 0).size).to eq 5 }
describe 'for dossier 1' do
let(:dossier) { dossier_1 }
it { expect(subject.size).to eq 2 }
it { expect(subject.first.type_de_champ.libelle).to eq 'type_1_1' }
it { expect(subject.last.type_de_champ.libelle).to eq 'type_1_2' }
end
describe 'for dossier 2' do
let(:dossier) { dossier_2 }
it { expect(subject.size).to eq 3 }
it { expect(subject.first.type_de_champ.libelle).to eq 'type_2_1' }
it { expect(subject.second.type_de_champ.libelle).to eq 'type_2_2' }
it { expect(subject.last.type_de_champ.libelle).to eq 'type_2_3' }
end
it { expect(dossier.ordered_champs.pluck(:libelle)).to match(%w(l1 l2 l3)) }
end
describe '#ordered_champs_private' do
let!(:procedure_1) { create :procedure }
let!(:procedure_2) { create :procedure }
let(:dossier_1) { Dossier.new(id: 0, procedure: procedure_1) }
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
let(:procedure) { create :procedure }
let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) }
before do
create :type_de_champ_private, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
create :type_de_champ_private, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure
create :type_de_champ_private, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure
create :type_de_champ_private, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure
create :type_de_champ_private, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure
dossier_1.build_default_champs
dossier_2.build_default_champs
create :type_de_champ_private, libelle: 'l1', order_place: 1, procedure: procedure
create :type_de_champ_private, libelle: 'l3', order_place: 3, procedure: procedure
create :type_de_champ_private, libelle: 'l2', order_place: 2, procedure: procedure
end
subject { dossier.ordered_champs_private }
it { expect(ChampPrivate.where(dossier_id: 0).size).to eq 5 }
describe 'for dossier 1' do
let(:dossier) { dossier_1 }
it { expect(subject.size).to eq 2 }
it { expect(subject.first.type_de_champ.libelle).to eq 'type_1_1' }
it { expect(subject.last.type_de_champ.libelle).to eq 'type_1_2' }
end
describe 'for dossier 2' do
let(:dossier) { dossier_2 }
it { expect(subject.size).to eq 3 }
it { expect(subject.first.type_de_champ.libelle).to eq 'type_2_1' }
it { expect(subject.second.type_de_champ.libelle).to eq 'type_2_2' }
it { expect(subject.last.type_de_champ.libelle).to eq 'type_2_3' }
end
it { expect(dossier.ordered_champs_private.pluck(:libelle)).to match(%w(l1 l2 l3)) }
end
describe '#total_follow' do

View file

@ -7,8 +7,8 @@ describe ClamavService do
subject { ClamavService.safe_file? path_file }
before do
allow_any_instance_of(ClamAV::Client).to receive(:initialize).and_return(ClamAV::Client)
allow_any_instance_of(ClamAV::Client).to receive(:execute).and_return([ClamAV::SuccessResponse])
client = instance_double("ClamAV::Client", :execute => [ClamAV::SuccessResponse])
allow(ClamAV::Client).to receive(:new).and_return(client)
end
it 'change permission of file path' do