Merge branch 'develop' into refactor_type_de_xxx
This commit is contained in:
commit
0f73a2fc94
16 changed files with 89 additions and 38 deletions
|
@ -1,7 +1,7 @@
|
|||
class Admin::ProceduresController < AdminController
|
||||
|
||||
def index
|
||||
@procedures = Procedure.all
|
||||
@procedures = current_administrateur.procedures
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
class BackofficeController < ApplicationController
|
||||
|
||||
def index
|
||||
redirect_to(controller: '/gestionnaires/sessions', action: :new) unless gestionnaire_signed_in?
|
||||
@dossiers_a_traiter = Dossier.a_traiter.decorate
|
||||
@dossiers_en_attente = Dossier.en_attente.decorate
|
||||
@dossiers_termine = Dossier.termine.decorate
|
||||
if !gestionnaire_signed_in?
|
||||
redirect_to(controller: '/gestionnaires/sessions', action: :new)
|
||||
else
|
||||
@dossiers_a_traiter = Dossier.a_traiter(current_gestionnaire).decorate
|
||||
@dossiers_en_attente = Dossier.en_attente(current_gestionnaire).decorate
|
||||
@dossiers_termine = Dossier.termine(current_gestionnaire).decorate
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,4 +3,7 @@ class Administrateur < ActiveRecord::Base
|
|||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
has_many :gestionnaires
|
||||
has_many :procedures
|
||||
end
|
||||
|
|
|
@ -116,16 +116,16 @@ class Dossier < ActiveRecord::Base
|
|||
state
|
||||
end
|
||||
|
||||
def self.a_traiter
|
||||
Dossier.where("state='initiated' OR state='updated' OR state='submitted'").order('updated_at ASC')
|
||||
def self.a_traiter current_gestionnaire
|
||||
Dossier.joins(:procedure).where("(state='initiated' OR state='updated' OR state='submitted') AND dossiers.procedure_id = procedures.id AND procedures.administrateur_id = #{current_gestionnaire.administrateur_id}").order('updated_at ASC')
|
||||
end
|
||||
|
||||
def self.en_attente
|
||||
Dossier.where("state='replied' OR state='validated'").order('updated_at ASC')
|
||||
def self.en_attente current_gestionnaire
|
||||
Dossier.joins(:procedure).where("(state='replied' OR state='validated') AND dossiers.procedure_id = procedures.id AND procedures.administrateur_id = #{current_gestionnaire.administrateur_id}").order('updated_at ASC')
|
||||
end
|
||||
|
||||
def self.termine
|
||||
Dossier.where("state='closed'").order('updated_at ASC')
|
||||
def self.termine current_gestionnaire
|
||||
Dossier.joins(:procedure).where("state='closed' AND dossiers.procedure_id = procedures.id AND procedures.administrateur_id = #{current_gestionnaire.administrateur_id}").order('updated_at ASC')
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -3,4 +3,6 @@ class Gestionnaire < ActiveRecord::Base
|
|||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
belongs_to :administrateur
|
||||
end
|
||||
|
|
|
@ -4,6 +4,8 @@ class Procedure < ActiveRecord::Base
|
|||
has_many :dossiers
|
||||
accepts_nested_attributes_for :types_de_champ,:reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
|
||||
|
||||
belongs_to :administrateur
|
||||
|
||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class CreateReferenceAdmninistrateurToProcedure < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :procedures, :administrateur, references: :procedures
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class CreateReferenceAdmninistrateurToGestionnaire < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :gestionnaires, :administrateur, references: :gestionnaires
|
||||
end
|
||||
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20151105095431) do
|
||||
ActiveRecord::Schema.define(version: 20151110091451) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -117,6 +117,7 @@ ActiveRecord::Schema.define(version: 20151105095431) do
|
|||
t.inet "last_sign_in_ip"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "administrateur_id"
|
||||
end
|
||||
|
||||
add_index "gestionnaires", ["email"], name: "index_gestionnaires_on_email", unique: true, using: :btree
|
||||
|
@ -136,10 +137,11 @@ ActiveRecord::Schema.define(version: 20151105095431) do
|
|||
t.string "organisation"
|
||||
t.string "direction"
|
||||
t.string "lien_demarche"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "test"
|
||||
t.boolean "use_api_carto", default: false
|
||||
t.boolean "use_api_carto", default: false
|
||||
t.integer "administrateur_id"
|
||||
end
|
||||
|
||||
create_table "types_de_champ", force: :cascade do |t|
|
||||
|
|
|
@ -20,7 +20,9 @@ feature 'when gestionnaire come to /backoffice and is not authenticated' do
|
|||
end
|
||||
end
|
||||
context 'when user enter good credentials' do
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
|
||||
|
||||
before do
|
||||
page.find_by_id(:gestionnaire_email).set gestionnaire.email
|
||||
page.find_by_id(:gestionnaire_password).set gestionnaire.password
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'on backoffice page' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
|
||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
|
||||
let!(:dossier) { create(:dossier, :with_user, :with_entreprise, procedure: procedure, state: 'replied') }
|
||||
before do
|
||||
visit backoffice_path
|
||||
end
|
||||
context 'when gestionnaire is logged in' do
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
before do
|
||||
page.find_by_id(:gestionnaire_email).set gestionnaire.email
|
||||
page.find_by_id(:gestionnaire_password).set gestionnaire.password
|
||||
page.find_by_id(:gestionnaire_email).set gestionnaire.email
|
||||
page.find_by_id(:gestionnaire_password).set gestionnaire.password
|
||||
page.click_on 'Se connecter'
|
||||
end
|
||||
context 'when he click on first dossier' do
|
||||
|
|
|
@ -15,4 +15,10 @@ describe Administrateur, type: :model do
|
|||
it { is_expected.to have_db_column(:created_at) }
|
||||
it { is_expected.to have_db_column(:updated_at) }
|
||||
end
|
||||
|
||||
describe 'assocations' do
|
||||
it { is_expected.to have_many(:gestionnaires) }
|
||||
it { is_expected.to have_many(:procedures) }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -381,29 +381,38 @@ describe Dossier do
|
|||
end
|
||||
|
||||
context 'gestionnaire backoffice methods' do
|
||||
let!(:dossier1) { create(:dossier, :with_user, :with_procedure, state: 'draft')}
|
||||
let!(:dossier2) { create(:dossier, :with_user, :with_procedure, state: 'initiated')}
|
||||
let!(:dossier3) { create(:dossier, :with_user, :with_procedure, state: 'initiated')}
|
||||
let!(:dossier4) { create(:dossier, :with_user, :with_procedure, state: 'replied')}
|
||||
let!(:dossier5) { create(:dossier, :with_user, :with_procedure, state: 'updated')}
|
||||
let!(:dossier6) { create(:dossier, :with_user, :with_procedure, state: 'validated')}
|
||||
let!(:dossier7) { create(:dossier, :with_user, :with_procedure, state: 'submitted')}
|
||||
let!(:dossier8) { create(:dossier, :with_user, :with_procedure, state: 'closed')}
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:admin_2) { create(:administrateur) }
|
||||
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: admin) }
|
||||
let(:procedure_admin) { create(:procedure, administrateur: admin) }
|
||||
let(:procedure_admin_2) { create(:procedure, administrateur: admin_2) }
|
||||
|
||||
let!(:dossier1) { create(:dossier, :with_user, procedure: procedure_admin, state: 'draft')}
|
||||
let!(:dossier2) { create(:dossier, :with_user, procedure: procedure_admin, state: 'initiated')} #a_traiter
|
||||
let!(:dossier3) { create(:dossier, :with_user, procedure: procedure_admin, state: 'initiated')} #a_traiter
|
||||
let!(:dossier4) { create(:dossier, :with_user, procedure: procedure_admin, state: 'replied')} #en_attente
|
||||
let!(:dossier5) { create(:dossier, :with_user, procedure: procedure_admin, state: 'updated')} #a_traiter
|
||||
let!(:dossier6) { create(:dossier, :with_user, procedure: procedure_admin_2, state: 'validated')} #en_attente
|
||||
let!(:dossier7) { create(:dossier, :with_user, procedure: procedure_admin_2, state: 'submitted')} #a_traiter
|
||||
let!(:dossier8) { create(:dossier, :with_user, procedure: procedure_admin_2, state: 'closed')} #termine
|
||||
let!(:dossier9) { create(:dossier, :with_user, procedure: procedure_admin, state: 'closed')} #termine
|
||||
|
||||
|
||||
describe '#a_traiter' do
|
||||
subject { described_class.a_traiter }
|
||||
subject { described_class.a_traiter gestionnaire }
|
||||
|
||||
it { expect(subject.size).to eq(4) }
|
||||
it { expect(subject.size).to eq(3) }
|
||||
end
|
||||
|
||||
describe '#en_attente' do
|
||||
subject { described_class.en_attente }
|
||||
subject { described_class.en_attente gestionnaire }
|
||||
|
||||
it { expect(subject.size).to eq(2) }
|
||||
it { expect(subject.size).to eq(1) }
|
||||
end
|
||||
|
||||
describe '#termine' do
|
||||
subject { described_class.termine }
|
||||
subject { described_class.termine gestionnaire }
|
||||
|
||||
it { expect(subject.size).to eq(1) }
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Gestionnaire, type: :model do
|
||||
|
||||
describe 'database column' do
|
||||
it { is_expected.to have_db_column(:email) }
|
||||
it { is_expected.to have_db_column(:encrypted_password) }
|
||||
|
@ -16,4 +15,8 @@ describe Gestionnaire, type: :model do
|
|||
it { is_expected.to have_db_column(:created_at) }
|
||||
it { is_expected.to have_db_column(:updated_at) }
|
||||
end
|
||||
|
||||
describe 'association' do
|
||||
it { is_expected.to belong_to(:administrateur) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,8 @@ describe Procedure do
|
|||
it { is_expected.to have_many(:types_de_piece_justificative) }
|
||||
it { is_expected.to have_many(:types_de_champ) }
|
||||
it { is_expected.to have_many(:dossiers) }
|
||||
it { is_expected.to belong_to(:administrateur) }
|
||||
|
||||
end
|
||||
|
||||
describe 'attributes' do
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'backoffice/index.html.haml', type: :view do
|
||||
let!(:procedure) { create(:procedure) }
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
|
||||
|
||||
let!(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure).decorate }
|
||||
|
||||
before do
|
||||
assign(:dossiers_a_traiter, Dossier.a_traiter.decorate)
|
||||
assign(:dossiers_en_attente, Dossier.en_attente.decorate)
|
||||
assign(:dossiers_termine, Dossier.termine.decorate)
|
||||
assign(:dossiers_a_traiter, Dossier.a_traiter(gestionnaire).decorate)
|
||||
assign(:dossiers_en_attente, Dossier.en_attente(gestionnaire).decorate)
|
||||
assign(:dossiers_termine, Dossier.termine(gestionnaire).decorate)
|
||||
|
||||
decorate_dossier.initiated!
|
||||
render
|
||||
end
|
||||
|
||||
subject { rendered }
|
||||
it { is_expected.to have_css('#backoffice') }
|
||||
it { is_expected.to have_content(procedure.libelle) }
|
||||
|
|
Loading…
Reference in a new issue