From 5b7085f7ceabc4194cc0f2a8cbca5611779abef7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 12 Feb 2018 14:24:11 +0100 Subject: [PATCH 01/14] Use overwind instead of hivemind --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 72098fa29..ee05fa6d3 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ Téléprocédures Simplifiées, ou TPS pour les intimes, est une plateforme 100 ### Développement - Mailcatcher : `gem install mailcatcher` -- Hivemind : - * Mac : `brew install hivemind` - * Linux : voir https://github.com/DarthSim/hivemind#installation +- Overmind : + * Mac : `brew install overmind` + * Linux : voir https://github.com/DarthSim/overmind#installation ### Tests @@ -89,7 +89,7 @@ client_secret: '' ## Lancement de l'application - hivemind + overmind ## Programmation des jobs @@ -117,6 +117,12 @@ Pour exécuter les tests de l'application, plusieurs possibilités : rake spec SPEC=file_path/file_name_spec.rb rspec file_path/file_name_spec.rb +## Debug + +Une fois `overmind` lancé, et un breakpoint `byebug` inséré dans le code, il faut se connecter au process `server` dans un nouveau terminal afin d'intéragir avec byebug : + + overmind connect server + ## Linting - Faire tourner RuboCop : `bundle exec rubocop` From 160b4e78c7b1599c3945ddfccbbe3beb7ffc97f9 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 8 Feb 2018 17:38:01 +0100 Subject: [PATCH 02/14] Update schema.rb --- db/schema.rb | 612 +++++++++++++++++++++++++-------------------------- 1 file changed, 303 insertions(+), 309 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 76daf76cd..320d92dc2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,467 +10,461 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180206153121) do +ActiveRecord::Schema.define(version: 2018_02_06_153121) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "unaccent" - create_table "administrateurs", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + create_table "administrateurs", id: :serial, force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" - t.string "api_token" - t.boolean "active", default: false - t.index ["email"], name: "index_administrateurs_on_email", unique: true, using: :btree - t.index ["reset_password_token"], name: "index_administrateurs_on_reset_password_token", unique: true, using: :btree + t.string "api_token" + t.boolean "active", default: false + t.index ["email"], name: "index_administrateurs_on_email", unique: true + t.index ["reset_password_token"], name: "index_administrateurs_on_reset_password_token", unique: true end create_table "administrateurs_gestionnaires", id: false, force: :cascade do |t| t.integer "administrateur_id" t.integer "gestionnaire_id" - t.index ["administrateur_id"], name: "index_administrateurs_gestionnaires_on_administrateur_id", using: :btree - t.index ["gestionnaire_id", "administrateur_id"], name: "unique_couple_administrateur_gestionnaire", unique: true, using: :btree - t.index ["gestionnaire_id"], name: "index_administrateurs_gestionnaires_on_gestionnaire_id", using: :btree + t.index ["administrateur_id"], name: "index_administrateurs_gestionnaires_on_administrateur_id" + t.index ["gestionnaire_id", "administrateur_id"], name: "unique_couple_administrateur_gestionnaire", unique: true + t.index ["gestionnaire_id"], name: "index_administrateurs_gestionnaires_on_gestionnaire_id" end - create_table "administrations", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + create_table "administrations", id: :serial, force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" - t.index ["email"], name: "index_administrations_on_email", unique: true, using: :btree - t.index ["reset_password_token"], name: "index_administrations_on_reset_password_token", unique: true, using: :btree + t.index ["email"], name: "index_administrations_on_email", unique: true + t.index ["reset_password_token"], name: "index_administrations_on_reset_password_token", unique: true end - create_table "ar_internal_metadata", primary_key: "key", id: :string, force: :cascade do |t| - t.string "value" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "assign_tos", force: :cascade do |t| + create_table "assign_tos", id: :serial, 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 - t.index ["procedure_id"], name: "index_assign_tos_on_procedure_id", using: :btree + t.index ["gestionnaire_id"], name: "index_assign_tos_on_gestionnaire_id" + t.index ["procedure_id"], name: "index_assign_tos_on_procedure_id" end - create_table "attestation_templates", force: :cascade do |t| - t.text "title" - t.text "body" - t.text "footer" - t.string "logo" - t.string "signature" - t.boolean "activated" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "procedure_id" - t.string "logo_secure_token" - t.string "signature_secure_token" - t.index ["procedure_id"], name: "index_attestation_templates_on_procedure_id", unique: true, using: :btree + create_table "attestation_templates", id: :serial, force: :cascade do |t| + t.text "title" + t.text "body" + t.text "footer" + t.string "logo" + t.string "signature" + t.boolean "activated" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "procedure_id" + t.string "logo_secure_token" + t.string "signature_secure_token" + t.index ["procedure_id"], name: "index_attestation_templates_on_procedure_id", unique: true end - create_table "attestations", force: :cascade do |t| - t.string "pdf" - t.string "title" - t.integer "dossier_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "content_secure_token" - t.index ["dossier_id"], name: "index_attestations_on_dossier_id", using: :btree + create_table "attestations", id: :serial, force: :cascade do |t| + t.string "pdf" + t.string "title" + t.integer "dossier_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "content_secure_token" + t.index ["dossier_id"], name: "index_attestations_on_dossier_id" end - create_table "avis", force: :cascade do |t| - t.string "email" - t.text "introduction" - t.text "answer" - t.integer "gestionnaire_id" - t.integer "dossier_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "claimant_id", null: false - t.boolean "confidentiel", default: false, null: false - t.index ["claimant_id"], name: "index_avis_on_claimant_id", using: :btree - t.index ["dossier_id"], name: "index_avis_on_dossier_id", using: :btree - t.index ["gestionnaire_id"], name: "index_avis_on_gestionnaire_id", using: :btree + create_table "avis", id: :serial, force: :cascade do |t| + t.string "email" + t.text "introduction" + t.text "answer" + t.integer "gestionnaire_id" + t.integer "dossier_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "claimant_id", null: false + t.boolean "confidentiel", default: false, null: false + t.index ["claimant_id"], name: "index_avis_on_claimant_id" + t.index ["dossier_id"], name: "index_avis_on_dossier_id" + t.index ["gestionnaire_id"], name: "index_avis_on_gestionnaire_id" end - create_table "cadastres", force: :cascade do |t| - t.string "surface_intersection" - t.float "surface_parcelle" - t.string "numero" + create_table "cadastres", id: :serial, force: :cascade do |t| + t.string "surface_intersection" + t.float "surface_parcelle" + t.string "numero" t.integer "feuille" - t.string "section" - t.string "code_dep" - t.string "nom_com" - t.string "code_com" - t.string "code_arr" - t.text "geometry" + t.string "section" + t.string "code_dep" + t.string "nom_com" + t.string "code_com" + t.string "code_arr" + t.text "geometry" t.integer "dossier_id" end - create_table "cerfas", force: :cascade do |t| - t.string "content" - t.integer "dossier_id" + create_table "cerfas", id: :serial, force: :cascade do |t| + t.string "content" + t.integer "dossier_id" t.datetime "created_at" - t.integer "user_id" - t.string "original_filename" - t.string "content_secure_token" - t.index ["dossier_id"], name: "index_cerfas_on_dossier_id", using: :btree + t.integer "user_id" + t.string "original_filename" + t.string "content_secure_token" + t.index ["dossier_id"], name: "index_cerfas_on_dossier_id" end - create_table "champs", force: :cascade do |t| - t.string "value" - t.integer "type_de_champ_id" - t.integer "dossier_id" - t.string "type" + create_table "champs", id: :serial, force: :cascade do |t| + t.string "value" + t.integer "type_de_champ_id" + t.integer "dossier_id" + t.string "type" t.datetime "created_at" t.datetime "updated_at" - t.index ["dossier_id"], name: "index_champs_on_dossier_id", using: :btree - t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id", using: :btree + t.index ["dossier_id"], name: "index_champs_on_dossier_id" + t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id" end - create_table "closed_mails", force: :cascade do |t| - t.text "body" - t.string "subject" - t.integer "procedure_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["procedure_id"], name: "index_closed_mails_on_procedure_id", using: :btree + create_table "closed_mails", id: :serial, force: :cascade do |t| + t.text "body" + t.string "subject" + t.integer "procedure_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["procedure_id"], name: "index_closed_mails_on_procedure_id" end - create_table "commentaires", force: :cascade do |t| - t.string "email" - t.datetime "created_at", null: false - t.string "body" - t.integer "dossier_id" - t.datetime "updated_at", null: false - t.integer "piece_justificative_id" - t.integer "champ_id" - t.string "file" - t.index ["champ_id"], name: "index_commentaires_on_champ_id", using: :btree - t.index ["dossier_id"], name: "index_commentaires_on_dossier_id", using: :btree + create_table "commentaires", id: :serial, force: :cascade do |t| + t.string "email" + t.datetime "created_at", null: false + t.string "body" + t.integer "dossier_id" + t.datetime "updated_at", null: false + t.integer "piece_justificative_id" + t.integer "champ_id" + t.string "file" + t.index ["champ_id"], name: "index_commentaires_on_champ_id" + t.index ["dossier_id"], name: "index_commentaires_on_dossier_id" end - create_table "delayed_jobs", force: :cascade do |t| - t.integer "priority", default: 0, null: false - t.integer "attempts", default: 0, null: false - t.text "handler", null: false - t.text "last_error" + create_table "delayed_jobs", id: :serial, force: :cascade do |t| + t.integer "priority", default: 0, null: false + t.integer "attempts", default: 0, null: false + t.text "handler", null: false + t.text "last_error" t.datetime "run_at" t.datetime "locked_at" t.datetime "failed_at" - t.string "locked_by" - t.string "queue" + t.string "locked_by" + t.string "queue" t.datetime "created_at" t.datetime "updated_at" - t.string "cron" - t.index ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree + t.string "cron" + t.index ["priority", "run_at"], name: "delayed_jobs_priority" end - create_table "dossiers", force: :cascade do |t| - t.boolean "autorisation_donnees" - t.integer "procedure_id" + create_table "dossiers", id: :serial, force: :cascade do |t| + t.boolean "autorisation_donnees" + t.integer "procedure_id" t.datetime "created_at" t.datetime "updated_at" - t.string "state" - t.integer "user_id" - t.text "json_latlngs" - t.boolean "archived", default: false - t.boolean "mandataire_social", default: false + t.string "state" + t.integer "user_id" + t.text "json_latlngs" + t.boolean "archived", default: false + t.boolean "mandataire_social", default: false t.datetime "en_construction_at" t.datetime "en_instruction_at" t.datetime "processed_at" - t.text "motivation" + t.text "motivation" t.datetime "hidden_at" - t.index ["hidden_at"], name: "index_dossiers_on_hidden_at", using: :btree - t.index ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree - t.index ["user_id"], name: "index_dossiers_on_user_id", using: :btree + t.index ["hidden_at"], name: "index_dossiers_on_hidden_at" + t.index ["procedure_id"], name: "index_dossiers_on_procedure_id" + t.index ["user_id"], name: "index_dossiers_on_user_id" end - create_table "drop_down_lists", force: :cascade do |t| - t.string "value" + create_table "drop_down_lists", id: :serial, force: :cascade do |t| + t.string "value" t.integer "type_de_champ_id" - t.index ["type_de_champ_id"], name: "index_drop_down_lists_on_type_de_champ_id", using: :btree + t.index ["type_de_champ_id"], name: "index_drop_down_lists_on_type_de_champ_id" end - create_table "entreprises", force: :cascade do |t| - t.string "siren" - t.integer "capital_social" - t.string "numero_tva_intracommunautaire" - t.string "forme_juridique" - t.string "forme_juridique_code" - t.string "nom_commercial" - t.string "raison_sociale" - t.string "siret_siege_social" - t.string "code_effectif_entreprise" + create_table "entreprises", id: :serial, force: :cascade do |t| + t.string "siren" + t.integer "capital_social" + t.string "numero_tva_intracommunautaire" + t.string "forme_juridique" + t.string "forme_juridique_code" + t.string "nom_commercial" + t.string "raison_sociale" + t.string "siret_siege_social" + t.string "code_effectif_entreprise" t.datetime "date_creation" - t.string "nom" - t.string "prenom" - t.integer "dossier_id" + t.string "nom" + t.string "prenom" + t.integer "dossier_id" t.datetime "created_at" t.datetime "updated_at" - t.index ["dossier_id"], name: "index_entreprises_on_dossier_id", using: :btree + t.index ["dossier_id"], name: "index_entreprises_on_dossier_id" end - create_table "etablissements", force: :cascade do |t| - t.string "siret" + create_table "etablissements", id: :serial, force: :cascade do |t| + t.string "siret" t.boolean "siege_social" - t.string "naf" - t.string "libelle_naf" - t.string "adresse" - t.string "numero_voie" - t.string "type_voie" - t.string "nom_voie" - t.string "complement_adresse" - t.string "code_postal" - t.string "localite" - t.string "code_insee_localite" + t.string "naf" + t.string "libelle_naf" + t.string "adresse" + t.string "numero_voie" + t.string "type_voie" + t.string "nom_voie" + t.string "complement_adresse" + t.string "code_postal" + t.string "localite" + t.string "code_insee_localite" t.integer "dossier_id" t.integer "entreprise_id" - t.index ["dossier_id"], name: "index_etablissements_on_dossier_id", using: :btree + t.index ["dossier_id"], name: "index_etablissements_on_dossier_id" end - create_table "exercices", force: :cascade do |t| - t.string "ca" + create_table "exercices", id: :serial, force: :cascade do |t| + t.string "ca" t.datetime "dateFinExercice" - t.integer "date_fin_exercice_timestamp" - t.integer "etablissement_id" + t.integer "date_fin_exercice_timestamp" + t.integer "etablissement_id" end - create_table "follows", force: :cascade do |t| - t.integer "gestionnaire_id", null: false - t.integer "dossier_id", null: false + create_table "follows", id: :serial, force: :cascade do |t| + t.integer "gestionnaire_id", null: false + t.integer "dossier_id", null: false t.datetime "demande_seen_at" t.datetime "annotations_privees_seen_at" t.datetime "avis_seen_at" t.datetime "messagerie_seen_at" - t.index ["dossier_id"], name: "index_follows_on_dossier_id", using: :btree - t.index ["gestionnaire_id", "dossier_id"], name: "index_follows_on_gestionnaire_id_and_dossier_id", unique: true, using: :btree - t.index ["gestionnaire_id"], name: "index_follows_on_gestionnaire_id", using: :btree + t.index ["dossier_id"], name: "index_follows_on_dossier_id" + t.index ["gestionnaire_id", "dossier_id"], name: "index_follows_on_gestionnaire_id_and_dossier_id", unique: true + t.index ["gestionnaire_id"], name: "index_follows_on_gestionnaire_id" end - create_table "france_connect_informations", force: :cascade do |t| - t.string "gender" - t.string "given_name" - t.string "family_name" - t.date "birthdate" - t.string "birthplace" - t.string "france_connect_particulier_id" + create_table "france_connect_informations", id: :serial, force: :cascade do |t| + t.string "gender" + t.string "given_name" + t.string "family_name" + t.date "birthdate" + t.string "birthplace" + t.string "france_connect_particulier_id" t.integer "user_id" - t.string "email_france_connect" - t.index ["user_id"], name: "index_france_connect_informations_on_user_id", using: :btree + t.string "email_france_connect" + t.index ["user_id"], name: "index_france_connect_informations_on_user_id" end - create_table "gestionnaires", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + create_table "gestionnaires", id: :serial, force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" - t.integer "procedure_filter" - t.index ["email"], name: "index_gestionnaires_on_email", unique: true, using: :btree - t.index ["reset_password_token"], name: "index_gestionnaires_on_reset_password_token", unique: true, using: :btree + t.integer "procedure_filter" + t.index ["email"], name: "index_gestionnaires_on_email", unique: true + t.index ["reset_password_token"], name: "index_gestionnaires_on_reset_password_token", unique: true end - create_table "individuals", force: :cascade do |t| - t.string "nom" - t.string "prenom" - t.string "birthdate" + create_table "individuals", id: :serial, force: :cascade do |t| + t.string "nom" + t.string "prenom" + t.string "birthdate" t.integer "dossier_id" - t.string "gender" - t.index ["dossier_id"], name: "index_individuals_on_dossier_id", using: :btree + t.string "gender" + t.index ["dossier_id"], name: "index_individuals_on_dossier_id" end - create_table "initiated_mails", force: :cascade do |t| - t.string "subject" - t.text "body" - t.integer "procedure_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["procedure_id"], name: "index_initiated_mails_on_procedure_id", using: :btree + create_table "initiated_mails", id: :serial, force: :cascade do |t| + t.string "subject" + t.text "body" + t.integer "procedure_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["procedure_id"], name: "index_initiated_mails_on_procedure_id" end - create_table "invites", force: :cascade do |t| - t.string "email" - t.string "email_sender" + create_table "invites", id: :serial, force: :cascade do |t| + t.string "email" + t.string "email_sender" t.integer "dossier_id" t.integer "user_id" - t.string "type", default: "InviteGestionnaire" + t.string "type", default: "InviteGestionnaire" end - create_table "module_api_cartos", force: :cascade do |t| + create_table "module_api_cartos", id: :serial, force: :cascade do |t| t.integer "procedure_id" - t.boolean "use_api_carto", default: false + t.boolean "use_api_carto", default: false t.boolean "quartiers_prioritaires", default: false - t.boolean "cadastre", default: false - t.index ["procedure_id"], name: "index_module_api_cartos_on_procedure_id", unique: true, using: :btree + t.boolean "cadastre", default: false + t.index ["procedure_id"], name: "index_module_api_cartos_on_procedure_id", unique: true end - create_table "pieces_justificatives", force: :cascade do |t| - t.string "content" - t.integer "dossier_id" - t.integer "type_de_piece_justificative_id" + create_table "pieces_justificatives", id: :serial, force: :cascade do |t| + t.string "content" + t.integer "dossier_id" + t.integer "type_de_piece_justificative_id" t.datetime "created_at" - t.integer "user_id" - t.string "original_filename" - t.string "content_secure_token" + t.integer "user_id" + t.string "original_filename" + t.string "content_secure_token" t.datetime "updated_at" - t.index ["dossier_id"], name: "index_pieces_justificatives_on_dossier_id", using: :btree - t.index ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree + t.index ["dossier_id"], name: "index_pieces_justificatives_on_dossier_id" + t.index ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id" end - create_table "procedure_paths", force: :cascade do |t| - t.string "path" + create_table "procedure_paths", id: :serial, force: :cascade do |t| + t.string "path" t.integer "procedure_id" t.integer "administrateur_id" - t.index ["path"], name: "index_procedure_paths_on_path", using: :btree + t.index ["path"], name: "index_procedure_paths_on_path" end - create_table "procedure_presentations", force: :cascade do |t| + create_table "procedure_presentations", id: :serial, force: :cascade do |t| t.integer "assign_to_id" - t.text "displayed_fields", default: ["{\"label\":\"Demandeur\",\"table\":\"user\",\"column\":\"email\"}"], null: false, array: true - t.json "sort", default: "{\"table\":\"notifications\",\"column\":\"notifications\",\"order\":\"desc\"}", null: false - t.json "filters", default: "{\"a-suivre\":[],\"suivis\":[],\"traites\":[],\"tous\":[],\"archives\":[]}", null: false - t.index ["assign_to_id"], name: "index_procedure_presentations_on_assign_to_id", unique: true, using: :btree + t.text "displayed_fields", default: ["{\"label\":\"Demandeur\",\"table\":\"user\",\"column\":\"email\"}"], null: false, array: true + t.json "sort", default: "{\"table\":\"notifications\",\"column\":\"notifications\",\"order\":\"desc\"}", null: false + t.json "filters", default: "{\"a-suivre\":[],\"suivis\":[],\"traites\":[],\"tous\":[],\"archives\":[]}", null: false + t.index ["assign_to_id"], name: "index_procedure_presentations_on_assign_to_id", unique: true end - create_table "procedures", force: :cascade do |t| - t.string "libelle" - t.string "description" - t.string "organisation", null: false - t.string "direction" - t.string "lien_demarche" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "administrateur_id" - t.boolean "euro_flag", default: false - t.string "logo" - t.boolean "cerfa_flag", default: false - t.string "logo_secure_token" - t.string "lien_site_web" - t.string "lien_notice" - t.boolean "for_individual", default: false - t.boolean "individual_with_siret", default: false - t.date "auto_archive_on" + create_table "procedures", id: :serial, force: :cascade do |t| + t.string "libelle" + t.string "description" + t.string "organisation", null: false + t.string "direction" + t.string "lien_demarche" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "administrateur_id" + t.boolean "euro_flag", default: false + t.string "logo" + t.boolean "cerfa_flag", default: false + t.string "logo_secure_token" + t.string "lien_site_web" + t.string "lien_notice" + t.boolean "for_individual", default: false + t.boolean "individual_with_siret", default: false + t.date "auto_archive_on" t.datetime "published_at" t.datetime "hidden_at" t.datetime "archived_at" t.datetime "whitelisted_at" - t.boolean "ask_birthday", default: false, null: false - t.index ["hidden_at"], name: "index_procedures_on_hidden_at", using: :btree + t.boolean "ask_birthday", default: false, null: false + t.index ["hidden_at"], name: "index_procedures_on_hidden_at" end - create_table "quartier_prioritaires", force: :cascade do |t| - t.string "code" - t.string "nom" - t.string "commune" - t.text "geometry" + create_table "quartier_prioritaires", id: :serial, force: :cascade do |t| + t.string "code" + t.string "nom" + t.string "commune" + t.text "geometry" t.integer "dossier_id" end - create_table "received_mails", force: :cascade do |t| - t.text "body" - t.string "subject" - t.integer "procedure_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["procedure_id"], name: "index_received_mails_on_procedure_id", using: :btree + create_table "received_mails", id: :serial, force: :cascade do |t| + t.text "body" + t.string "subject" + t.integer "procedure_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["procedure_id"], name: "index_received_mails_on_procedure_id" end - create_table "refused_mails", force: :cascade do |t| - t.text "body" - t.string "subject" - t.integer "procedure_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["procedure_id"], name: "index_refused_mails_on_procedure_id", using: :btree + create_table "refused_mails", id: :serial, force: :cascade do |t| + t.text "body" + t.string "subject" + t.integer "procedure_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["procedure_id"], name: "index_refused_mails_on_procedure_id" end - create_table "rna_informations", force: :cascade do |t| - t.string "association_id" - t.string "titre" - t.text "objet" - t.date "date_creation" - t.date "date_declaration" - t.date "date_publication" + create_table "rna_informations", id: :serial, force: :cascade do |t| + t.string "association_id" + t.string "titre" + t.text "objet" + t.date "date_creation" + t.date "date_declaration" + t.date "date_publication" t.integer "entreprise_id" - t.index ["entreprise_id"], name: "index_rna_informations_on_entreprise_id", using: :btree + t.index ["entreprise_id"], name: "index_rna_informations_on_entreprise_id" end - create_table "types_de_champ", force: :cascade do |t| - t.string "libelle" - t.string "type_champ" + create_table "types_de_champ", id: :serial, force: :cascade do |t| + t.string "libelle" + t.string "type_champ" t.integer "order_place" t.integer "procedure_id" - t.text "description" - t.boolean "mandatory", default: false - t.string "type" + t.text "description" + t.boolean "mandatory", default: false + t.string "type" end - create_table "types_de_piece_justificative", force: :cascade do |t| - t.string "libelle" - t.string "description" - t.boolean "api_entreprise", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "procedure_id" - t.integer "order_place" - t.string "lien_demarche" - t.boolean "mandatory", default: false + create_table "types_de_piece_justificative", id: :serial, force: :cascade do |t| + t.string "libelle" + t.string "description" + t.boolean "api_entreprise", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "procedure_id" + t.integer "order_place" + t.string "lien_demarche" + t.boolean "mandatory", default: false end - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + create_table "users", id: :serial, force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" - t.string "siret" - t.string "loged_in_with_france_connect", default: "false" - t.index ["email"], name: "index_users_on_email", unique: true, using: :btree - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + t.string "siret" + t.string "loged_in_with_france_connect", default: "false" + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end - create_table "without_continuation_mails", force: :cascade do |t| - t.text "body" - t.string "subject" - t.integer "procedure_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["procedure_id"], name: "index_without_continuation_mails_on_procedure_id", using: :btree + create_table "without_continuation_mails", id: :serial, force: :cascade do |t| + t.text "body" + t.string "subject" + t.integer "procedure_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["procedure_id"], name: "index_without_continuation_mails_on_procedure_id" end add_foreign_key "attestation_templates", "procedures" @@ -488,7 +482,7 @@ ActiveRecord::Schema.define(version: 20180206153121) do add_foreign_key "refused_mails", "procedures" add_foreign_key "without_continuation_mails", "procedures" - create_view :searches, sql_definition: <<-SQL + create_view "searches", sql_definition: <<-SQL SELECT dossiers.id AS dossier_id, (((((((((((((((((((((((((((((((((((((((((((((((((((((((COALESCE(users.email, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.given_name, ''::character varying))::text) || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) || ' '::text) || (COALESCE(cerfas.content, ''::character varying))::text) || ' '::text) || (COALESCE(champs.value, ''::character varying))::text) || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siren, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.association_id, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.titre, ''::character varying))::text) || ' '::text) || COALESCE(rna_informations.objet, ''::text)) || ' '::text) || (COALESCE(etablissements.siret, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.nom, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(pieces_justificatives.content, ''::character varying))::text) AS term FROM ((((((((((dossiers From 9105e4e3f749c09ab74b0b96c7399f39a470ceaa Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 7 Feb 2018 20:40:15 +0100 Subject: [PATCH 03/14] [Fix #1403] Apply dossier index style to recherche --- .../recherche/index.html.haml | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/app/views/new_gestionnaire/recherche/index.html.haml b/app/views/new_gestionnaire/recherche/index.html.haml index 87a54eb34..ccd7f4f45 100644 --- a/app/views/new_gestionnaire/recherche/index.html.haml +++ b/app/views/new_gestionnaire/recherche/index.html.haml @@ -9,23 +9,26 @@ %table.table.dossiers-table.hoverable %thead %tr - %th Nº + %th.notification-col + %th.number-col Nº dossier %th Procédure %th Demandeur - %th Statut + %th.status-col Statut %tbody - - @dossiers.each do |dossier| - / # FIXME: here we have a n+1, we fire a request - / (due to dossier_linked_path) per result - %tr - %td.number-col - = link_to(dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') do - %span.icon.folder> - = dossier.id - %td= link_to(dossier.procedure.libelle, dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') - %td= link_to(dossier.user.email, dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') - %td.status-col - = link_to(dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') do - = render partial: 'new_gestionnaire/procedures/status', locals: { dossier: dossier } + - @dossiers.each do |dossier| + / # FIXME: here we have a n+1, we fire a request + / (due to dossier_linked_path) per result + %tr + %td.folder-col + = link_to(dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') do + %span.icon.folder + %td.number-col + = link_to(dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') do + = dossier.id + %td= link_to(dossier.procedure.libelle, dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') + %td= link_to(dossier.user.email, dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') + %td.status-col + = link_to(dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') do + = render partial: 'new_gestionnaire/procedures/status', locals: { dossier: dossier } - else %h2 Aucun dossier correspondant à votre recherche n'a été trouvé From 5398864609bfe31f9f36029d690318b8fb770ed3 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 7 Feb 2018 20:40:15 +0100 Subject: [PATCH 04/14] Whole line should be clickable --- app/views/new_gestionnaire/procedures/show.html.haml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml index 78c7668d2..2e334e972 100644 --- a/app/views/new_gestionnaire/procedures/show.html.haml +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -94,9 +94,10 @@ - @dossiers.each do |dossier| %tr %td.folder-col - %span.icon.folder - - if current_gestionnaire.notifications_for_procedure(@procedure).include?(dossier.id) - %span.notifications{ 'aria-label': 'notifications' } + = link_to(dossier_path(@procedure, dossier), class: 'cell-link') do + %span.icon.folder + - if current_gestionnaire.notifications_for_procedure(@procedure).include?(dossier.id) + %span.notifications{ 'aria-label': 'notifications' } %td.number-col = link_to(dossier_path(@procedure, dossier), class: 'cell-link') do From ffe3fe3db2129421f4292f39270505ca5797402c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 13 Feb 2018 11:12:15 +0100 Subject: [PATCH 05/14] The overmind command was incorrect --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ee05fa6d3..1da3805cd 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ client_secret: '' ## Lancement de l'application - overmind + overmind s ## Programmation des jobs From 52749713ab252200b354a92b06aa687a68a9b186 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 9 Feb 2018 17:38:30 +0100 Subject: [PATCH 06/14] Remove ChampPublic/ChampPrivate STI --- app/controllers/root_controller.rb | 6 +---- app/models/champ.rb | 14 +++++++++- app/models/champ_private.rb | 2 -- app/models/champ_public.rb | 2 -- app/models/dossier.rb | 12 +++------ app/models/procedure.rb | 4 +++ app/models/type_de_champ.rb | 26 ++++++++++++++++++- app/serializers/champ_private_serializer.rb | 5 ---- app/serializers/champ_public_serializer.rb | 5 ---- app/serializers/champ_serializer.rb | 5 ++++ .../admin/types_de_champ/_fields.html.haml | 2 +- .../dossiers_controller_spec.rb | 6 ++--- spec/models/champ_private_spec.rb | 10 ++++--- spec/models/champ_public_spec.rb | 7 ----- spec/models/champ_shared_example.rb | 6 ++--- spec/models/champ_spec.rb | 18 +++++++++---- 16 files changed, 78 insertions(+), 52 deletions(-) delete mode 100644 app/models/champ_private.rb delete mode 100644 app/models/champ_public.rb delete mode 100644 app/serializers/champ_private_serializer.rb delete mode 100644 app/serializers/champ_public_serializer.rb create mode 100644 app/serializers/champ_serializer.rb delete mode 100644 spec/models/champ_public_spec.rb diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index aa78ee3d0..febfb25d1 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -20,11 +20,7 @@ class RootController < ApplicationController all_champs = TypeDeChamp.type_champs .map { |name, _| TypeDeChamp.new(type_champ: name, libelle: name, description: description, mandatory: true) } - .map { |type_de_champ| ChampPublic.new(type_de_champ: type_de_champ) } - .map.with_index do |champ, i| - champ.id = i - champ - end + .map.with_index { |type_de_champ, i| type_de_champ.champ.build(id: i) } all_champs .select { |champ| champ.type_champ == 'header_section' } diff --git a/app/models/champ.rb b/app/models/champ.rb index e4e1555b8..65f53ee9b 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -1,6 +1,8 @@ class Champ < ActiveRecord::Base + self.inheritance_column = :_type_disabled + belongs_to :dossier, touch: true - belongs_to :type_de_champ + belongs_to :type_de_champ, inverse_of: :champ has_many :commentaires delegate :libelle, :type_champ, :order_place, :mandatory, :description, :drop_down_list, to: :type_de_champ @@ -10,11 +12,21 @@ class Champ < ActiveRecord::Base before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' } scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) } + scope :public_only, -> { where('champs.type != ?', 'ChampPrivate') } + scope :private_only, -> { where(type: 'ChampPrivate') } def mandatory? mandatory end + def public? + !private? + end + + def private? + type == 'ChampPrivate' + end + def same_hour? num same_date? num, '%H' end diff --git a/app/models/champ_private.rb b/app/models/champ_private.rb deleted file mode 100644 index 118e58415..000000000 --- a/app/models/champ_private.rb +++ /dev/null @@ -1,2 +0,0 @@ -class ChampPrivate < Champ -end diff --git a/app/models/champ_public.rb b/app/models/champ_public.rb deleted file mode 100644 index c922614ae..000000000 --- a/app/models/champ_public.rb +++ /dev/null @@ -1,2 +0,0 @@ -class ChampPublic < Champ -end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 6c09b5328..5fede6a93 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -20,8 +20,8 @@ class Dossier < ActiveRecord::Base has_many :cerfa, dependent: :destroy has_many :pieces_justificatives, dependent: :destroy - has_many :champs, class_name: 'ChampPublic', dependent: :destroy - has_many :champs_private, class_name: 'ChampPrivate', dependent: :destroy + has_many :champs, -> { public_only }, dependent: :destroy + has_many :champs_private, -> { private_only }, class_name: 'Champ', dependent: :destroy has_many :quartier_prioritaires, dependent: :destroy has_many :cadastres, dependent: :destroy has_many :commentaires, dependent: :destroy @@ -89,12 +89,8 @@ class Dossier < ActiveRecord::Base end def build_default_champs - procedure.types_de_champ.all.each do |type_de_champ| - ChampPublic.create(type_de_champ: type_de_champ, dossier: self) - end - - procedure.types_de_champ_private.all.each do |type_de_champ| - ChampPrivate.create(type_de_champ: type_de_champ, dossier: self) + procedure.all_types_de_champ.each do |type_de_champ| + type_de_champ.champ.create(dossier: self) end end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 0d81f0a3a..7cf0c3d67 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -62,6 +62,10 @@ class Procedure < ActiveRecord::Base types_de_champ_private.order(:order_place) end + def all_types_de_champ + types_de_champ + types_de_champ_private + end + def self.active id publiees.find(id) end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 86747bc5a..aed2c6225 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -24,7 +24,23 @@ class TypeDeChamp < ActiveRecord::Base belongs_to :procedure - has_many :champ, dependent: :destroy + has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do + def build_params(params) + if proxy_association.owner.public? + params.merge(type: 'ChampPublic') + else + params.merge(type: 'ChampPrivate') + end + end + + def build(params = {}) + super(build_params(params)) + end + + def create(params = {}) + super(build_params(params)) + end + end has_one :drop_down_list accepts_nested_attributes_for :drop_down_list @@ -46,4 +62,12 @@ class TypeDeChamp < ActiveRecord::Base self.mandatory = false if %w(header_section explication).include?(self.type_champ) true end + + def private? + type == 'TypeDeChampPrivate' + end + + def public? + !private? + end end diff --git a/app/serializers/champ_private_serializer.rb b/app/serializers/champ_private_serializer.rb deleted file mode 100644 index b26cf274f..000000000 --- a/app/serializers/champ_private_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ChampPrivateSerializer < ActiveModel::Serializer - attributes :value - - has_one :type_de_champ -end diff --git a/app/serializers/champ_public_serializer.rb b/app/serializers/champ_public_serializer.rb deleted file mode 100644 index 66806c982..000000000 --- a/app/serializers/champ_public_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ChampPublicSerializer < ActiveModel::Serializer - attributes :value - - has_one :type_de_champ -end diff --git a/app/serializers/champ_serializer.rb b/app/serializers/champ_serializer.rb new file mode 100644 index 000000000..981c2b9cc --- /dev/null +++ b/app/serializers/champ_serializer.rb @@ -0,0 +1,5 @@ +class ChampSerializer < ActiveModel::Serializer + attributes :value + + has_one :type_de_champ +end diff --git a/app/views/admin/types_de_champ/_fields.html.haml b/app/views/admin/types_de_champ/_fields.html.haml index 9e651454b..bbadc32d8 100644 --- a/app/views/admin/types_de_champ/_fields.html.haml +++ b/app/views/admin/types_de_champ/_fields.html.haml @@ -21,7 +21,7 @@ = fff.hidden_field :id - - hide_mandatory = (ff.object.object.class == TypeDeChampPrivate || type_champ == 'explication') + - hide_mandatory = (ff.object.object.private? || type_champ == 'explication') .form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil } %h4 Obligatoire ? .center diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index 04d9586f2..5a08115b3 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -355,13 +355,11 @@ describe NewGestionnaire::DossiersController, type: :controller do describe "#update_annotations" do let(:champ_multiple_drop_down_list) do - type_de_champ = TypeDeChamp.create(type_champ: 'multiple_drop_down_list', libelle: 'libelle') - ChampPrivate.create(type_de_champ: type_de_champ) + create(:type_de_champ_private, type_champ: 'multiple_drop_down_list', libelle: 'libelle').champ.create end let(:champ_datetime) do - type_de_champ = TypeDeChamp.create(type_champ: 'datetime', libelle: 'libelle') - ChampPrivate.create(type_de_champ: type_de_champ) + create(:type_de_champ_private, type_champ: 'datetime', libelle: 'libelle').champ.create end let(:dossier) do diff --git a/spec/models/champ_private_spec.rb b/spec/models/champ_private_spec.rb index 733505696..5e3dee9af 100644 --- a/spec/models/champ_private_spec.rb +++ b/spec/models/champ_private_spec.rb @@ -1,7 +1,11 @@ require 'spec_helper' -describe ChampPrivate do - require 'models/champ_shared_example.rb' +describe Champ do + describe '#private?' do + let(:type_de_champ) { build(:type_de_champ_private) } + let(:champ) { type_de_champ.champ.build } - it_should_behave_like "champ_spec" + it { expect(champ.private?).to be_truthy } + it { expect(champ.public?).to be_falsey } + end end diff --git a/spec/models/champ_public_spec.rb b/spec/models/champ_public_spec.rb deleted file mode 100644 index a981702c7..000000000 --- a/spec/models/champ_public_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -describe ChampPublic do - require 'models/champ_shared_example.rb' - - it_should_behave_like "champ_spec" -end diff --git a/spec/models/champ_shared_example.rb b/spec/models/champ_shared_example.rb index 60dc38e9a..6c42ed032 100644 --- a/spec/models/champ_shared_example.rb +++ b/spec/models/champ_shared_example.rb @@ -1,7 +1,7 @@ shared_examples 'champ_spec' do describe 'mandatory_and_blank?' do - let(:type_de_champ) { TypeDeChamp.new(mandatory: mandatory) } - let(:champ) { Champ.new(type_de_champ: type_de_champ, value: value) } + let(:type_de_champ) { build(:type_de_champ_public, mandatory: mandatory) } + let(:champ) { type_de_champ.champ.build(value: value) } let(:value) { '' } let(:mandatory) { true } @@ -34,7 +34,7 @@ shared_examples 'champ_spec' do context "when type_champ=date" do let(:type_de_champ) { create(:type_de_champ_public, type_champ: "date") } - let(:champ) { create(:champ, type_de_champ: type_de_champ) } + let(:champ) { type_de_champ.champ.create } it "should convert %d/%m/%Y format to ISO" do champ.value = "31/12/2017" diff --git a/spec/models/champ_spec.rb b/spec/models/champ_spec.rb index 6085a5719..f56a0f390 100644 --- a/spec/models/champ_spec.rb +++ b/spec/models/champ_spec.rb @@ -5,9 +5,17 @@ describe Champ do it_should_behave_like "champ_spec" + describe '#public?' do + let(:type_de_champ) { build(:type_de_champ_public) } + let(:champ) { type_de_champ.champ.build } + + it { expect(champ.public?).to be_truthy } + it { expect(champ.private?).to be_falsey } + end + describe '#format_datetime' do - let(:type_de_champ) { TypeDeChamp.new(type_champ: 'datetime') } - let(:champ) { Champ.new(type_de_champ: type_de_champ, value: value) } + let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'datetime') } + let(:champ) { type_de_champ.champ.build(value: value) } before { champ.save } @@ -25,8 +33,8 @@ describe Champ do end describe '#multiple_select_to_string' do - let(:type_de_champ) { TypeDeChamp.new(type_champ: 'multiple_drop_down_list') } - let(:champ) { Champ.new(type_de_champ: type_de_champ, value: value) } + let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'multiple_drop_down_list') } + let(:champ) { type_de_champ.champ.build(value: value) } before { champ.save } @@ -64,7 +72,7 @@ describe Champ do describe 'for_export' do let(:type_de_champ) { create(:type_de_champ_public, type_champ: type_champ) } - let(:champ) { Champ.new(type_de_champ: type_de_champ, value: value) } + let(:champ) { type_de_champ.champ.build(value: value) } before { champ.save } From 2e4ada98e675c83bd1f82866ffb42030d31ffc89 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 9 Feb 2018 17:21:46 +0100 Subject: [PATCH 07/14] Add private columns to Champ and TypeDeChamp --- app/models/champ.rb | 6 +++--- app/models/type_de_champ.rb | 18 ++++++++---------- ...2_add_private_to_champ_and_type_de_champ.rb | 11 +++++++++++ db/schema.rb | 6 +++++- 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20180209133452_add_private_to_champ_and_type_de_champ.rb diff --git a/app/models/champ.rb b/app/models/champ.rb index 65f53ee9b..4daf0e05d 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -12,8 +12,8 @@ class Champ < ActiveRecord::Base before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' } scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) } - scope :public_only, -> { where('champs.type != ?', 'ChampPrivate') } - scope :private_only, -> { where(type: 'ChampPrivate') } + scope :public_only, -> { where.not(type: 'ChampPrivate').or(where(private: [false, nil])) } + scope :private_only, -> { where(type: 'ChampPrivate').or(where(private: true)) } def mandatory? mandatory @@ -24,7 +24,7 @@ class Champ < ActiveRecord::Base end def private? - type == 'ChampPrivate' + super || type == 'ChampPrivate' end def same_hour? num diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index aed2c6225..4a792d1cd 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -25,20 +25,12 @@ class TypeDeChamp < ActiveRecord::Base belongs_to :procedure has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do - def build_params(params) - if proxy_association.owner.public? - params.merge(type: 'ChampPublic') - else - params.merge(type: 'ChampPrivate') - end - end - def build(params = {}) - super(build_params(params)) + super(params.merge(proxy_association.owner.params_for_champ)) end def create(params = {}) - super(build_params(params)) + super(params.merge(proxy_association.owner.params_for_champ)) end end has_one :drop_down_list @@ -50,6 +42,12 @@ class TypeDeChamp < ActiveRecord::Base before_validation :check_mandatory + def params_for_champ + { + private: private? + } + end + def self.type_de_champs_list_fr type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] } end diff --git a/db/migrate/20180209133452_add_private_to_champ_and_type_de_champ.rb b/db/migrate/20180209133452_add_private_to_champ_and_type_de_champ.rb new file mode 100644 index 000000000..5feb76084 --- /dev/null +++ b/db/migrate/20180209133452_add_private_to_champ_and_type_de_champ.rb @@ -0,0 +1,11 @@ +class AddPrivateToChampAndTypeDeChamp < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def change + add_column :champs, :private, :boolean, index: true + add_column :types_de_champ, :private, :boolean, index: true + + add_index :champs, :private, algorithm: :concurrently + add_index :types_de_champ, :private, algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 320d92dc2..8db9e6a21 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_02_06_153121) do +ActiveRecord::Schema.define(version: 2018_02_09_133452) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -138,7 +138,9 @@ ActiveRecord::Schema.define(version: 2018_02_06_153121) do t.string "type" t.datetime "created_at" t.datetime "updated_at" + t.boolean "private" t.index ["dossier_id"], name: "index_champs_on_dossier_id" + t.index ["private"], name: "index_champs_on_private" t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id" end @@ -425,6 +427,8 @@ ActiveRecord::Schema.define(version: 2018_02_06_153121) do t.text "description" t.boolean "mandatory", default: false t.string "type" + t.boolean "private" + t.index ["private"], name: "index_types_de_champ_on_private" end create_table "types_de_piece_justificative", id: :serial, force: :cascade do |t| From f80a9466b9289877b67a5c892c008731cd255527 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 9 Feb 2018 17:42:53 +0100 Subject: [PATCH 08/14] Delegate `mandatory?` to `type_de_champ` --- app/models/champ.rb | 6 +----- .../dossiers/editable_champs/_address.html.haml | 2 +- .../dossiers/editable_champs/_champ_label.html.haml | 2 +- .../dossiers/editable_champs/_checkbox.html.haml | 2 +- .../dossiers/editable_champs/_date.html.haml | 2 +- .../dossiers/editable_champs/_departements.html.haml | 2 +- .../dossiers/editable_champs/_dossier_link.html.haml | 2 +- .../dossiers/editable_champs/_drop_down_list.html.haml | 2 +- .../dossiers/editable_champs/_email.html.haml | 2 +- .../dossiers/editable_champs/_engagement.html.haml | 2 +- .../dossiers/editable_champs/_number.html.haml | 2 +- .../dossiers/editable_champs/_pays.html.haml | 2 +- .../dossiers/editable_champs/_phone.html.haml | 2 +- .../dossiers/editable_champs/_regions.html.haml | 2 +- .../dossiers/editable_champs/_text.html.haml | 2 +- .../dossiers/editable_champs/_textarea.html.haml | 2 +- 16 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app/models/champ.rb b/app/models/champ.rb index 4daf0e05d..4cbb7a48b 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -5,7 +5,7 @@ class Champ < ActiveRecord::Base belongs_to :type_de_champ, inverse_of: :champ has_many :commentaires - delegate :libelle, :type_champ, :order_place, :mandatory, :description, :drop_down_list, to: :type_de_champ + delegate :libelle, :type_champ, :order_place, :mandatory?, :description, :drop_down_list, to: :type_de_champ before_save :format_date_to_iso, if: Proc.new { type_champ == 'date' } before_save :format_datetime, if: Proc.new { type_champ == 'datetime' } @@ -15,10 +15,6 @@ class Champ < ActiveRecord::Base scope :public_only, -> { where.not(type: 'ChampPrivate').or(where(private: [false, nil])) } scope :private_only, -> { where(type: 'ChampPrivate').or(where(private: true)) } - def mandatory? - mandatory - end - def public? !private? end diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_address.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_address.html.haml index 24ee6b39b..19a5a9e52 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_address.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_address.html.haml @@ -1,4 +1,4 @@ = form.text_field :value, 'data-address': 'true', placeholder: champ.libelle, - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_champ_label.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_champ_label.html.haml index a75334b35..38749d6da 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_champ_label.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_champ_label.html.haml @@ -1,6 +1,6 @@ = form.label :value do #{champ.libelle} - - if champ.mandatory + - if champ.mandatory? %span.mandatory * - if champ.updated_at.present? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_checkbox.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_checkbox.html.haml index 3dfe83c16..5bd197a73 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_checkbox.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_checkbox.html.haml @@ -1,5 +1,5 @@ = form.check_box :value, - { required: champ.mandatory }, + { required: champ.mandatory? }, 'on', 'off' diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_date.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_date.html.haml index 40794faef..b20444520 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_date.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_date.html.haml @@ -1,4 +1,4 @@ = form.date_field :value, value: champ.value, placeholder: 'JJ/MM/AAAA', - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_departements.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_departements.html.haml index 790e22f07..90c2ca408 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_departements.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_departements.html.haml @@ -1,3 +1,3 @@ = form.select :value, Champ.departements, - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_dossier_link.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_dossier_link.html.haml index 924cdc78e..53ca52c5c 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_dossier_link.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_dossier_link.html.haml @@ -8,7 +8,7 @@ placeholder: "Numéro de dossier", autocomplete: 'off', 'data-type': 'dossier-link', - required: champ.mandatory + required: champ.mandatory? .help-block %p.text-info{ style: show_text_summary ? nil : 'display: none;' } diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_drop_down_list.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_drop_down_list.html.haml index fbe889285..05b938cfc 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_drop_down_list.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_drop_down_list.html.haml @@ -2,4 +2,4 @@ = form.select :value, champ.drop_down_list.options, disabled: champ.drop_down_list.disabled_options, - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_email.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_email.html.haml index 8cdac1a75..ce589db77 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_email.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_email.html.haml @@ -1,3 +1,3 @@ = form.email_field :value, placeholder: champ.libelle, - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_engagement.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_engagement.html.haml index 3dfe83c16..5bd197a73 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_engagement.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_engagement.html.haml @@ -1,5 +1,5 @@ = form.check_box :value, - { required: champ.mandatory }, + { required: champ.mandatory? }, 'on', 'off' diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_number.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_number.html.haml index 956daca53..d5aab710a 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_number.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_number.html.haml @@ -1,3 +1,3 @@ = form.number_field :value, placeholder: champ.libelle, - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_pays.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_pays.html.haml index 678a06eff..cdc2e489d 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_pays.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_pays.html.haml @@ -1,3 +1,3 @@ = form.select :value, Champ.pays, - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_phone.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_phone.html.haml index 32f36f5f8..00ff6f5c6 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_phone.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_phone.html.haml @@ -1,3 +1,3 @@ = form.phone_field :value, placeholder: champ.libelle, - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_regions.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_regions.html.haml index 24863e110..b947a8d31 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_regions.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_regions.html.haml @@ -1,3 +1,3 @@ = form.select :value, Champ.regions, - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_text.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_text.html.haml index 6134a07b1..2b5d10584 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_text.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_text.html.haml @@ -1,3 +1,3 @@ = form.text_field :value, placeholder: champ.libelle, - required: champ.mandatory + required: champ.mandatory? diff --git a/app/views/new_gestionnaire/dossiers/editable_champs/_textarea.html.haml b/app/views/new_gestionnaire/dossiers/editable_champs/_textarea.html.haml index 5f67724f5..c1bac654c 100644 --- a/app/views/new_gestionnaire/dossiers/editable_champs/_textarea.html.haml +++ b/app/views/new_gestionnaire/dossiers/editable_champs/_textarea.html.haml @@ -1,5 +1,5 @@ ~ form.text_area :value, row: 6, placeholder: champ.description, - required: champ.mandatory, + required: champ.mandatory?, value: html_to_string(champ.value) From 793768684e8d8d1dd4e1b5a5d36ffaf83f22fe1c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 9 Feb 2018 17:46:40 +0100 Subject: [PATCH 09/14] =?UTF-8?q?Checkbox=20should=20take=20a=20=E2=80=9Co?= =?UTF-8?q?n=E2=80=9D=20not=20=E2=80=9Ctrue=E2=80=9D=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb b/spec/views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb index 21925c3f9..05a2e22d2 100644 --- a/spec/views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb +++ b/spec/views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb @@ -13,7 +13,7 @@ describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do context "there are some champs" do let(:dossier) { create(:dossier) } let(:avis) { create :avis, dossier: dossier, gestionnaire: gestionnaire } - let(:champ1) { create(:champ, :checkbox, value: "true") } + let(:champ1) { create(:champ, :checkbox, value: "on") } let(:champ2) { create(:champ, :header_section, value: "Section") } let(:champ3) { create(:champ, :explication, value: "mazette") } let(:champ4) { create(:champ, :dossier_link, value: dossier.id) } @@ -53,7 +53,7 @@ describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do context "with seen_at" do let(:dossier) { create(:dossier) } - let(:champ1) { create(:champ, :checkbox, value: "true") } + let(:champ1) { create(:champ, :checkbox, value: "on") } let(:champs) { [champ1] } context "with a demande_seen_at after champ updated_at" do From 0c10f2bd47482e58942a6b1c41b116b5dce1704b Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 9 Feb 2018 17:50:10 +0100 Subject: [PATCH 10/14] Always use factories in spec --- spec/models/drop_down_list_spec.rb | 8 ++++---- spec/services/champs_service_spec.rb | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/models/drop_down_list_spec.rb b/spec/models/drop_down_list_spec.rb index b898201db..3f01f7148 100644 --- a/spec/models/drop_down_list_spec.rb +++ b/spec/models/drop_down_list_spec.rb @@ -47,16 +47,16 @@ describe DropDownList do end context 'when multiple' do - let(:type_de_champ) { TypeDeChamp.new(type_champ: 'multiple_drop_down_list') } + let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'multiple_drop_down_list') } + let(:champ) { type_de_champ.champ.build(value: '["1","2"]').decorate } - let(:champ) { Champ.new(value: '["1","2"]').decorate } it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) } end context 'when simple' do - let(:type_de_champ) { TypeDeChamp.new(type_champ: 'drop_down_list') } + let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'drop_down_list') } + let(:champ) { type_de_champ.champ.build(value: '1').decorate } - let(:champ) { Champ.new(value: '1').decorate } it { expect(dropdownlist.selected_options(champ)).to match(['1']) } end end diff --git a/spec/services/champs_service_spec.rb b/spec/services/champs_service_spec.rb index 2912da0e9..108596113 100644 --- a/spec/services/champs_service_spec.rb +++ b/spec/services/champs_service_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' describe ChampsService do - let!(:champ) { Champ.create(value: 'toto', type_de_champ: TypeDeChamp.new) } - let!(:champ_mandatory_empty) { Champ.create(type_de_champ: TypeDeChamp.new(libelle: 'mandatory', mandatory: true)) } - let!(:champ_datetime) do - champ_datetime = TypeDeChamp.new(type_champ: 'datetime') - Champ.create(type_de_champ: champ_datetime) - end + let(:type_de_champ) { create(:type_de_champ_public) } + let(:type_de_champ_mandatory) { create(:type_de_champ_public, libelle: 'mandatory', mandatory: true) } + let(:type_de_champ_datetime) { create(:type_de_champ_public, type_champ: :datetime) } + let!(:champ) { type_de_champ.champ.create(value: 'toto') } + let!(:champ_mandatory_empty) { type_de_champ_mandatory.champ.create } + let!(:champ_datetime) { type_de_champ_datetime.champ.create } let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] } describe 'save_champs' do From b3e07d85044393f497ca08b53b909f3a57b334c5 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 9 Feb 2018 17:51:26 +0100 Subject: [PATCH 11/14] Use `in?` in `type_champ` tests --- app/models/type_de_champ.rb | 13 ++++++++----- spec/models/type_de_champ_shared_example.rb | 10 ---------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 4a792d1cd..6df25d6a0 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -52,13 +52,16 @@ class TypeDeChamp < ActiveRecord::Base type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] } end - def field_for_list? - !(type_champ == 'textarea' || type_champ == 'header_section') + def check_mandatory + if non_fillable? + self.mandatory = false + else + true + end end - def check_mandatory - self.mandatory = false if %w(header_section explication).include?(self.type_champ) - true + def non_fillable? + type_champ.in?(['header_section', 'explication']) end def private? diff --git a/spec/models/type_de_champ_shared_example.rb b/spec/models/type_de_champ_shared_example.rb index fbe3b24de..1da5c0e22 100644 --- a/spec/models/type_de_champ_shared_example.rb +++ b/spec/models/type_de_champ_shared_example.rb @@ -29,14 +29,4 @@ shared_examples 'type_de_champ_spec' do it { is_expected.to allow_value('blabla').for(:description) } end end - - describe 'field_for_list?' do - let(:type_de_champ_yes) { create :type_de_champ_public, type_champ: 'text' } - let(:type_de_champ_no_1) { create :type_de_champ_public, type_champ: 'textarea' } - let(:type_de_champ_no_2) { create :type_de_champ_public, type_champ: 'header_section' } - - it { expect(type_de_champ_yes.field_for_list?).to be_truthy } - it { expect(type_de_champ_no_1.field_for_list?).to be_falsey } - it { expect(type_de_champ_no_2.field_for_list?).to be_falsey } - end end From 75b2e16cc00900f60ad3af8da14f1bdf27f12dc4 Mon Sep 17 00:00:00 2001 From: CamilleGarrigue <33320335+CamilleGarrigue@users.noreply.github.com> Date: Wed, 14 Feb 2018 10:44:26 +0000 Subject: [PATCH 12/14] Update _list.html.haml --- app/views/users/dossiers/_list.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/dossiers/_list.html.haml b/app/views/users/dossiers/_list.html.haml index 75eca7639..592f5695e 100644 --- a/app/views/users/dossiers/_list.html.haml +++ b/app/views/users/dossiers/_list.html.haml @@ -27,7 +27,7 @@ %td{ id: "dossier_#{dossier.id}_state" }= dossier.display_state %td= dossier.last_update - %td= link_to('X', url_for(controller: 'dossiers', action: :destroy, id: dossier.id), 'data-confirm' => "Voulez-vous supprimer la brouillon ?", 'data-method' => :delete, class: 'btn-sm btn-danger') if @liste == "brouillon" + %td= link_to('X', url_for(controller: 'dossiers', action: :destroy, id: dossier.id), 'data-confirm' => "Voulez-vous supprimer le brouillon ?", 'data-method' => :delete, class: 'btn-sm btn-danger') if @liste == "brouillon" = smart_listing.paginate = smart_listing.pagination_per_page_links From 31d638ae2ad6d48d2ac27c1fc5aa2eedf99c5268 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 13 Feb 2018 15:38:26 +0100 Subject: [PATCH 13/14] Remove TypeDeChampPublic/TypeDeChampPrivate STI --- app/controllers/root_controller.rb | 2 +- app/facades/admin_types_de_champ_facades.rb | 2 +- app/models/procedure.rb | 4 +- app/models/type_de_champ.rb | 7 ++- app/models/type_de_champ_private.rb | 2 - app/models/type_de_champ_public.rb | 2 - app/services/types_de_champ_service.rb | 12 ++--- .../admin/types_de_champ_controller_spec.rb | 3 +- .../types_de_champ_private_controller_spec.rb | 6 +-- spec/factories/type_de_champ_private.rb | 3 +- spec/factories/type_de_champ_public.rb | 3 +- spec/models/type_de_champ_private_spec.rb | 9 ++-- spec/models/type_de_champ_public_spec.rb | 7 --- spec/services/types_de_champ_service_spec.rb | 53 ++++++++++--------- 14 files changed, 58 insertions(+), 57 deletions(-) delete mode 100644 app/models/type_de_champ_private.rb delete mode 100644 app/models/type_de_champ_public.rb delete mode 100644 spec/models/type_de_champ_public_spec.rb diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index febfb25d1..3d16871fa 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -19,7 +19,7 @@ class RootController < ApplicationController description = 'a not so long description' all_champs = TypeDeChamp.type_champs - .map { |name, _| TypeDeChamp.new(type_champ: name, libelle: name, description: description, mandatory: true) } + .map { |name, _| TypeDeChamp.new(type_champ: name, private: false, libelle: name, description: description, mandatory: true) } .map.with_index { |type_de_champ, i| type_de_champ.champ.build(id: i) } all_champs diff --git a/app/facades/admin_types_de_champ_facades.rb b/app/facades/admin_types_de_champ_facades.rb index a8f7fe578..eefe7e57c 100644 --- a/app/facades/admin_types_de_champ_facades.rb +++ b/app/facades/admin_types_de_champ_facades.rb @@ -23,7 +23,7 @@ class AdminTypesDeChampFacades end def new_type_de_champ - @private ? TypeDeChampPrivate.new.decorate : TypeDeChampPublic.new.decorate + TypeDeChamp.new(private: @private).decorate end def fields_for_var diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 7cf0c3d67..5441fbc3d 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -1,7 +1,7 @@ class Procedure < ActiveRecord::Base has_many :types_de_piece_justificative, -> { order "order_place ASC" }, dependent: :destroy - has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy - has_many :types_de_champ_private, dependent: :destroy + has_many :types_de_champ, -> { public_only }, dependent: :destroy + has_many :types_de_champ_private, -> { private_only }, class_name: 'TypeDeChamp', dependent: :destroy has_many :dossiers has_one :procedure_path, dependent: :destroy diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 6df25d6a0..f6bf5a36d 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -1,4 +1,6 @@ class TypeDeChamp < ActiveRecord::Base + self.inheritance_column = :_type_disabled + enum type_champs: { text: 'text', textarea: 'textarea', @@ -24,6 +26,9 @@ class TypeDeChamp < ActiveRecord::Base belongs_to :procedure + scope :public_only, -> { where.not(type: 'TypeDeChampPrivate').or(where(private: [false, nil])) } + scope :private_only, -> { where(type: 'TypeDeChampPrivate').or(where(private: true)) } + has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do def build(params = {}) super(params.merge(proxy_association.owner.params_for_champ)) @@ -65,7 +70,7 @@ class TypeDeChamp < ActiveRecord::Base end def private? - type == 'TypeDeChampPrivate' + super || type == 'TypeDeChampPrivate' end def public? diff --git a/app/models/type_de_champ_private.rb b/app/models/type_de_champ_private.rb deleted file mode 100644 index ba6e89a82..000000000 --- a/app/models/type_de_champ_private.rb +++ /dev/null @@ -1,2 +0,0 @@ -class TypeDeChampPrivate < TypeDeChamp -end diff --git a/app/models/type_de_champ_public.rb b/app/models/type_de_champ_public.rb deleted file mode 100644 index 3be990e13..000000000 --- a/app/models/type_de_champ_public.rb +++ /dev/null @@ -1,2 +0,0 @@ -class TypeDeChampPublic < TypeDeChamp -end diff --git a/app/services/types_de_champ_service.rb b/app/services/types_de_champ_service.rb index 7f8cfe1e9..d4eb53a9b 100644 --- a/app/services/types_de_champ_service.rb +++ b/app/services/types_de_champ_service.rb @@ -13,17 +13,17 @@ class TypesDeChampService :type_champ, :id, :mandatory, - :type, drop_down_list_attributes: [:value, :id] ]) - parameters[attributes].each do |param_first, param_second| - if param_second[:libelle].empty? - parameters[attributes].delete(param_first.to_s) + parameters[attributes].each do |index, param| + param[:private] = private + if param[:libelle].empty? + parameters[attributes].delete(index.to_s) end - if param_second['drop_down_list_attributes'] && param_second['drop_down_list_attributes']['value'] - param_second['drop_down_list_attributes']['value'] = self.clean_value (param_second['drop_down_list_attributes']['value']) + if param['drop_down_list_attributes'] && param['drop_down_list_attributes']['value'] + param['drop_down_list_attributes']['value'] = self.clean_value (param['drop_down_list_attributes']['value']) end end diff --git a/spec/controllers/admin/types_de_champ_controller_spec.rb b/spec/controllers/admin/types_de_champ_controller_spec.rb index d3b6fc8fa..a1520d05e 100644 --- a/spec/controllers/admin/types_de_champ_controller_spec.rb +++ b/spec/controllers/admin/types_de_champ_controller_spec.rb @@ -57,8 +57,7 @@ describe Admin::TypesDeChampController, type: :controller do description: '', order_place: '1', id: '', - mandatory: false, - type: 'TypeDeChampPublic' + mandatory: false } } } diff --git a/spec/controllers/admin/types_de_champ_private_controller_spec.rb b/spec/controllers/admin/types_de_champ_private_controller_spec.rb index 61ab44966..07d388183 100644 --- a/spec/controllers/admin/types_de_champ_private_controller_spec.rb +++ b/spec/controllers/admin/types_de_champ_private_controller_spec.rb @@ -49,8 +49,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do description: description, order_place: order_place, id: types_de_champ_id, - mandatory: mandatory, - type: 'TypeDeChampPrivate' + mandatory: mandatory }, '1' => { libelle: '', @@ -58,8 +57,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do description: '', order_place: '1', id: '', - mandatory: false, - type: 'TypeDeChampPrivate' + mandatory: false } } } diff --git a/spec/factories/type_de_champ_private.rb b/spec/factories/type_de_champ_private.rb index d804dd42b..11a434765 100644 --- a/spec/factories/type_de_champ_private.rb +++ b/spec/factories/type_de_champ_private.rb @@ -1,5 +1,6 @@ FactoryBot.define do - factory :type_de_champ_private do + factory :type_de_champ_private, class: 'TypeDeChamp' do + private true sequence(:libelle) { |n| "Libelle champ privé #{n}" } sequence(:description) { |n| "description du champ privé #{n}" } type_champ 'text' diff --git a/spec/factories/type_de_champ_public.rb b/spec/factories/type_de_champ_public.rb index 7f63092cf..9654959e1 100644 --- a/spec/factories/type_de_champ_public.rb +++ b/spec/factories/type_de_champ_public.rb @@ -1,5 +1,6 @@ FactoryBot.define do - factory :type_de_champ_public do + factory :type_de_champ_public, class: 'TypeDeChamp' do + private false sequence(:libelle) { |n| "Libelle du champ #{n}" } sequence(:description) { |n| "description du champ #{n}" } type_champ 'text' diff --git a/spec/models/type_de_champ_private_spec.rb b/spec/models/type_de_champ_private_spec.rb index 6f0b1ce8a..19b8a631b 100644 --- a/spec/models/type_de_champ_private_spec.rb +++ b/spec/models/type_de_champ_private_spec.rb @@ -1,7 +1,10 @@ require 'spec_helper' -describe TypeDeChampPrivate do - require 'models/type_de_champ_shared_example' +describe TypeDeChamp do + describe '#private?' do + let(:type_de_champ) { build(:type_de_champ_private) } - it_should_behave_like "type_de_champ_spec" + it { expect(type_de_champ.private?).to be_truthy } + it { expect(type_de_champ.public?).to be_falsey } + end end diff --git a/spec/models/type_de_champ_public_spec.rb b/spec/models/type_de_champ_public_spec.rb deleted file mode 100644 index fc855566f..000000000 --- a/spec/models/type_de_champ_public_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -describe TypeDeChampPublic do - require 'models/type_de_champ_shared_example' - - it_should_behave_like "type_de_champ_spec" -end diff --git a/spec/services/types_de_champ_service_spec.rb b/spec/services/types_de_champ_service_spec.rb index dbe847cc0..f08072542 100644 --- a/spec/services/types_de_champ_service_spec.rb +++ b/spec/services/types_de_champ_service_spec.rb @@ -9,7 +9,7 @@ describe TypesDeChampService do describe 'the drop down list attributes' do let(:types_de_champ_attributes) do { - "0" => { + "0": { libelle: 'top', drop_down_list_attributes: { value: "un\r\n deux\r\n -- commentaire --\r\n trois", @@ -28,29 +28,34 @@ describe TypesDeChampService do describe 'reorder the fields' do let(:types_de_champ_attributes) do { - '0' => { 'libelle' => 'a', 'order_place' => '0', 'custom_order_place' => '1' }, - '1' => { 'libelle' => 'b', 'order_place' => '1', 'custom_order_place' => '2' } + '0': { 'libelle': 'a', 'order_place': '0', 'custom_order_place': '1' }, + '1': { 'libelle': 'b', 'order_place': '1', 'custom_order_place': '2' } } end subject { result['types_de_champ_attributes'].to_unsafe_hash } - it { is_expected.to match({ "0" => { 'libelle' => 'a', 'order_place' => '0' }, "1" => { 'libelle' => 'b', 'order_place' => '1' } }) } + it do + is_expected.to match({ + '0': { 'libelle': 'a', 'order_place': '0', 'private': false }, + '1': { 'libelle': 'b', 'order_place': '1', 'private': false } + }) + end context 'when the user specifies a position on one element' do let(:types_de_champ_attributes) do { - '0' => { 'libelle' => 'a', 'order_place' => '1', 'custom_order_place' => '1' }, - '1' => { 'libelle' => 'b', 'order_place' => '10', 'custom_order_place' => '10' }, - '2' => { 'libelle' => 'c', 'order_place' => '11', 'custom_order_place' => '2' } + '0': { 'libelle': 'a', 'order_place': '1', 'custom_order_place': '1' }, + '1': { 'libelle': 'b', 'order_place': '10', 'custom_order_place': '10' }, + '2': { 'libelle': 'c', 'order_place': '11', 'custom_order_place': '2' } } end it do is_expected.to match({ - '0' => { 'libelle' => 'a', 'order_place' => '0' }, - '1' => { 'libelle' => 'c', 'order_place' => '1' }, - '2' => { 'libelle' => 'b', 'order_place' => '2' } + '0': { 'libelle': 'a', 'order_place': '0', 'private': false }, + '1': { 'libelle': 'c', 'order_place': '1', 'private': false }, + '2': { 'libelle': 'b', 'order_place': '2', 'private': false } }) end end @@ -58,17 +63,17 @@ describe TypesDeChampService do context 'when the user puts a champ down' do let(:types_de_champ_attributes) do { - '0' => { 'libelle' => 'a', 'order_place' => '0', 'custom_order_place' => '2' }, - '1' => { 'libelle' => 'b', 'order_place' => '1', 'custom_order_place' => '2' }, - '2' => { 'libelle' => 'c', 'order_place' => '2', 'custom_order_place' => '3' } + '0': { 'libelle': 'a', 'order_place': '0', 'custom_order_place': '2' }, + '1': { 'libelle': 'b', 'order_place': '1', 'custom_order_place': '2' }, + '2': { 'libelle': 'c', 'order_place': '2', 'custom_order_place': '3' } } end it do is_expected.to match({ - '0' => { 'libelle' => 'b', 'order_place' => '0' }, - '1' => { 'libelle' => 'a', 'order_place' => '1' }, - '2' => { 'libelle' => 'c', 'order_place' => '2' } + '0': { 'libelle': 'b', 'order_place': '0', 'private': false }, + '1': { 'libelle': 'a', 'order_place': '1', 'private': false }, + '2': { 'libelle': 'c', 'order_place': '2', 'private': false } }) end end @@ -76,19 +81,19 @@ describe TypesDeChampService do context 'when the user uses not a number' do let(:types_de_champ_attributes) do { - '0' => { 'libelle' => 'a', 'order_place' => '0', 'custom_order_place' => '1' }, - '1' => { 'libelle' => 'b', 'order_place' => '1', 'custom_order_place' => '2' }, - '2' => { 'libelle' => 'c', 'order_place' => '2', 'custom_order_place' => '' }, - '3' => { 'libelle' => 'd', 'order_place' => '3', 'custom_order_place' => 'a' } + '0': { 'libelle': 'a', 'order_place': '0', 'custom_order_place': '1' }, + '1': { 'libelle': 'b', 'order_place': '1', 'custom_order_place': '2' }, + '2': { 'libelle': 'c', 'order_place': '2', 'custom_order_place': '' }, + '3': { 'libelle': 'd', 'order_place': '3', 'custom_order_place': 'a' } } end it 'does not change the natural order' do is_expected.to match({ - '0' => { 'libelle' => 'a', 'order_place' => '0' }, - '1' => { 'libelle' => 'b', 'order_place' => '1' }, - '2' => { 'libelle' => 'c', 'order_place' => '2' }, - '3' => { 'libelle' => 'd', 'order_place' => '3' } + '0': { 'libelle': 'a', 'order_place': '0', 'private': false }, + '1': { 'libelle': 'b', 'order_place': '1', 'private': false }, + '2': { 'libelle': 'c', 'order_place': '2', 'private': false }, + '3': { 'libelle': 'd', 'order_place': '3', 'private': false } }) end end From 0c1d529b61c582e7bf1c5dea22eeff46afb50fa2 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 13 Feb 2018 17:00:19 +0100 Subject: [PATCH 14/14] Unify :type_de_champ public/private factories --- .../admin/types_de_champ_controller_spec.rb | 18 ++++++------ .../types_de_champ_private_controller_spec.rb | 18 ++++++------ .../dossiers_controller_spec.rb | 4 +-- spec/decorators/champ_decorator_spec.rb | 3 +- .../type_de_champ_decorator_spec.rb | 6 ++-- spec/factories/champ.rb | 10 +++---- spec/factories/procedure.rb | 12 ++++---- ...pe_de_champ_public.rb => type_de_champ.rb} | 8 +++++- spec/factories/type_de_champ_private.rb | 16 ----------- .../move_down_type_de_champ_private_spec.rb | 8 +++--- .../admin/move_down_type_de_champ_spec.rb | 8 +++--- .../move_up_type_de_champ_private_spec.rb | 8 +++--- .../admin/move_up_type_de_champ_spec.rb | 8 +++--- .../users/flux_de_commentaires_spec.rb | 2 +- spec/jobs/find_dubious_procedures_job_spec.rb | 6 ++-- spec/models/attestation_template_spec.rb | 4 +-- spec/models/champ_private_spec.rb | 2 +- spec/models/champ_shared_example.rb | 4 +-- spec/models/champ_spec.rb | 8 +++--- .../concern/tags_substitution_concern_spec.rb | 22 +++++++-------- spec/models/dossier_spec.rb | 12 ++++---- spec/models/drop_down_list_spec.rb | 4 +-- spec/models/procedure_spec.rb | 28 +++++++++---------- spec/models/type_de_champ_private_spec.rb | 2 +- spec/services/champs_service_spec.rb | 6 ++-- .../types_de_champ/show.html.haml_spec.rb | 10 +++---- .../show.html.haml_spec.rb | 10 +++---- .../champs/_date.html.haml_spec.rb | 2 +- .../champs/_dossier_link.html.haml_spec.rb | 2 +- .../champs/_engagement.html.haml_spec.rb | 2 +- .../_render_list_champs.html.haml_spec.rb | 4 +-- .../champs/_yes_no.html.haml_spec.rb | 2 +- 32 files changed, 125 insertions(+), 134 deletions(-) rename spec/factories/{type_de_champ_public.rb => type_de_champ.rb} (78%) delete mode 100644 spec/factories/type_de_champ_private.rb diff --git a/spec/controllers/admin/types_de_champ_controller_spec.rb b/spec/controllers/admin/types_de_champ_controller_spec.rb index a1520d05e..e14f11107 100644 --- a/spec/controllers/admin/types_de_champ_controller_spec.rb +++ b/spec/controllers/admin/types_de_champ_controller_spec.rb @@ -147,7 +147,7 @@ describe Admin::TypesDeChampController, type: :controller do end end context 'when procedure and type de champs are not linked' do - let(:type_de_champ) { create(:type_de_champ_public) } + let(:type_de_champ) { create(:type_de_champ) } let(:type_de_champ_id) { type_de_champ.id } it { expect(subject.status).to eq(404) } end @@ -162,20 +162,20 @@ describe Admin::TypesDeChampController, type: :controller do end context 'when procedure have only one type de champ' do let(:index) { 1 } - let!(:type_de_champ) { create(:type_de_champ_public, procedure: procedure) } + let!(:type_de_champ) { create(:type_de_champ, procedure: procedure) } it { expect(subject.status).to eq(400) } end context 'when procedure have tow type de champs' do context 'when index == 0' do let(:index) { 0 } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure) } - let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure) } + let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure) } it { expect(subject.status).to eq(400) } end context 'when index > 0' do let(:index) { 1 } - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } it { expect(subject.status).to eq(200) } it { expect(subject).to render_template('show') } @@ -200,12 +200,12 @@ describe Admin::TypesDeChampController, type: :controller do it { expect(subject.status).to eq(400) } end context 'when procedure have only one type de champ' do - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure) } it { expect(subject.status).to eq(400) } end context 'when procedure have 2 type de champ' do - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } context 'when index represent last type_de_champ' do let(:index) { 1 } it { expect(subject.status).to eq(400) } diff --git a/spec/controllers/admin/types_de_champ_private_controller_spec.rb b/spec/controllers/admin/types_de_champ_private_controller_spec.rb index 07d388183..d3a48202b 100644 --- a/spec/controllers/admin/types_de_champ_private_controller_spec.rb +++ b/spec/controllers/admin/types_de_champ_private_controller_spec.rb @@ -129,7 +129,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do end end context 'when procedure and type de champs are not linked' do - let(:type_de_champ) { create(:type_de_champ_public) } + let(:type_de_champ) { create(:type_de_champ) } let(:type_de_champ_id) { type_de_champ.id } it { expect(subject.status).to eq(404) } end @@ -144,20 +144,20 @@ describe Admin::TypesDeChampPrivateController, type: :controller do end context 'when procedure have only one type de champ' do let(:index) { 1 } - let!(:type_de_champ) { create(:type_de_champ_private, procedure: procedure) } + let!(:type_de_champ) { create(:type_de_champ, :private, procedure: procedure) } it { expect(subject.status).to eq(400) } end context 'when procedure have tow type de champs' do context 'when index == 0' do let(:index) { 0 } - let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure) } - let!(:type_de_champ_2) { create(:type_de_champ_private, procedure: procedure) } + let!(:type_de_champ_1) { create(:type_de_champ, :private, procedure: procedure) } + let!(:type_de_champ_2) { create(:type_de_champ, :private, procedure: procedure) } it { expect(subject.status).to eq(400) } end context 'when index > 0' do let(:index) { 1 } - let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) } + let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) } it { expect(subject.status).to eq(200) } it { expect(subject).to render_template('show') } @@ -182,12 +182,12 @@ describe Admin::TypesDeChampPrivateController, type: :controller do it { expect(subject.status).to eq(400) } end context 'when procedure have only one type de champ' do - let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure) } + let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure) } it { expect(subject.status).to eq(400) } end context 'when procedure have 2 type de champ' do - let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) } + let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) } context 'when index represent last type_de_champ' do let(:index) { 1 } it { expect(subject.status).to eq(400) } diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index 5a08115b3..be6329132 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -355,11 +355,11 @@ describe NewGestionnaire::DossiersController, type: :controller do describe "#update_annotations" do let(:champ_multiple_drop_down_list) do - create(:type_de_champ_private, type_champ: 'multiple_drop_down_list', libelle: 'libelle').champ.create + create(:type_de_champ, :private, type_champ: 'multiple_drop_down_list', libelle: 'libelle').champ.create end let(:champ_datetime) do - create(:type_de_champ_private, type_champ: 'datetime', libelle: 'libelle').champ.create + create(:type_de_champ, :private, type_champ: 'datetime', libelle: 'libelle').champ.create end let(:dossier) do diff --git a/spec/decorators/champ_decorator_spec.rb b/spec/decorators/champ_decorator_spec.rb index c01beac14..101483406 100644 --- a/spec/decorators/champ_decorator_spec.rb +++ b/spec/decorators/champ_decorator_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' describe ChampDecorator do - let(:champ) { create :champ, type_de_champ: (create :type_de_champ_public, type_champ: type_champ) } + let(:type_de_champ) { create(:type_de_champ, type_champ: type_champ) } + let(:champ) { type_de_champ.champ.create } let(:decorator) { champ.decorate } describe 'value' do diff --git a/spec/decorators/type_de_champ_decorator_spec.rb b/spec/decorators/type_de_champ_decorator_spec.rb index 0a6ac784a..7a490aefc 100644 --- a/spec/decorators/type_de_champ_decorator_spec.rb +++ b/spec/decorators/type_de_champ_decorator_spec.rb @@ -4,9 +4,9 @@ describe TypeDeChampDecorator do let(:procedure) { create(:procedure) } let(:url) { 'http://localhost' } let(:params) { { url: url, index: index } } - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } - let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } + let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } describe '#button_up' do describe 'with first piece justificative' do diff --git a/spec/factories/champ.rb b/spec/factories/champ.rb index ee5917834..f6570f6f4 100644 --- a/spec/factories/champ.rb +++ b/spec/factories/champ.rb @@ -1,21 +1,21 @@ FactoryBot.define do factory :champ do - type_de_champ { FactoryBot.create(:type_de_champ_public) } + type_de_champ { FactoryBot.create(:type_de_champ) } trait :checkbox do - type_de_champ { FactoryBot.create(:type_de_champ_public, :checkbox) } + type_de_champ { FactoryBot.create(:type_de_champ, :checkbox) } end trait :header_section do - type_de_champ { FactoryBot.create(:type_de_champ_public, :header_section) } + type_de_champ { FactoryBot.create(:type_de_champ, :header_section) } end trait :explication do - type_de_champ { FactoryBot.create(:type_de_champ_public, :explication) } + type_de_champ { FactoryBot.create(:type_de_champ, :explication) } end trait :dossier_link do - type_de_champ { FactoryBot.create(:type_de_champ_public, :type_dossier_link) } + type_de_champ { FactoryBot.create(:type_de_champ, :type_dossier_link) } end end end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 29892706d..656a0631b 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -36,7 +36,7 @@ FactoryBot.define do after(:build) do |procedure, evaluator| evaluator.types_de_champ_count.times do - type_de_champ = create(:type_de_champ_public) + type_de_champ = create(:type_de_champ) procedure.types_de_champ << type_de_champ end @@ -50,7 +50,7 @@ FactoryBot.define do after(:build) do |procedure, evaluator| evaluator.types_de_champ_private_count.times do - type_de_champ = create(:type_de_champ_private) + type_de_champ = create(:type_de_champ, :private) procedure.types_de_champ_private << type_de_champ end @@ -59,7 +59,7 @@ FactoryBot.define do trait :with_type_de_champ_mandatory do after(:build) do |procedure, _evaluator| - type_de_champ = create(:type_de_champ_public, mandatory: true) + type_de_champ = create(:type_de_champ, mandatory: true) procedure.types_de_champ << type_de_champ end @@ -67,7 +67,7 @@ FactoryBot.define do trait :with_datetime do after(:build) do |procedure, _evaluator| - type_de_champ = create(:type_de_champ_public, mandatory: true, type_champ: :datetime) + type_de_champ = create(:type_de_champ, mandatory: true, type_champ: :datetime) procedure.types_de_champ << type_de_champ end @@ -75,7 +75,7 @@ FactoryBot.define do trait :with_dossier_link do after(:build) do |procedure, _evaluator| - type_de_champ = create(:type_de_champ_public, :type_dossier_link) + type_de_champ = create(:type_de_champ, :type_dossier_link) procedure.types_de_champ << type_de_champ end @@ -83,7 +83,7 @@ FactoryBot.define do trait :with_yes_no do after(:build) do |procedure, _evaluator| - type_de_champ = create(:type_de_champ_public, :type_yes_no) + type_de_champ = create(:type_de_champ, :type_yes_no) procedure.types_de_champ << type_de_champ end diff --git a/spec/factories/type_de_champ_public.rb b/spec/factories/type_de_champ.rb similarity index 78% rename from spec/factories/type_de_champ_public.rb rename to spec/factories/type_de_champ.rb index 9654959e1..5752a5aec 100644 --- a/spec/factories/type_de_champ_public.rb +++ b/spec/factories/type_de_champ.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :type_de_champ_public, class: 'TypeDeChamp' do + factory :type_de_champ do private false sequence(:libelle) { |n| "Libelle du champ #{n}" } sequence(:description) { |n| "description du champ #{n}" } @@ -34,5 +34,11 @@ FactoryBot.define do type_champ 'drop_down_list' drop_down_list { create(:drop_down_list) } end + + trait :private do + private true + sequence(:libelle) { |n| "Libelle champ privé #{n}" } + sequence(:description) { |n| "description du champ privé #{n}" } + end end end diff --git a/spec/factories/type_de_champ_private.rb b/spec/factories/type_de_champ_private.rb deleted file mode 100644 index 11a434765..000000000 --- a/spec/factories/type_de_champ_private.rb +++ /dev/null @@ -1,16 +0,0 @@ -FactoryBot.define do - factory :type_de_champ_private, class: 'TypeDeChamp' do - private true - sequence(:libelle) { |n| "Libelle champ privé #{n}" } - sequence(:description) { |n| "description du champ privé #{n}" } - type_champ 'text' - order_place 1 - mandatory false - - trait :type_drop_down_list do - libelle 'Menu déroulant' - type_champ 'drop_down_list' - drop_down_list { create(:drop_down_list) } - end - end -end diff --git a/spec/features/admin/move_down_type_de_champ_private_spec.rb b/spec/features/admin/move_down_type_de_champ_private_spec.rb index b811617a0..87d0f98ef 100644 --- a/spec/features/admin/move_down_type_de_champ_private_spec.rb +++ b/spec/features/admin/move_down_type_de_champ_private_spec.rb @@ -8,10 +8,10 @@ feature 'move down button type de champs', js: true do end let(:procedure) { create(:procedure, administrateur: administrateur) } - let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) } - let!(:type_de_champ_2) { create(:type_de_champ_private, procedure: procedure, order_place: 2) } - let!(:type_de_champ_3) { create(:type_de_champ_private, procedure: procedure, order_place: 3) } + let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) } + let!(:type_de_champ_2) { create(:type_de_champ, :private, procedure: procedure, order_place: 2) } + let!(:type_de_champ_3) { create(:type_de_champ, :private, procedure: procedure, order_place: 3) } context 'when clicking on move down for type de champ 1' do before do diff --git a/spec/features/admin/move_down_type_de_champ_spec.rb b/spec/features/admin/move_down_type_de_champ_spec.rb index 0e9243cf9..84f291caf 100644 --- a/spec/features/admin/move_down_type_de_champ_spec.rb +++ b/spec/features/admin/move_down_type_de_champ_spec.rb @@ -8,10 +8,10 @@ feature 'move down button type de champs', js: true do end let(:procedure) { create(:procedure, administrateur: administrateur) } - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } - let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) } - let!(:type_de_champ_3) { create(:type_de_champ_public, procedure: procedure, order_place: 3) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } + let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } + let!(:type_de_champ_3) { create(:type_de_champ, procedure: procedure, order_place: 3) } context 'when clicking on move down for type de champ 1' do before do diff --git a/spec/features/admin/move_up_type_de_champ_private_spec.rb b/spec/features/admin/move_up_type_de_champ_private_spec.rb index 377fcea61..b0f0bec29 100644 --- a/spec/features/admin/move_up_type_de_champ_private_spec.rb +++ b/spec/features/admin/move_up_type_de_champ_private_spec.rb @@ -8,10 +8,10 @@ feature 'move up button type de champs', js: true do end let(:procedure) { create(:procedure, administrateur: administrateur) } - let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) } - let!(:type_de_champ_2) { create(:type_de_champ_private, procedure: procedure, order_place: 2) } - let!(:type_de_champ_3) { create(:type_de_champ_private, procedure: procedure, order_place: 3) } + let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) } + let!(:type_de_champ_2) { create(:type_de_champ, :private, procedure: procedure, order_place: 2) } + let!(:type_de_champ_3) { create(:type_de_champ, :private, procedure: procedure, order_place: 3) } context 'when clicking on move down for type de champ 1' do before do diff --git a/spec/features/admin/move_up_type_de_champ_spec.rb b/spec/features/admin/move_up_type_de_champ_spec.rb index 28c0ab9f5..4f0679509 100644 --- a/spec/features/admin/move_up_type_de_champ_spec.rb +++ b/spec/features/admin/move_up_type_de_champ_spec.rb @@ -8,10 +8,10 @@ feature 'move up button type de champs', js: true do end let(:procedure) { create(:procedure, administrateur: administrateur) } - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } - let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) } - let!(:type_de_champ_3) { create(:type_de_champ_public, procedure: procedure, order_place: 3) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } + let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } + let!(:type_de_champ_3) { create(:type_de_champ, procedure: procedure, order_place: 3) } context 'when clicking on move down for type de champ 1' do before do diff --git a/spec/features/users/flux_de_commentaires_spec.rb b/spec/features/users/flux_de_commentaires_spec.rb index b39c5717e..92a68e63f 100644 --- a/spec/features/users/flux_de_commentaires_spec.rb +++ b/spec/features/users/flux_de_commentaires_spec.rb @@ -6,7 +6,7 @@ feature 'users: flux de commentaires' do let(:dossier_id) { dossier.id } let(:champ1) { dossier.champs.first } - let(:champ2) { create(:champ, dossier: dossier, type_de_champ: create(:type_de_champ_public, libelle: "subtitle")) } + let(:champ2) { create(:champ, dossier: dossier, type_de_champ: create(:type_de_champ, libelle: "subtitle")) } let!(:commentaire1) { create(:commentaire, dossier: dossier, champ: champ1) } let!(:commentaire2) { create(:commentaire, dossier: dossier) } diff --git a/spec/jobs/find_dubious_procedures_job_spec.rb b/spec/jobs/find_dubious_procedures_job_spec.rb index d18ac6992..ba34e3cb3 100644 --- a/spec/jobs/find_dubious_procedures_job_spec.rb +++ b/spec/jobs/find_dubious_procedures_job_spec.rb @@ -4,7 +4,7 @@ RSpec.describe FindDubiousProceduresJob, type: :job do describe 'perform' do let(:mailer_double) { double('mailer', deliver_now: true) } let(:procedure) { create(:procedure) } - let(:allowed_tdc) { create(:type_de_champ_public, libelle: 'fournir') } + let(:allowed_tdc) { create(:type_de_champ, libelle: 'fournir') } before do allow(AdministrationMailer).to receive(:dubious_procedures) @@ -17,8 +17,8 @@ RSpec.describe FindDubiousProceduresJob, type: :job do context 'with suspicious champs' do let(:forbidden_tdcs) do [ - create(:type_de_champ_public, libelle: 'num de securite sociale, stp'), - create(:type_de_champ_public, libelle: "t'aurais une carte bancaire ?") + create(:type_de_champ, libelle: 'num de securite sociale, stp'), + create(:type_de_champ, libelle: "t'aurais une carte bancaire ?") ] end diff --git a/spec/models/attestation_template_spec.rb b/spec/models/attestation_template_spec.rb index 455907c8a..680c72ef2 100644 --- a/spec/models/attestation_template_spec.rb +++ b/spec/models/attestation_template_spec.rb @@ -149,8 +149,8 @@ describe AttestationTemplate, type: :model do context 'when the procedure has a type de champ named libelleA et libelleB' do let(:types_de_champ) do [ - create(:type_de_champ_public, libelle: 'libelleA'), - create(:type_de_champ_public, libelle: 'libelleB') + create(:type_de_champ, libelle: 'libelleA'), + create(:type_de_champ, libelle: 'libelleB') ] end diff --git a/spec/models/champ_private_spec.rb b/spec/models/champ_private_spec.rb index 5e3dee9af..c6f60362a 100644 --- a/spec/models/champ_private_spec.rb +++ b/spec/models/champ_private_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Champ do describe '#private?' do - let(:type_de_champ) { build(:type_de_champ_private) } + let(:type_de_champ) { build(:type_de_champ, :private) } let(:champ) { type_de_champ.champ.build } it { expect(champ.private?).to be_truthy } diff --git a/spec/models/champ_shared_example.rb b/spec/models/champ_shared_example.rb index 6c42ed032..2fd1a1a3f 100644 --- a/spec/models/champ_shared_example.rb +++ b/spec/models/champ_shared_example.rb @@ -1,6 +1,6 @@ shared_examples 'champ_spec' do describe 'mandatory_and_blank?' do - let(:type_de_champ) { build(:type_de_champ_public, mandatory: mandatory) } + let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) } let(:champ) { type_de_champ.champ.build(value: value) } let(:value) { '' } let(:mandatory) { true } @@ -33,7 +33,7 @@ shared_examples 'champ_spec' do end context "when type_champ=date" do - let(:type_de_champ) { create(:type_de_champ_public, type_champ: "date") } + let(:type_de_champ) { create(:type_de_champ, type_champ: "date") } let(:champ) { type_de_champ.champ.create } it "should convert %d/%m/%Y format to ISO" do diff --git a/spec/models/champ_spec.rb b/spec/models/champ_spec.rb index f56a0f390..5a4f1d15c 100644 --- a/spec/models/champ_spec.rb +++ b/spec/models/champ_spec.rb @@ -6,7 +6,7 @@ describe Champ do it_should_behave_like "champ_spec" describe '#public?' do - let(:type_de_champ) { build(:type_de_champ_public) } + let(:type_de_champ) { build(:type_de_champ) } let(:champ) { type_de_champ.champ.build } it { expect(champ.public?).to be_truthy } @@ -14,7 +14,7 @@ describe Champ do end describe '#format_datetime' do - let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'datetime') } + let(:type_de_champ) { build(:type_de_champ, type_champ: 'datetime') } let(:champ) { type_de_champ.champ.build(value: value) } before { champ.save } @@ -33,7 +33,7 @@ describe Champ do end describe '#multiple_select_to_string' do - let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'multiple_drop_down_list') } + let(:type_de_champ) { build(:type_de_champ, type_champ: 'multiple_drop_down_list') } let(:champ) { type_de_champ.champ.build(value: value) } before { champ.save } @@ -71,7 +71,7 @@ describe Champ do end describe 'for_export' do - let(:type_de_champ) { create(:type_de_champ_public, type_champ: type_champ) } + let(:type_de_champ) { create(:type_de_champ, type_champ: type_champ) } let(:champ) { type_de_champ.champ.build(value: value) } before { champ.save } diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index 4f6f185a2..42cc2bd44 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -71,8 +71,8 @@ describe TagsSubstitutionConcern, type: :model do context 'when the procedure has a type de champ named libelleA et libelleB' do let(:types_de_champ) do [ - create(:type_de_champ_public, libelle: 'libelleA'), - create(:type_de_champ_public, libelle: 'libelleB') + create(:type_de_champ, libelle: 'libelleA'), + create(:type_de_champ, libelle: 'libelleB') ] end @@ -123,7 +123,7 @@ describe TagsSubstitutionConcern, type: :model do end context 'when the procedure has a type de champ prive named libelleA' do - let(:types_de_champ_private) { [create(:type_de_champ_private, libelle: 'libelleA')] } + let(:types_de_champ_private) { [create(:type_de_champ, :private, libelle: 'libelleA')] } context 'and it is used in the template' do let(:template) { '--libelleA--' } @@ -144,13 +144,13 @@ describe TagsSubstitutionConcern, type: :model do # The dossier just transitionned from brouillon to en construction, # so champs private are not valid tags yet - let(:types_de_champ_private) { [create(:type_de_champ_private, libelle: 'libelleA')] } + let(:types_de_champ_private) { [create(:type_de_champ, :private, libelle: 'libelleA')] } it { is_expected.to eq('--libelleA--') } end context 'champs publics are valid tags' do - let(:types_de_champ) { [create(:type_de_champ_public, libelle: 'libelleA')] } + let(:types_de_champ) { [create(:type_de_champ, libelle: 'libelleA')] } before { dossier.champs.first.update_attributes(value: 'libelle1') } @@ -161,8 +161,8 @@ describe TagsSubstitutionConcern, type: :model do context 'when the procedure has 2 types de champ date and datetime' do let(:types_de_champ) do [ - create(:type_de_champ_public, libelle: 'date', type_champ: 'date'), - create(:type_de_champ_public, libelle: 'datetime', type_champ: 'datetime') + create(:type_de_champ, libelle: 'date', type_champ: 'date'), + create(:type_de_champ, libelle: 'datetime', type_champ: 'datetime') ] end @@ -224,13 +224,13 @@ describe TagsSubstitutionConcern, type: :model do shared_examples "treat all kinds of space as equivalent" do context 'and the champ has a non breaking space' do - let(:types_de_champ) { [create(:type_de_champ_public, libelle: 'mon tag')] } + let(:types_de_champ) { [create(:type_de_champ, libelle: 'mon tag')] } it { is_expected.to eq('valeur') } end context 'and the champ has an ordinary space' do - let(:types_de_champ) { [create(:type_de_champ_public, libelle: 'mon tag')] } + let(:types_de_champ) { [create(:type_de_champ, libelle: 'mon tag')] } it { is_expected.to eq('valeur') } end @@ -265,8 +265,8 @@ describe TagsSubstitutionConcern, type: :model do describe 'tags' do subject { template_concern.tags } - let(:types_de_champ) { [create(:type_de_champ_public, libelle: 'public')] } - let(:types_de_champ_private) { [create(:type_de_champ_private, libelle: 'privé')] } + let(:types_de_champ) { [create(:type_de_champ, libelle: 'public')] } + let(:types_de_champ_private) { [create(:type_de_champ, :private, libelle: 'privé')] } context 'when generating a document for a dossier terminé' do it { is_expected.to include(include({ libelle: 'motivation' })) } diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 5f8f32820..4dc9e35f0 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -349,9 +349,9 @@ describe Dossier do let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) } before do - 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) + create(:type_de_champ, libelle: 'l1', order_place: 1, procedure: procedure) + create(:type_de_champ, libelle: 'l3', order_place: 3, procedure: procedure) + create(:type_de_champ, libelle: 'l2', order_place: 2, procedure: procedure) end it { expect(dossier.ordered_champs.pluck(:libelle)).to match(%w(l1 l2 l3)) } @@ -362,9 +362,9 @@ describe Dossier do let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) } before do - 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 + 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 it { expect(dossier.ordered_champs_private.pluck(:libelle)).to match(%w(l1 l2 l3)) } diff --git a/spec/models/drop_down_list_spec.rb b/spec/models/drop_down_list_spec.rb index 3f01f7148..130edcdd1 100644 --- a/spec/models/drop_down_list_spec.rb +++ b/spec/models/drop_down_list_spec.rb @@ -47,14 +47,14 @@ describe DropDownList do end context 'when multiple' do - let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'multiple_drop_down_list') } + let(:type_de_champ) { build(:type_de_champ, type_champ: 'multiple_drop_down_list') } let(:champ) { type_de_champ.champ.build(value: '["1","2"]').decorate } it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) } end context 'when simple' do - let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'drop_down_list') } + let(:type_de_champ) { build(:type_de_champ, type_champ: 'drop_down_list') } let(:champ) { type_de_champ.champ.build(value: '1').decorate } it { expect(dropdownlist.selected_options(champ)).to match(['1']) } diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index c749185e8..827205514 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -69,8 +69,8 @@ describe Procedure do describe '#types_de_champ_ordered' do let(:procedure) { create(:procedure) } - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 1) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 0) } subject { procedure.types_de_champ_ordered } it { expect(subject.first).to eq(type_de_champ_1) } it { expect(subject.last).to eq(type_de_champ_0) } @@ -85,8 +85,8 @@ describe Procedure do it { expect(subject).to eq(false) } end context 'when procedure have 2 types de champ' do - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } context 'when index is not the last element' do it { expect(subject).to eq(true) } it 'switch order place' do @@ -153,12 +153,12 @@ describe Procedure do let(:archived_at) { nil } let(:published_at) { nil } let(:procedure) { create(:procedure, archived_at: archived_at, published_at: published_at, received_mail: received_mail) } - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } - let!(:type_de_champ_2) { create(:type_de_champ_public, :type_drop_down_list, procedure: procedure, order_place: 2) } - let!(:type_de_champ_private_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) } - let!(:type_de_champ_private_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) } - let!(:type_de_champ_private_2) { create(:type_de_champ_private, :type_drop_down_list, procedure: procedure, order_place: 2) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } + let!(:type_de_champ_2) { create(:type_de_champ, :type_drop_down_list, procedure: procedure, order_place: 2) } + let!(:type_de_champ_private_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } + let!(:type_de_champ_private_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) } + let!(:type_de_champ_private_2) { create(:type_de_champ, :private, :type_drop_down_list, procedure: procedure, order_place: 2) } let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) } let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) } let(:received_mail){ create(:received_mail) } @@ -342,10 +342,10 @@ describe Procedure do it { expect(subject[:headers]).to eq(dossier.export_headers) } context 'with ordered champs' do - let(:tc_2) { create(:type_de_champ_public, order_place: 2) } - let(:tc_1) { create(:type_de_champ_public, order_place: 1) } - let(:tcp_2) { create(:type_de_champ_private, order_place: 2) } - let(:tcp_1) { create(:type_de_champ_private, order_place: 1) } + let(:tc_2) { create(:type_de_champ, order_place: 2) } + let(:tc_1) { create(:type_de_champ, order_place: 1) } + let(:tcp_2) { create(:type_de_champ, :private, order_place: 2) } + let(:tcp_1) { create(:type_de_champ, :private, order_place: 1) } before do procedure.types_de_champ << tc_2 << tc_1 diff --git a/spec/models/type_de_champ_private_spec.rb b/spec/models/type_de_champ_private_spec.rb index 19b8a631b..161897d8e 100644 --- a/spec/models/type_de_champ_private_spec.rb +++ b/spec/models/type_de_champ_private_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe TypeDeChamp do describe '#private?' do - let(:type_de_champ) { build(:type_de_champ_private) } + let(:type_de_champ) { build(:type_de_champ, :private) } it { expect(type_de_champ.private?).to be_truthy } it { expect(type_de_champ.public?).to be_falsey } diff --git a/spec/services/champs_service_spec.rb b/spec/services/champs_service_spec.rb index 108596113..4aa2578e0 100644 --- a/spec/services/champs_service_spec.rb +++ b/spec/services/champs_service_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' describe ChampsService do - let(:type_de_champ) { create(:type_de_champ_public) } - let(:type_de_champ_mandatory) { create(:type_de_champ_public, libelle: 'mandatory', mandatory: true) } - let(:type_de_champ_datetime) { create(:type_de_champ_public, type_champ: :datetime) } + let(:type_de_champ) { create(:type_de_champ) } + let(:type_de_champ_mandatory) { create(:type_de_champ, libelle: 'mandatory', mandatory: true) } + let(:type_de_champ_datetime) { create(:type_de_champ, type_champ: :datetime) } let!(:champ) { type_de_champ.champ.create(value: 'toto') } let!(:champ_mandatory_empty) { type_de_champ_mandatory.champ.create } let!(:champ_datetime) { type_de_champ_datetime.champ.create } diff --git a/spec/views/admin/types_de_champ/show.html.haml_spec.rb b/spec/views/admin/types_de_champ/show.html.haml_spec.rb index 1921dd9f6..566542f23 100644 --- a/spec/views/admin/types_de_champ/show.html.haml_spec.rb +++ b/spec/views/admin/types_de_champ/show.html.haml_spec.rb @@ -6,8 +6,8 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do describe 'fields sorted' do let(:first_libelle) { 'salut la compagnie' } let(:last_libelle) { 'je suis bien sur la page' } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1, libelle: last_libelle) } - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0, libelle: first_libelle) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1, libelle: last_libelle) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0, libelle: first_libelle) } before do procedure.reload assign(:procedure, procedure) @@ -32,15 +32,15 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do it { expect(subject).not_to have_css('.fa-chevron-up') } end context 'when there is only one field in database' do - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } it { expect(subject).to have_css('#btn_down_0[style*="visibility: hidden"]') } it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } it { expect(subject).not_to have_css('#btn_up_1') } it { expect(subject).not_to have_css('#btn_down_1') } end context 'when there are 2 fields in database' do - let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } it { expect(subject).to have_css('#btn_down_0') } it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } it { expect(subject).to have_css('#btn_up_1') } diff --git a/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb b/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb index 36dce5ecc..7e9708199 100644 --- a/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb +++ b/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb @@ -6,8 +6,8 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do describe 'fields sorted' do let(:first_libelle) { 'salut la compagnie' } let(:last_libelle) { 'je suis bien sur la page' } - let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1, libelle: last_libelle) } - let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0, libelle: first_libelle) } + let!(:type_de_champ_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1, libelle: last_libelle) } + let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0, libelle: first_libelle) } before do procedure.reload assign(:procedure, procedure) @@ -40,15 +40,15 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do it { expect(subject).not_to have_css('.fa-chevron-up') } end context 'when there is only one field in database' do - let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) } + let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } it { expect(subject).to have_css('#btn_down_0[style*="visibility: hidden"]') } it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } it { expect(subject).not_to have_css('#btn_up_1') } it { expect(subject).not_to have_css('#btn_down_1') } end context 'when there are 2 fields in database' do - let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) } + let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) } it { expect(subject).to have_css('#btn_down_0') } it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } it { expect(subject).to have_css('#btn_up_1') } diff --git a/spec/views/users/description/champs/_date.html.haml_spec.rb b/spec/views/users/description/champs/_date.html.haml_spec.rb index 5e0e797e7..5cb1ed190 100644 --- a/spec/views/users/description/champs/_date.html.haml_spec.rb +++ b/spec/views/users/description/champs/_date.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'users/description/champs/date.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_public, type_champ: :date) } + let(:type_champ) { create(:type_de_champ, type_champ: :date) } before do render 'users/description/champs/date.html.haml', champ: champ diff --git a/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb b/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb index 970ab4a43..2a01477e8 100644 --- a/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb +++ b/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'users/description/champs/dossier_link.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_public, type_champ: :dossier_link) } + let(:type_champ) { create(:type_de_champ, type_champ: :dossier_link) } before do render 'users/description/champs/dossier_link.html.haml', champ: champ diff --git a/spec/views/users/description/champs/_engagement.html.haml_spec.rb b/spec/views/users/description/champs/_engagement.html.haml_spec.rb index a5ddd2f1d..c35c97662 100644 --- a/spec/views/users/description/champs/_engagement.html.haml_spec.rb +++ b/spec/views/users/description/champs/_engagement.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'users/description/champs/engagement.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_public, type_champ: :engagement) } + let(:type_champ) { create(:type_de_champ, type_champ: :engagement) } subject { render 'users/description/champs/engagement.html.haml', champ: champ } diff --git a/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb b/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb index 233114a9b..f790279ab 100644 --- a/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb +++ b/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb @@ -1,5 +1,5 @@ describe 'users/description/champs/render_list_champs.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_public, :checkbox) } + let(:type_champ) { create(:type_de_champ, :checkbox) } context "with any champ" do let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) } @@ -40,7 +40,7 @@ describe 'users/description/champs/render_list_champs.html.haml', type: :view do end context 'with a dossier_link' do - let(:type_champ) { create(:type_de_champ_public, type_champ: :dossier_link) } + let(:type_champ) { create(:type_de_champ, type_champ: :dossier_link) } let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) } before do diff --git a/spec/views/users/description/champs/_yes_no.html.haml_spec.rb b/spec/views/users/description/champs/_yes_no.html.haml_spec.rb index 9d2af680c..22ece7583 100644 --- a/spec/views/users/description/champs/_yes_no.html.haml_spec.rb +++ b/spec/views/users/description/champs/_yes_no.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'users/description/champs/yes_no.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_public, type_champ: :yes_no) } + let(:type_champ) { create(:type_de_champ, type_champ: :yes_no) } before do render 'users/description/champs/yes_no.html.haml', champ: champ