From 75f746640ac2a2e163a86661efcf0b0da4a7346b Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Tue, 15 Feb 2022 12:33:21 +0100 Subject: [PATCH] blocks architecture --- .../website/blocks_controller.rb | 61 +++++++++++++++++++ app/models/communication/website/block.rb | 46 ++++++++++++++ app/models/communication/website/home.rb | 1 + app/models/communication/website/page.rb | 2 + .../communication/website/with_abouts.rb | 4 ++ app/models/concerns/with_blocks.rb | 7 +++ app/models/education/program.rb | 13 ++++ app/models/research/journal/article.rb | 2 +- app/models/research/laboratory/axis.rb | 1 + app/models/university/person.rb | 1 + app/models/university/person/administrator.rb | 1 + app/models/university/person/author.rb | 1 + app/models/university/person/researcher.rb | 1 + app/models/university/person/teacher.rb | 1 + .../website/blocks/_list.html.erb | 28 +++++++++ .../website/blocks/_static.html.erb | 0 .../website/blocks/edit.html.erb | 8 +++ .../communication/website/blocks/new.html.erb | 20 ++++++ .../organization_chart/_edit.html.erb | 1 + .../organization_chart/_show.html.erb | 0 .../organization_chart/_static.html.erb | 0 .../blocks/templates/partners/_edit.html.erb | 1 + .../blocks/templates/partners/_show.html.erb | 0 .../templates/partners/_static.html.erb | 0 .../communication/website/pages/show.html.erb | 1 + config/locales/communication/en.yml | 13 ++++ config/locales/communication/fr.yml | 13 ++++ config/routes/admin/communication.rb | 1 + ...808_create_communication_website_blocks.rb | 14 +++++ db/schema.rb | 38 +++++++++++- docs/communication/websites/blocks.md | 1 + .../website/blocks_controller_test.rb | 48 +++++++++++++++ .../fixtures/communication/website/blocks.yml | 43 +++++++++++++ test/fixtures/research/laboratory/axes.yml | 1 + .../communication/website/block_test.rb | 33 ++++++++++ test/models/research/laboratory/axis_test.rb | 1 + .../communication/website/blocks_test.rb | 53 ++++++++++++++++ 37 files changed, 457 insertions(+), 3 deletions(-) create mode 100644 app/controllers/admin/communication/website/blocks_controller.rb create mode 100644 app/models/communication/website/block.rb create mode 100644 app/models/concerns/with_blocks.rb create mode 100644 app/views/admin/communication/website/blocks/_list.html.erb create mode 100644 app/views/admin/communication/website/blocks/_static.html.erb create mode 100644 app/views/admin/communication/website/blocks/edit.html.erb create mode 100644 app/views/admin/communication/website/blocks/new.html.erb create mode 100644 app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb create mode 100644 app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb create mode 100644 app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb create mode 100644 app/views/admin/communication/website/blocks/templates/partners/_edit.html.erb create mode 100644 app/views/admin/communication/website/blocks/templates/partners/_show.html.erb create mode 100644 app/views/admin/communication/website/blocks/templates/partners/_static.html.erb create mode 100644 db/migrate/20220215094808_create_communication_website_blocks.rb create mode 100644 test/controllers/communication/website/blocks_controller_test.rb create mode 100644 test/fixtures/communication/website/blocks.yml create mode 100644 test/models/communication/website/block_test.rb create mode 100644 test/system/communication/website/blocks_test.rb diff --git a/app/controllers/admin/communication/website/blocks_controller.rb b/app/controllers/admin/communication/website/blocks_controller.rb new file mode 100644 index 000000000..4b0abb3b4 --- /dev/null +++ b/app/controllers/admin/communication/website/blocks_controller.rb @@ -0,0 +1,61 @@ +class Admin::Communication::Website::BlocksController < Admin::Communication::Website::ApplicationController + load_and_authorize_resource class: Communication::Website::Block, through: :website + + def reorder + ids = params[:ids] || [] + first_page = nil + ids.each.with_index do |id, index| + block = @website.blocks.find(id) + block.update position: index + 1 + end + end + + def new + @block.about_type = params[:about_type] + @block.about_id = params[:about_id] + breadcrumb + end + + def edit + breadcrumb + end + + def create + @block.university = @website.university + @block.website = @website + if @block.save + redirect_to [:admin, @block.about], notice: t('admin.successfully_created_html', model: @block.to_s) + else + render :new, status: :unprocessable_entity + end + end + + def update + if @block.update(block_params) + redirect_to [:admin, @block.about], notice: t('admin.successfully_updated_html', model: @block.to_s) + else + render :edit, status: :unprocessable_entity + end + end + + def destroy + @about = @block.about + @block.destroy + redirect_to [:admin, @about], notice: t('admin.successfully_destroyed_html', model: @block.to_s) + end + + protected + + def breadcrumb + super + add_breadcrumb @block.about.model_name.human(count: 2), [:admin, @block.about.class] + add_breadcrumb @block.about, [:admin, @block.about] + add_breadcrumb t('communication.website.block.choose_template') + end + + + def block_params + params.require(:communication_website_block) + .permit(:about_id, :about_type, :template, :data) + end +end diff --git a/app/models/communication/website/block.rb b/app/models/communication/website/block.rb new file mode 100644 index 000000000..ca0170661 --- /dev/null +++ b/app/models/communication/website/block.rb @@ -0,0 +1,46 @@ +# == Schema Information +# +# Table name: communication_website_blocks +# +# id :uuid not null, primary key +# about_type :string indexed => [about_id] +# data :jsonb +# position :integer default(0), not null +# template :integer default(0), not null +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed => [about_type] +# communication_website_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_communication_website_blocks_on_about (about_type,about_id) +# index_communication_website_blocks_on_communication_website_id (communication_website_id) +# index_communication_website_blocks_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_18291ef65f (university_id => universities.id) +# fk_rails_75bd7c8d6c (communication_website_id => communication_websites.id) +# +class Communication::Website::Block < ApplicationRecord + include WithPosition + + belongs_to :university + belongs_to :website, foreign_key: :communication_website_id + belongs_to :about, polymorphic: true + + enum template: { + organization_chart: 100, + partners: 200 + } + + def to_s + "Bloc #{position}" + end + + def last_ordered_element + about.blocks.ordered.last + end +end diff --git a/app/models/communication/website/home.rb b/app/models/communication/website/home.rb index e35d331f3..00353bdc2 100644 --- a/app/models/communication/website/home.rb +++ b/app/models/communication/website/home.rb @@ -6,6 +6,7 @@ # description :text # featured_image_alt :string # github_path :text +# text_new :text # created_at :datetime not null # updated_at :datetime not null # communication_website_id :uuid not null, indexed diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 4a81253e0..4ffcf0ecd 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -12,6 +12,7 @@ # position :integer default(0), not null # published :boolean default(FALSE) # slug :string +# text_new :text # title :string # created_at :datetime not null # updated_at :datetime not null @@ -45,6 +46,7 @@ class Communication::Website::Page < ApplicationRecord include WithSlug # We override slug_unavailable? method include WithTree include WithPosition + include WithBlocks has_rich_text :text diff --git a/app/models/communication/website/with_abouts.rb b/app/models/communication/website/with_abouts.rb index 83916b815..556203472 100644 --- a/app/models/communication/website/with_abouts.rb +++ b/app/models/communication/website/with_abouts.rb @@ -26,6 +26,10 @@ module Communication::Website::WithAbouts foreign_key: :communication_website_id, dependent: :destroy + has_many :blocks, + foreign_key: :communication_website_id, + dependent: :destroy + def self.about_types [ nil, diff --git a/app/models/concerns/with_blocks.rb b/app/models/concerns/with_blocks.rb new file mode 100644 index 000000000..bdfbf632b --- /dev/null +++ b/app/models/concerns/with_blocks.rb @@ -0,0 +1,7 @@ +module WithBlocks + extend ActiveSupport::Concern + + included do + has_many :blocks, as: :about + end +end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 4396afb13..9abd988e9 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -3,16 +3,29 @@ # Table name: education_programs # # id :uuid not null, primary key +# accessibility_new :text # capacity :integer +# contacts_new :text +# content_new :text # continuing :boolean # description :text +# duration_new :text # ects :integer +# evaluation_new :text # featured_image_alt :string # level :integer # name :string +# objectives_new :text +# opportunities_new :text +# other_new :text # path :string +# pedagogy_new :text # position :integer default(0) +# prerequisites_new :text +# pricing_new :text # published :boolean default(FALSE) +# registration_new :text +# results_new :text # slug :string # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index bfe4270b1..3ff64d109 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -5,12 +5,12 @@ # id :uuid not null, primary key # abstract :text # keywords :text -# old_text :text # position :integer # published :boolean default(FALSE) # published_at :datetime # references :text # slug :string +# text_new :text # title :string # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/research/laboratory/axis.rb b/app/models/research/laboratory/axis.rb index 372f8165f..5556990de 100644 --- a/app/models/research/laboratory/axis.rb +++ b/app/models/research/laboratory/axis.rb @@ -7,6 +7,7 @@ # name :string # position :integer # short_name :string +# text_new :text # created_at :datetime not null # updated_at :datetime not null # research_laboratory_id :uuid not null, indexed diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 311541fc3..8f25ccd6d 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/models/university/person/administrator.rb b/app/models/university/person/administrator.rb index 422bbd695..45c0cf4c7 100644 --- a/app/models/university/person/administrator.rb +++ b/app/models/university/person/administrator.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/models/university/person/author.rb b/app/models/university/person/author.rb index eee35eb42..1bb44c1eb 100644 --- a/app/models/university/person/author.rb +++ b/app/models/university/person/author.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/models/university/person/researcher.rb b/app/models/university/person/researcher.rb index 165f8868d..207a0919a 100644 --- a/app/models/university/person/researcher.rb +++ b/app/models/university/person/researcher.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/models/university/person/teacher.rb b/app/models/university/person/teacher.rb index 59c75c7b3..18518ba92 100644 --- a/app/models/university/person/teacher.rb +++ b/app/models/university/person/teacher.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/views/admin/communication/website/blocks/_list.html.erb b/app/views/admin/communication/website/blocks/_list.html.erb new file mode 100644 index 000000000..cc32c21ab --- /dev/null +++ b/app/views/admin/communication/website/blocks/_list.html.erb @@ -0,0 +1,28 @@ +<div class="card flex-fill w-100"> + <div class="card-header"> + <div class="float-end"> + <%= link_to t('add'), + new_admin_communication_website_block_path(about_id: about.id, about_type: about.class.name), + class: button_classes %> + </div> + <h2 class="card-title mb-0 h5"> + <%= Communication::Website::Block.model_name.human(count: 2) %> + </h2> + </div> + <table class="<%= table_classes %>"> + <thead> + <tr> + <th><%= Communication::Website::Block.human_attribute_name('name') %></th> + <th><%= Communication::Website::Block.human_attribute_name('template') %></th> + </tr> + </thead> + <tbody> + <% about.blocks.each do |block| %> + <tr> + <td><%= link_to block, edit_admin_communication_website_block_path(block) %></td> + <td><%= block.template_i18n %></td> + </tr> + <% end %> + </tbody> + </table> +</div> diff --git a/app/views/admin/communication/website/blocks/_static.html.erb b/app/views/admin/communication/website/blocks/_static.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/admin/communication/website/blocks/edit.html.erb b/app/views/admin/communication/website/blocks/edit.html.erb new file mode 100644 index 000000000..7502b581b --- /dev/null +++ b/app/views/admin/communication/website/blocks/edit.html.erb @@ -0,0 +1,8 @@ +<% content_for :title, @block %> + +<%= simple_form_for [:admin, @block] do |f| %> + <%= render "admin/communication/website/blocks/templates/#{@block.template}/edit", f: f %> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> +<% end %> diff --git a/app/views/admin/communication/website/blocks/new.html.erb b/app/views/admin/communication/website/blocks/new.html.erb new file mode 100644 index 000000000..82d23c0ee --- /dev/null +++ b/app/views/admin/communication/website/blocks/new.html.erb @@ -0,0 +1,20 @@ +<% content_for :title, t('communication.website.block.choose_template') %> + +<div class="row"> + <% Communication::Website::Block.templates.keys.each do |template| %> + <% @block.template = template %> + <div class="col-lg-3 col-md-4"> + <div class="card"> + <div class="card-body"> + <h5 class="card-title"><%= t "enums.communication.website.block.template.#{template}" %></h5> + <%= simple_form_for [:admin, @block] do |f| %> + <%= f.input :about_type, as: :hidden %> + <%= f.input :about_id, as: :hidden %> + <%= f.input :template, as: :hidden %> + <%= f.submit t('communication.website.block.choose'), class: button_classes %> + <% end %> + </div> + </div> + </div> + <% end %> +</div> diff --git a/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb b/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb new file mode 100644 index 000000000..f805d4a4e --- /dev/null +++ b/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb @@ -0,0 +1 @@ +<%= f.input :data %> diff --git a/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb b/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb b/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/admin/communication/website/blocks/templates/partners/_edit.html.erb b/app/views/admin/communication/website/blocks/templates/partners/_edit.html.erb new file mode 100644 index 000000000..f805d4a4e --- /dev/null +++ b/app/views/admin/communication/website/blocks/templates/partners/_edit.html.erb @@ -0,0 +1 @@ +<%= f.input :data %> diff --git a/app/views/admin/communication/website/blocks/templates/partners/_show.html.erb b/app/views/admin/communication/website/blocks/templates/partners/_show.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/admin/communication/website/blocks/templates/partners/_static.html.erb b/app/views/admin/communication/website/blocks/templates/partners/_static.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/admin/communication/website/pages/show.html.erb b/app/views/admin/communication/website/pages/show.html.erb index 898684ec0..d92e5afa4 100644 --- a/app/views/admin/communication/website/pages/show.html.erb +++ b/app/views/admin/communication/website/pages/show.html.erb @@ -16,6 +16,7 @@ <%= @page.text %> </div> </div> + <%= render 'admin/communication/website/blocks/list', about: @page %> </div> <div class="col-md-4"> <div class="card flex-fill w-100"> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index afa0575fb..f7cc60ce5 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -7,6 +7,9 @@ en: communication/website: one: Website other: Websites + communication/website/block: + one: Content block + other: Content blocks communication/website/category: one: Category other: Categories @@ -43,6 +46,9 @@ en: about_type: About name: Name url: URL + communication/website/block: + name: Name + template: Kind of block communication/website/category: children: Children categories description: Description @@ -130,6 +136,9 @@ en: manage_authors: Manage authors number_of_posts: Nunber of posts website: + block: + choose_template: Choose the kind of block to add + choose: Choose git: Git imported: from: Imported from @@ -150,6 +159,10 @@ en: enums: communication: website: + block: + template: + organization_chart: Organization chart + partners: Partners menu: item: kind: diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index c59adc6e0..957fdc4fa 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -7,6 +7,9 @@ fr: communication/website: one: Site Web other: Sites Web + communication/website/block: + one: Bloc de contenu + other: Blocs de contenu communication/website/category: one: Catégorie other: Catégories @@ -43,6 +46,9 @@ fr: about_type: Sujet du site name: Nom url: URL + communication/website/block: + name: Nom + template: Type de bloc communication/website/category: children: Catégories enfants description: Description @@ -130,6 +136,9 @@ fr: manage_authors: Gérer les auteur·rice·s number_of_posts: Nombre d'actualités website: + block: + choose_template: Choisir le type de bloc à ajouter + choose: Choisir git: Git imported: from: Importé depuis @@ -150,6 +159,10 @@ fr: enums: communication: website: + block: + template: + organization_chart: Organigramme + partners: Partenaires menu: item: kind: diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 705d9fb28..6acaccc89 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -25,6 +25,7 @@ namespace :communication do resources :authors, controller: 'website/authors', only: [:index, :show] resources :posts, controller: 'website/posts' resources :curations, path: 'posts/curations', as: :post_curations, controller: 'website/posts/curations', only: [:new, :create] + resources :blocks, controller: 'website/blocks', except: [:index, :show] resources :menus, controller: 'website/menus' do resources :items, controller: 'website/menu/items', except: :index do collection do diff --git a/db/migrate/20220215094808_create_communication_website_blocks.rb b/db/migrate/20220215094808_create_communication_website_blocks.rb new file mode 100644 index 000000000..dddd548af --- /dev/null +++ b/db/migrate/20220215094808_create_communication_website_blocks.rb @@ -0,0 +1,14 @@ +class CreateCommunicationWebsiteBlocks < ActiveRecord::Migration[6.1] + def change + create_table :communication_website_blocks, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :communication_website, null: false, foreign_key: true, type: :uuid + t.references :about, polymorphic: true, type: :uuid + t.integer :template, default: 0, null: false + t.jsonb :data + t.integer :position, default: 0, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f18cf9d8e..11b72faae 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: 2022_02_10_105040) do +ActiveRecord::Schema.define(version: 2022_02_15_094808) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -79,6 +79,21 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" end + create_table "communication_website_blocks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "communication_website_id", null: false + t.string "about_type" + t.uuid "about_id" + t.integer "template", default: 0, null: false + t.jsonb "data" + t.integer "position", default: 0, null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" + t.index ["communication_website_id"], name: "index_communication_website_blocks_on_communication_website_id" + t.index ["university_id"], name: "index_communication_website_blocks_on_university_id" + end + create_table "communication_website_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false @@ -126,6 +141,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.text "github_path" t.string "featured_image_alt" t.text "description" + t.text "text_new" t.index ["communication_website_id"], name: "idx_comm_website_homes_on_communication_website_id" t.index ["university_id"], name: "index_communication_website_homes_on_university_id" end @@ -288,6 +304,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.text "github_path" t.uuid "related_category_id" t.string "featured_image_alt" + t.text "text_new" t.index ["about_type", "about_id"], name: "index_communication_website_pages_on_about" t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id" t.index ["parent_id"], name: "index_communication_website_pages_on_parent_id" @@ -407,6 +424,19 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.text "description" t.boolean "published", default: false t.string "featured_image_alt" + t.text "accessibility_new" + t.text "contacts_new" + t.text "duration_new" + t.text "evaluation_new" + t.text "objectives_new" + t.text "opportunities_new" + t.text "other_new" + t.text "pedagogy_new" + t.text "prerequisites_new" + t.text "pricing_new" + t.text "registration_new" + t.text "content_new" + t.text "results_new" t.index ["parent_id"], name: "index_education_programs_on_parent_id" t.index ["university_id"], name: "index_education_programs_on_university_id" end @@ -448,7 +478,6 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do create_table "research_journal_articles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" - t.text "old_text" t.datetime "published_at" t.uuid "university_id", null: false t.uuid "research_journal_id", null: false @@ -462,6 +491,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.string "slug" t.boolean "published", default: false t.integer "position" + t.text "text_new" t.index ["research_journal_id"], name: "index_research_journal_articles_on_research_journal_id" t.index ["research_journal_volume_id"], name: "index_research_journal_articles_on_research_journal_volume_id" t.index ["university_id"], name: "index_research_journal_articles_on_university_id" @@ -525,6 +555,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.string "short_name" + t.text "text_new" t.index ["research_laboratory_id"], name: "index_research_laboratory_axes_on_research_laboratory_id" t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id" end @@ -578,6 +609,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.text "description" t.boolean "habilitation", default: false t.boolean "tenure", default: false + t.text "biography_new" t.index ["university_id"], name: "index_university_people_on_university_id" t.index ["user_id"], name: "index_university_people_on_user_id" end @@ -655,6 +687,8 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "administration_qualiopi_indicators", "administration_qualiopi_criterions", column: "criterion_id" + add_foreign_key "communication_website_blocks", "communication_websites" + add_foreign_key "communication_website_blocks", "universities" add_foreign_key "communication_website_categories", "communication_website_categories", column: "parent_id" add_foreign_key "communication_website_categories", "communication_websites" add_foreign_key "communication_website_categories", "education_programs", column: "program_id" diff --git a/docs/communication/websites/blocks.md b/docs/communication/websites/blocks.md index 626779b0f..b71d384d8 100644 --- a/docs/communication/websites/blocks.md +++ b/docs/communication/websites/blocks.md @@ -15,6 +15,7 @@ communication/website/Block - website:references - about:references (polymorphic) - template:integer (enum) +- position:integer - data:jsonb ``` diff --git a/test/controllers/communication/website/blocks_controller_test.rb b/test/controllers/communication/website/blocks_controller_test.rb new file mode 100644 index 000000000..09dc448c4 --- /dev/null +++ b/test/controllers/communication/website/blocks_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class Communication::Website::BlocksControllerTest < ActionDispatch::IntegrationTest + setup do + @communication_website_block = communication_website_blocks(:one) + end + + test "should get index" do + get communication_website_blocks_url + assert_response :success + end + + test "should get new" do + get new_communication_website_block_url + assert_response :success + end + + test "should create communication_website_block" do + assert_difference('Communication::Website::Block.count') do + post communication_website_blocks_url, params: { communication_website_block: { about_id: @communication_website_block.about_id, communication_website_id: @communication_website_block.communication_website_id, data: @communication_website_block.data, position: @communication_website_block.position, template: @communication_website_block.template, university_id: @communication_website_block.university_id } } + end + + assert_redirected_to communication_website_block_url(Communication::Website::Block.last) + end + + test "should show communication_website_block" do + get communication_website_block_url(@communication_website_block) + assert_response :success + end + + test "should get edit" do + get edit_communication_website_block_url(@communication_website_block) + assert_response :success + end + + test "should update communication_website_block" do + patch communication_website_block_url(@communication_website_block), params: { communication_website_block: { about_id: @communication_website_block.about_id, communication_website_id: @communication_website_block.communication_website_id, data: @communication_website_block.data, position: @communication_website_block.position, template: @communication_website_block.template, university_id: @communication_website_block.university_id } } + assert_redirected_to communication_website_block_url(@communication_website_block) + end + + test "should destroy communication_website_block" do + assert_difference('Communication::Website::Block.count', -1) do + delete communication_website_block_url(@communication_website_block) + end + + assert_redirected_to communication_website_blocks_url + end +end diff --git a/test/fixtures/communication/website/blocks.yml b/test/fixtures/communication/website/blocks.yml new file mode 100644 index 000000000..6ca674282 --- /dev/null +++ b/test/fixtures/communication/website/blocks.yml @@ -0,0 +1,43 @@ +# == Schema Information +# +# Table name: communication_website_blocks +# +# id :uuid not null, primary key +# about_type :string indexed => [about_id] +# data :jsonb +# position :integer default(0), not null +# template :integer default(0), not null +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed => [about_type] +# communication_website_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_communication_website_blocks_on_about (about_type,about_id) +# index_communication_website_blocks_on_communication_website_id (communication_website_id) +# index_communication_website_blocks_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_18291ef65f (university_id => universities.id) +# fk_rails_75bd7c8d6c (communication_website_id => communication_websites.id) +# +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + university: one + communication_website: one + about: one + template: 1 + data: + position: 1 + +two: + university: two + communication_website: two + about: two + template: 1 + data: + position: 1 diff --git a/test/fixtures/research/laboratory/axes.yml b/test/fixtures/research/laboratory/axes.yml index 51a668b66..1ff6715cc 100644 --- a/test/fixtures/research/laboratory/axes.yml +++ b/test/fixtures/research/laboratory/axes.yml @@ -7,6 +7,7 @@ # name :string # position :integer # short_name :string +# text_new :text # created_at :datetime not null # updated_at :datetime not null # research_laboratory_id :uuid not null, indexed diff --git a/test/models/communication/website/block_test.rb b/test/models/communication/website/block_test.rb new file mode 100644 index 000000000..78ac46988 --- /dev/null +++ b/test/models/communication/website/block_test.rb @@ -0,0 +1,33 @@ +# == Schema Information +# +# Table name: communication_website_blocks +# +# id :uuid not null, primary key +# about_type :string indexed => [about_id] +# data :jsonb +# position :integer default(0), not null +# template :integer default(0), not null +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed => [about_type] +# communication_website_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_communication_website_blocks_on_about (about_type,about_id) +# index_communication_website_blocks_on_communication_website_id (communication_website_id) +# index_communication_website_blocks_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_18291ef65f (university_id => universities.id) +# fk_rails_75bd7c8d6c (communication_website_id => communication_websites.id) +# +require "test_helper" + +class Communication::Website::BlockTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/research/laboratory/axis_test.rb b/test/models/research/laboratory/axis_test.rb index 909fb0dd8..0ed57cec5 100644 --- a/test/models/research/laboratory/axis_test.rb +++ b/test/models/research/laboratory/axis_test.rb @@ -7,6 +7,7 @@ # name :string # position :integer # short_name :string +# text_new :text # created_at :datetime not null # updated_at :datetime not null # research_laboratory_id :uuid not null, indexed diff --git a/test/system/communication/website/blocks_test.rb b/test/system/communication/website/blocks_test.rb new file mode 100644 index 000000000..c00bb64c8 --- /dev/null +++ b/test/system/communication/website/blocks_test.rb @@ -0,0 +1,53 @@ +require "application_system_test_case" + +class Communication::Website::BlocksTest < ApplicationSystemTestCase + setup do + @communication_website_block = communication_website_blocks(:one) + end + + test "visiting the index" do + visit communication_website_blocks_url + assert_selector "h1", text: "Communication/Website/Blocks" + end + + test "creating a Block" do + visit communication_website_blocks_url + click_on "New Communication/Website/Block" + + fill_in "About", with: @communication_website_block.about_id + fill_in "Communication website", with: @communication_website_block.communication_website_id + fill_in "Data", with: @communication_website_block.data + fill_in "Position", with: @communication_website_block.position + fill_in "Template", with: @communication_website_block.template + fill_in "University", with: @communication_website_block.university_id + click_on "Create Block" + + assert_text "Block was successfully created" + click_on "Back" + end + + test "updating a Block" do + visit communication_website_blocks_url + click_on "Edit", match: :first + + fill_in "About", with: @communication_website_block.about_id + fill_in "Communication website", with: @communication_website_block.communication_website_id + fill_in "Data", with: @communication_website_block.data + fill_in "Position", with: @communication_website_block.position + fill_in "Template", with: @communication_website_block.template + fill_in "University", with: @communication_website_block.university_id + click_on "Update Block" + + assert_text "Block was successfully updated" + click_on "Back" + end + + test "destroying a Block" do + visit communication_website_blocks_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "Block was successfully destroyed" + end +end -- GitLab