commit
b1ed1dce0a
7 changed files with 42 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
||||||
class Administrateur < ApplicationRecord
|
class Administrateur < ApplicationRecord
|
||||||
self.ignored_columns = ['email', 'features', 'encrypted_password', 'reset_password_token', 'reset_password_sent_at', 'remember_created_at', 'sign_in_count', 'current_sign_in_at', 'last_sign_in_at', 'current_sign_in_ip', 'last_sign_in_ip', 'failed_attempts', 'unlock_token', 'locked_at']
|
self.ignored_columns = ['features', 'encrypted_password', 'reset_password_token', 'reset_password_sent_at', 'remember_created_at', 'sign_in_count', 'current_sign_in_at', 'last_sign_in_at', 'current_sign_in_ip', 'last_sign_in_ip', 'failed_attempts', 'unlock_token', 'locked_at']
|
||||||
include ActiveRecord::SecureToken
|
include ActiveRecord::SecureToken
|
||||||
|
|
||||||
has_and_belongs_to_many :instructeurs
|
has_and_belongs_to_many :instructeurs
|
||||||
|
|
|
@ -26,7 +26,9 @@ class Champ < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def siblings
|
def siblings
|
||||||
if public?
|
if parent
|
||||||
|
parent&.champs
|
||||||
|
elsif public?
|
||||||
dossier&.champs
|
dossier&.champs
|
||||||
else
|
else
|
||||||
dossier&.champs_private
|
dossier&.champs_private
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Instructeur < ApplicationRecord
|
class Instructeur < ApplicationRecord
|
||||||
self.ignored_columns = ['email', 'features', 'encrypted_password', 'reset_password_token', 'reset_password_sent_at', 'remember_created_at', 'sign_in_count', 'current_sign_in_at', 'last_sign_in_at', 'current_sign_in_ip', 'last_sign_in_ip', 'failed_attempts', 'unlock_token', 'locked_at']
|
self.ignored_columns = ['features', 'encrypted_password', 'reset_password_token', 'reset_password_sent_at', 'remember_created_at', 'sign_in_count', 'current_sign_in_at', 'last_sign_in_at', 'current_sign_in_ip', 'last_sign_in_ip', 'failed_attempts', 'unlock_token', 'locked_at']
|
||||||
|
|
||||||
has_and_belongs_to_many :administrateurs
|
has_and_belongs_to_many :administrateurs
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AdministrateursRemoveEmail < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
remove_column :administrateurs, :email
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_02_10_100938) do
|
ActiveRecord::Schema.define(version: 2020_02_11_170134) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -48,12 +48,10 @@ ActiveRecord::Schema.define(version: 2020_02_10_100938) do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "administrateurs", id: :serial, force: :cascade do |t|
|
create_table "administrateurs", id: :serial, force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.boolean "active", default: false
|
t.boolean "active", default: false
|
||||||
t.string "encrypted_token"
|
t.string "encrypted_token"
|
||||||
t.index ["email"], name: "index_administrateurs_on_email"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "administrateurs_instructeurs", id: false, force: :cascade do |t|
|
create_table "administrateurs_instructeurs", id: false, force: :cascade do |t|
|
||||||
|
|
|
@ -23,15 +23,17 @@ describe Champ do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#siblings' do
|
describe '#siblings' do
|
||||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, types_de_champ_count: 1, types_de_champ_private_count: 1) }
|
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :with_repetition, types_de_champ_count: 1, types_de_champ_private_count: 1) }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
let(:public_champ) { dossier.champs.first }
|
let(:public_champ) { dossier.champs.first }
|
||||||
let(:private_champ) { dossier.champs_private.first }
|
let(:private_champ) { dossier.champs_private.first }
|
||||||
|
let(:champ_in_repetition) { dossier.champs.find(&:repetition?).champs.first }
|
||||||
let(:standalone_champ) { create(:champ, dossier: nil) }
|
let(:standalone_champ) { create(:champ, dossier: nil) }
|
||||||
|
|
||||||
it 'returns the sibling champs of a champ' do
|
it 'returns the sibling champs of a champ' do
|
||||||
expect(public_champ.siblings).to eq(dossier.champs)
|
expect(public_champ.siblings).to eq(dossier.champs)
|
||||||
expect(private_champ.siblings).to eq(dossier.champs_private)
|
expect(private_champ.siblings).to eq(dossier.champs_private)
|
||||||
|
expect(champ_in_repetition.siblings).to eq(champ_in_repetition.parent.champs)
|
||||||
expect(standalone_champ.siblings).to be_nil
|
expect(standalone_champ.siblings).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,14 +11,35 @@ describe Champs::HeaderSectionChamp do
|
||||||
create(:type_de_champ_email, order_place: 5)
|
create(:type_de_champ_email, order_place: 5)
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
let(:procedure) { create(:procedure, types_de_champ: types_de_champ) }
|
|
||||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
|
||||||
let(:first_header) { dossier.champs[0] }
|
|
||||||
let(:second_header) { dossier.champs[3] }
|
|
||||||
|
|
||||||
it 'returns the index of the section (starting from 1)' do
|
context 'for root-level champs' do
|
||||||
expect(first_header.section_index).to eq 1
|
let(:procedure) { create(:procedure, types_de_champ: types_de_champ) }
|
||||||
expect(second_header.section_index).to eq 2
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
|
let(:first_header) { dossier.champs[0] }
|
||||||
|
let(:second_header) { dossier.champs[3] }
|
||||||
|
|
||||||
|
it 'returns the index of the section (starting from 1)' do
|
||||||
|
expect(first_header.section_index).to eq 1
|
||||||
|
expect(second_header.section_index).to eq 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'for repetition champs' do
|
||||||
|
let(:procedure) { create(:procedure, :with_repetition) }
|
||||||
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
|
|
||||||
|
let(:repetition_tdc) { procedure.types_de_champ.find(&:repetition?) }
|
||||||
|
let(:first_header) { dossier.champs.first.champs[0] }
|
||||||
|
let(:second_header) { dossier.champs.first.champs[3] }
|
||||||
|
|
||||||
|
before do
|
||||||
|
repetition_tdc.types_de_champ = types_de_champ
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns the index of the section in the repetition (starting from 1)' do
|
||||||
|
expect(first_header.section_index).to eq 1
|
||||||
|
expect(second_header.section_index).to eq 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue