Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-03-17 17:33:51 +01:00
commit 05bc2c0f4b
18 changed files with 108 additions and 20 deletions

View file

@ -34,7 +34,7 @@ class Users::DescriptionController < UsersController
if @procedure.cerfa_flag?
unless params[:cerfa_pdf].nil?
cerfa = Cerfa.new(content: params[:cerfa_pdf], dossier: @dossier)
cerfa = Cerfa.new(content: params[:cerfa_pdf], dossier: @dossier, user: current_user)
unless cerfa.save
flash.now.alert = cerfa.errors.full_messages.join('<br />').html_safe
return render 'show'
@ -60,7 +60,8 @@ class Users::DescriptionController < UsersController
piece_justificative = PieceJustificative.new(content: params["piece_justificative_#{type_de_pieces_justificatives.id}"],
dossier: @dossier,
type_de_piece_justificative: type_de_pieces_justificatives)
type_de_piece_justificative: type_de_pieces_justificatives,
user: current_user)
unless piece_justificative.save
flash.now.alert = piece_justificative.errors.full_messages.join('<br />').html_safe

View file

@ -1,5 +1,6 @@
class Cerfa < ActiveRecord::Base
belongs_to :dossier
belongs_to :user
mount_uploader :content, CerfaUploader
validates :content, :file_size => {:maximum => 3.megabytes}

View file

@ -2,6 +2,8 @@ class PieceJustificative < ActiveRecord::Base
belongs_to :dossier
belongs_to :type_de_piece_justificative
belongs_to :user
delegate :api_entreprise, :libelle, to: :type_de_piece_justificative
alias_attribute :type, :type_de_piece_justificative_id

View file

@ -9,6 +9,8 @@ class User < ActiveRecord::Base
has_many :dossiers, dependent: :destroy
has_many :invites, dependent: :destroy
has_many :piece_justificative, dependent: :destroy
has_many :cerfa, dependent: :destroy
has_one :france_connect_information, dependent: :destroy
delegate :given_name, :family_name, :email_france_connect, :gender, :birthdate, :birthplace, :france_connect_particulier_id, to: :france_connect_information

View file

@ -3,5 +3,5 @@ class CerfaSerializer < ActiveModel::Serializer
attributes :created_at,
:content_url => :url
has_one :user
end

View file

@ -12,5 +12,6 @@ class DossierSerializer < ActiveModel::Serializer
has_many :cerfa
has_many :commentaires
has_many :champs
has_many :pieces_justificatives
has_many :types_de_piece_justificative
end

View file

@ -1,5 +1,7 @@
class PieceJustificativeSerializer < ActiveModel::Serializer
attributes :created_at,
:type_de_piece_justificative_id,
:content_url => :url
has_one :user
end

View file

@ -3,5 +3,4 @@ class TypeDePieceJustificativeSerializer < ActiveModel::Serializer
:libelle,
:description
has_many :pieces_justificatives
end

View file

@ -0,0 +1,3 @@
class UserSerializer < ActiveModel::Serializer
attributes :email
end

View file

@ -22,7 +22,7 @@
- @facade.cerfas_ordered.each do |cerfa|
%tr
%td.col-md-6.col-lg-4
= cerfa.dossier.user.email
= cerfa.user.email
%td.col-md-6.col-lg-4
= cerfa.created_at
%td.col-md-6.col-lg-4
@ -32,7 +32,7 @@
- @facade.dossier.retrieve_all_piece_justificative_by_type(type_de_piece_justificative.id).each do |piece_justificative|
%tr
%td.col-md-6.col-lg-4
= piece_justificative.dossier.user.email
= piece_justificative.user.email
%td.col-md-6.col-lg-4
= piece_justificative.created_at
%td.col-md-6.col-lg-4

View file

@ -0,0 +1,22 @@
class PieceJustificativeHaveUser < ActiveRecord::Migration
class PieceJustificative < ActiveRecord::Base
belongs_to :dossier
end
class Dossier < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
end
def change
add_reference :pieces_justificatives, :user, references: :users
PieceJustificative.all.each do |piece_justificative|
piece_justificative.user_id = piece_justificative.dossier.user.id
piece_justificative.save
end
end
end

View file

