instructeurs: create without providing the email
This commit is contained in:
parent
f131dbb80d
commit
f8358b3ae9
7 changed files with 22 additions and 15 deletions
|
@ -1,11 +1,8 @@
|
|||
class Instructeur < ApplicationRecord
|
||||
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 EmailSanitizableConcern
|
||||
|
||||
has_and_belongs_to_many :administrateurs
|
||||
|
||||
before_validation -> { sanitize_email(:email) }
|
||||
|
||||
has_many :assign_to, dependent: :destroy
|
||||
has_many :groupe_instructeurs, through: :assign_to
|
||||
has_many :procedures, -> { distinct }, through: :groupe_instructeurs
|
||||
|
|
|
@ -70,7 +70,7 @@ class User < ApplicationRecord
|
|||
|
||||
if user.valid?
|
||||
if user.instructeur_id.nil?
|
||||
user.create_instructeur!(email: email)
|
||||
user.create_instructeur!
|
||||
end
|
||||
|
||||
user.instructeur.administrateurs << administrateurs
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class RemoveUniqueConstraintOnInstructeurEmails < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
# Drop the index entirely
|
||||
remove_index :instructeurs, :email
|
||||
# Add the index again, without the unicity constraint
|
||||
add_index :instructeurs, :email
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :instructeurs, :email
|
||||
add_index :instructeurs, :email, unique: true
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_10_23_183120) do
|
||||
ActiveRecord::Schema.define(version: 2019_10_24_150452) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -419,7 +419,7 @@ ActiveRecord::Schema.define(version: 2019_10_23_183120) do
|
|||
t.datetime "updated_at"
|
||||
t.text "encrypted_login_token"
|
||||
t.datetime "login_token_created_at"
|
||||
t.index ["email"], name: "index_instructeurs_on_email", unique: true
|
||||
t.index ["email"], name: "index_instructeurs_on_email"
|
||||
end
|
||||
|
||||
create_table "invites", id: :serial, force: :cascade do |t|
|
||||
|
|
10
db/seeds.rb
10
db/seeds.rb
|
@ -10,12 +10,10 @@ default_password = "this is a very complicated password !"
|
|||
|
||||
puts "Create test user '#{default_user}'"
|
||||
Administration.create!(email: default_user, password: default_password)
|
||||
administrateur = Administrateur.create!(email: default_user)
|
||||
instructeur = Instructeur.create!(email: default_user)
|
||||
User.create!(
|
||||
user = User.create!(
|
||||
email: default_user,
|
||||
password: default_password,
|
||||
confirmed_at: Time.zone.now,
|
||||
administrateur: administrateur,
|
||||
instructeur: instructeur
|
||||
confirmed_at: Time.zone.now
|
||||
)
|
||||
user.create_instructeur!
|
||||
user.create_administrateur!(email: user.email)
|
||||
|
|
|
@ -2,9 +2,8 @@ FactoryBot.define do
|
|||
sequence(:instructeur_email) { |n| "inst#{n}@inst.com" }
|
||||
|
||||
factory :instructeur do
|
||||
email { generate(:instructeur_email) }
|
||||
|
||||
transient do
|
||||
email { generate(:instructeur_email) }
|
||||
password { 'somethingverycomplated!' }
|
||||
end
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ describe User, type: :model do
|
|||
context 'with an existing instructeur' do
|
||||
let(:old_admins) { [create(:administrateur)] }
|
||||
let(:admins) { [create(:administrateur)] }
|
||||
let!(:instructeur) { Instructeur.create(email: 'i@mail.com', administrateurs: old_admins) }
|
||||
let!(:instructeur) { create(:instructeur, email: 'i@mail.com', administrateurs: old_admins) }
|
||||
|
||||
before do
|
||||
User
|
||||
|
|
Loading…
Reference in a new issue