@ -0,0 +1,22 @@
class CerfaHaveUser < ActiveRecord::Migration
class Cerfa < ActiveRecord::Base
belongs_to :dossier
end
class Dossier < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
end
def change
add_reference :cerfas, :user, references: :users
Cerfa.all.each do |cerfa|
cerfa.user_id = cerfa.dossier.user.id
cerfa.save
end
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160317135217) do
ActiveRecord::Schema.define(version: 20160317153115) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -71,6 +71,7 @@ ActiveRecord::Schema.define(version: 20160317135217) do
t.string "content"
t.integer "dossier_id"
t.datetime "created_at"
t.integer "user_id"
end
add_index "cerfas", ["dossier_id"], name: "index_cerfas_on_dossier_id", using: :btree
@ -200,6 +201,7 @@ ActiveRecord::Schema.define(version: 20160317135217) do
t.integer "dossier_id"
t.integer "type_de_piece_justificative_id"
t.datetime "created_at"
t.integer "user_id"
end
add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree

View file

@ -116,7 +116,7 @@ describe API::V1::DossiersController do
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
let(:dossier_id) { dossier.id }
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :champs, :commentaires] }
let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :commentaires] }
subject { body[:dossier] }
it 'return REST code 200', :show_in_doc do
@ -162,10 +162,6 @@ describe API::V1::DossiersController do
end
describe 'types_de_piece_justificative' do
before do
create :piece_justificative, dossier: dossier, type_de_piece_justificative: dossier.procedure.types_de_piece_justificative.first
end
let(:field_list) { [
:id,
:libelle,
@ -180,16 +176,32 @@ describe API::V1::DossiersController do
it { expect(subject.keys.include?(:id)).to be_truthy }
it { expect(subject[:libelle]).to eq('RIB') }
it { expect(subject[:description]).to eq('Releve identité bancaire') }
end
end
describe 'piece justificative' do
before do
create :piece_justificative, dossier: dossier, type_de_piece_justificative: dossier.procedure.types_de_piece_justificative.first, user: dossier.user
end
let(:field_list) { [
:url, :created_at] }
:url, :created_at, :type_de_piece_justificative_id] }
subject {
super()[:pieces_justificatives].first }
it { expect(subject.keys.include?(:url)).to be_truthy }
it { expect(subject[:created_at]).not_to be_nil }
end
it { expect(subject[:type_de_piece_justificative_id]).not_to be_nil }
it { expect(subject.keys.include?(:user)).to be_truthy }
describe 'user' do
let(:field_list) { [
:url, :created_at, :type_de_piece_justificative_id] }
subject {
super()[:user] }
it { expect(subject[:email]).not_to be_nil }
end
end
@ -244,6 +256,7 @@ describe API::V1::DossiersController do
before do
tmp_cerfa = dossier.cerfa.first
tmp_cerfa.content = content
tmp_cerfa.user = dossier.user
tmp_cerfa.save
end
@ -251,6 +264,15 @@ describe API::V1::DossiersController do
it { expect(subject[:created_at]).not_to be_nil }
it { expect(subject[:url]).to match /^http:\/\/.*downloads.*_CERFA\.pdf$/ }
describe 'user' do
let(:field_list) { [
:url, :created_at, :type_de_piece_justificative_id] }
subject {
super()[:user] }
it { expect(subject[:email]).not_to be_nil }
end
end
describe 'etablissement' do

View file

@ -142,6 +142,8 @@ describe Users::DescriptionController, type: :controller do
it 'dossier_id' do
expect(subject.dossier_id).to eq(dossier_id)
end
it { expect(subject.user).to eq user }
end
context 'les anciens CERFA PDF ne sont pas écrasées' do
@ -222,10 +224,12 @@ describe Users::DescriptionController, type: :controller do
context 'for piece 0' do
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[0].to_s }
it { expect(subject.content).not_to be_nil }
it { expect(subject.user).to eq user }
end
context 'for piece 1' do
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[1].to_s }
it { expect(subject.content).not_to be_nil }
it { expect(subject.user).to eq user }
end
end
end

View file

@ -8,6 +8,7 @@ describe Cerfa do
describe 'associations' do
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:user) }
end
describe 'empty?' do

View file

@ -9,6 +9,8 @@ describe PieceJustificative do
describe 'associations' do
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:type_de_piece_justificative) }
it { is_expected.to belong_to(:user) }
end
describe 'delegation' do

View file

@ -21,6 +21,8 @@ describe User, type: :model do
describe 'associations' do
it { is_expected.to have_many(:dossiers) }
it { is_expected.to have_many(:invites) }
it { is_expected.to have_many(:piece_justificative) }
it { is_expected.to have_many(:cerfa) }
end
describe '#find_for_france_connect' do
let(:siret) { '00000000000000' }