From 88a5143bf84ac7c1be0dbf47344ac4738c7e4038 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Mon, 7 Mar 2022 07:32:34 +0100
Subject: [PATCH] organizations

---
 .../university/organizations_controller.rb    | 68 +++++++++++++++++++
 .../admin/university/people_controller.rb     |  9 ++-
 .../university/organizations_controller.rb    | 11 +++
 app/models/university.rb                      |  2 +-
 app/models/university/organization.rb         | 52 ++++++++++++++
 app/models/university/with_people.rb          |  7 --
 .../with_people_and_organizations.rb          |  8 +++
 .../university/organizations/_form.html.erb   | 46 +++++++++++++
 .../university/organizations/_list.html.erb   | 23 +++++++
 .../university/organizations/edit.html.erb    |  3 +
 .../university/organizations/index.html.erb   |  8 +++
 .../university/organizations/new.html.erb     |  3 +
 .../university/organizations/show.html.erb    | 61 +++++++++++++++++
 .../university/organizations/static.html.erb  | 20 ++++++
 config/admin_navigation.rb                    |  1 +
 config/locales/university/en.yml              |  6 ++
 config/locales/university/fr.yml              |  6 ++
 config/routes.rb                              |  2 +
 config/routes/admin/university.rb             |  2 +-
 config/routes/extranet.rb                     |  3 +
 ...7053000_create_university_organizations.rb | 22 ++++++
 db/schema.rb                                  | 40 ++++++++++-
 .../organizations_controller_test.rb          | 48 +++++++++++++
 test/fixtures/university/organizations.yml    | 58 ++++++++++++++++
 test/models/university/organization_test.rb   | 37 ++++++++++
 test/system/university/organizations_test.rb  | 65 ++++++++++++++++++
 26 files changed, 598 insertions(+), 13 deletions(-)
 create mode 100644 app/controllers/admin/university/organizations_controller.rb
 create mode 100644 app/controllers/university/organizations_controller.rb
 create mode 100644 app/models/university/organization.rb
 delete mode 100644 app/models/university/with_people.rb
 create mode 100644 app/models/university/with_people_and_organizations.rb
 create mode 100644 app/views/admin/university/organizations/_form.html.erb
 create mode 100644 app/views/admin/university/organizations/_list.html.erb
 create mode 100644 app/views/admin/university/organizations/edit.html.erb
 create mode 100644 app/views/admin/university/organizations/index.html.erb
 create mode 100644 app/views/admin/university/organizations/new.html.erb
 create mode 100644 app/views/admin/university/organizations/show.html.erb
 create mode 100644 app/views/admin/university/organizations/static.html.erb
 create mode 100644 config/routes/extranet.rb
 create mode 100644 db/migrate/20220307053000_create_university_organizations.rb
 create mode 100644 test/controllers/university/organizations_controller_test.rb
 create mode 100644 test/fixtures/university/organizations.yml
 create mode 100644 test/models/university/organization_test.rb
 create mode 100644 test/system/university/organizations_test.rb

diff --git a/app/controllers/admin/university/organizations_controller.rb b/app/controllers/admin/university/organizations_controller.rb
new file mode 100644
index 000000000..87bbb34a2
--- /dev/null
+++ b/app/controllers/admin/university/organizations_controller.rb
@@ -0,0 +1,68 @@
+class Admin::University::OrganizationsController < Admin::University::ApplicationController
+  load_and_authorize_resource class: University::Organization,
+                              through: :current_university,
+                              through_association: :organizations
+
+  def index
+    @organizations = @organizations.ordered.page(params[:page])
+    breadcrumb
+  end
+
+  def show
+    breadcrumb
+  end
+
+  def new
+    breadcrumb
+  end
+
+  def edit
+    breadcrumb
+    add_breadcrumb t('edit')
+  end
+
+  def create
+    @organization.university = current_university
+    if @organization.save_and_sync()
+      redirect_to admin_university_organization_path(@organization),
+                  notice: t('admin.successfully_created_html', model: @organization.to_s)
+    else
+      breadcrumb
+      render :new, status: :unprocessable_entity
+    end
+  end
+
+  def update
+    if @organization.update_and_sync(organization_params)
+      redirect_to admin_university_organization_path(@organization),
+                  notice: t('admin.successfully_updated_html', model: @organization.to_s)
+    else
+      breadcrumb
+      add_breadcrumb t('edit')
+    end
+  end
+
+  def destroy
+    @organization.destroy_and_sync
+    redirect_to admin_university_organizations_url,
+                notice: t('admin.successfully_destroyed_html', model: @organization.to_s)
+  end
+
+  protected
+
+  def breadcrumb
+    super
+    add_breadcrumb  University::Organization.model_name.human(count: 2),
+                    admin_university_organizations_path
+    breadcrumb_for @organization
+  end
+
+  def organization_params
+    params.require(:university_organization)
+          .permit(
+            :name, :long_name, :description, :active, :sirene, :kind,
+            :address, :zipcode, :city, :country,
+            :website, :phone, :mail, :logo, :logo_delete
+          )
+  end
+end
diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb
index ad7485c51..fa8a15a9c 100644
--- a/app/controllers/admin/university/people_controller.rb
+++ b/app/controllers/admin/university/people_controller.rb
@@ -25,7 +25,8 @@ class Admin::University::PeopleController < Admin::University::ApplicationContro
 
   def create
     if @person.save_and_sync
-      redirect_to admin_university_person_path(@person), notice: t('admin.successfully_created_html', model: @person.to_s)
+      redirect_to admin_university_person_path(@person),
+                  notice: t('admin.successfully_created_html', model: @person.to_s)
     else
       breadcrumb
       render :new, status: :unprocessable_entity
@@ -34,7 +35,8 @@ class Admin::University::PeopleController < Admin::University::ApplicationContro
 
   def update
     if @person.update_and_sync(person_params)
-      redirect_to admin_university_person_path(@person), notice: t('admin.successfully_updated_html', model: @person.to_s)
+      redirect_to admin_university_person_path(@person),
+                  notice: t('admin.successfully_updated_html', model: @person.to_s)
     else
       breadcrumb
       add_breadcrumb t('edit')
@@ -44,7 +46,8 @@ class Admin::University::PeopleController < Admin::University::ApplicationContro
 
   def destroy
     @person.destroy_and_sync
-    redirect_to admin_university_people_url, notice: t('admin.successfully_destroyed_html', model: @person.to_s)
+    redirect_to admin_university_people_url,
+                notice: t('admin.successfully_destroyed_html', model: @person.to_s)
   end
 
   protected
diff --git a/app/controllers/university/organizations_controller.rb b/app/controllers/university/organizations_controller.rb
new file mode 100644
index 000000000..145babc5c
--- /dev/null
+++ b/app/controllers/university/organizations_controller.rb
@@ -0,0 +1,11 @@
+class University::OrganizationsController < ApplicationController
+  load_and_authorize_resource class: University::Organization,
+                              through: :current_university,
+                              through_association: :organizations
+
+  def index
+  end
+
+  def show
+  end
+end
diff --git a/app/models/university.rb b/app/models/university.rb
index 7e65310db..4c1b31dc8 100644
--- a/app/models/university.rb
+++ b/app/models/university.rb
@@ -20,7 +20,7 @@
 #  updated_at        :datetime         not null
 #
 class University < ApplicationRecord
-  include WithPeople
+  include WithPeopleAndOrganizations
   include WithCommunication
   include WithEducation
   include WithIdentifier
diff --git a/app/models/university/organization.rb b/app/models/university/organization.rb
new file mode 100644
index 000000000..6adb4785a
--- /dev/null
+++ b/app/models/university/organization.rb
@@ -0,0 +1,52 @@
+# == Schema Information
+#
+# Table name: university_organizations
+#
+#  id            :uuid             not null, primary key
+#  active        :boolean          default(TRUE)
+#  address       :string
+#  city          :string
+#  country       :string
+#  description   :text
+#  kind          :integer          default("company")
+#  long_name     :string
+#  mail          :string
+#  name          :string
+#  phone         :string
+#  sirene        :string
+#  website       :string
+#  zipcode       :string
+#  created_at    :datetime         not null
+#  updated_at    :datetime         not null
+#  university_id :uuid             not null, indexed
+#
+# Indexes
+#
+#  index_university_organizations_on_university_id  (university_id)
+#
+# Foreign Keys
+#
+#  fk_rails_35fcd198e0  (university_id => universities.id)
+#
+class University::Organization < ApplicationRecord
+  include WithGit
+  include WithBlobs
+
+  has_one_attached_deletable :logo
+
+  belongs_to :university
+
+  scope :ordered, -> { order(:name) }
+
+  validates_presence_of :name
+
+  enum kind: {
+    company: 10,
+    non_profit: 20,
+    government: 30
+  }
+
+  def to_s
+    "#{name}"
+  end
+end
diff --git a/app/models/university/with_people.rb b/app/models/university/with_people.rb
deleted file mode 100644
index 0f992a60d..000000000
--- a/app/models/university/with_people.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module University::WithPeople
-  extend ActiveSupport::Concern
-
-  included do
-    has_many :people, class_name: 'University::Person', dependent: :destroy
-  end
-end
diff --git a/app/models/university/with_people_and_organizations.rb b/app/models/university/with_people_and_organizations.rb
new file mode 100644
index 000000000..e9f4c637e
--- /dev/null
+++ b/app/models/university/with_people_and_organizations.rb
@@ -0,0 +1,8 @@
+module University::WithPeopleAndOrganizations
+  extend ActiveSupport::Concern
+
+  included do
+    has_many :people, class_name: 'University::Person', dependent: :destroy
+    has_many :organizations, class_name: 'University::Organization', dependent: :destroy
+  end
+end
diff --git a/app/views/admin/university/organizations/_form.html.erb b/app/views/admin/university/organizations/_form.html.erb
new file mode 100644
index 000000000..3f4d31f61
--- /dev/null
+++ b/app/views/admin/university/organizations/_form.html.erb
@@ -0,0 +1,46 @@
+<%= simple_form_for [:admin, organization] do |f| %>
+<div class="row">
+  <div class="col-md-6">
+    <div class="card flex-fill w-100">
+      <div class="card-header">
+        <h5 class="card-title mb-0"><%= t('content') %></h5>
+      </div>
+      <div class="card-body">
+        <%= f.input :name %>
+        <%= f.input :long_name %>
+        <%= f.input :kind, include_blank: false %>
+        <%= f.input :active %>
+        <%= f.input :sirene %>
+        <%= f.input :description %>
+        <%= f.input :logo,
+                    as: :single_deletable_file,
+                    input_html: { accept: '.jpg,.jpeg,.png,.svg' },
+                    preview: 200,
+                    resize: 1,
+                    direct_upload: true %>
+      </div>
+    </div>
+  </div>
+  <div class="col-md-6">
+    <div class="card flex-fill w-100">
+      <div class="card-header">
+        <h5 class="card-title mb-0">
+          <%= University::Organization.human_attribute_name('contact_informations') %>
+        </h5>
+      </div>
+      <div class="card-body">
+        <%= f.input :address %>
+        <%= f.input :zipcode %>
+        <%= f.input :city %>
+        <%= f.input :country %>
+        <%= f.input :website %>
+        <%= f.input :phone %>
+        <%= f.input :mail %>
+      </div>
+    </div>
+  </div>
+</div>
+    <% content_for :action_bar_right do %>
+      <%= submit f %>
+    <% end %>
+<% end %>
diff --git a/app/views/admin/university/organizations/_list.html.erb b/app/views/admin/university/organizations/_list.html.erb
new file mode 100644
index 000000000..6eb06b201
--- /dev/null
+++ b/app/views/admin/university/organizations/_list.html.erb
@@ -0,0 +1,23 @@
+<table class="<%= table_classes %>">
+  <thead>
+    <tr>
+      <th><%= University::Organization.human_attribute_name('name') %></th>
+      <th><%= University::Organization.human_attribute_name('kind') %></th>
+      <th></th>
+    </tr>
+  </thead>
+  <tbody>
+    <% organizations.each do |organization| %>
+      <tr>
+        <td><%= link_to organization, admin_university_organization_path(organization) %></td>
+        <td><%= organization.kind %></td>
+        <td class="text-end">
+          <div class="btn-group" role="group">
+            <%= edit_button organization %>
+            <%= delete_button organization %>
+          </div>
+        </td>
+      </tr>
+    <% end %>
+  </tbody>
+</table>
diff --git a/app/views/admin/university/organizations/edit.html.erb b/app/views/admin/university/organizations/edit.html.erb
new file mode 100644
index 000000000..8e990f073
--- /dev/null
+++ b/app/views/admin/university/organizations/edit.html.erb
@@ -0,0 +1,3 @@
+<% content_for :title, @organization %>
+
+<%= render 'form', organization: @organization %>
diff --git a/app/views/admin/university/organizations/index.html.erb b/app/views/admin/university/organizations/index.html.erb
new file mode 100644
index 000000000..3911980fb
--- /dev/null
+++ b/app/views/admin/university/organizations/index.html.erb
@@ -0,0 +1,8 @@
+<% content_for :title, "#{University::Organization.model_name.human(count: 2)} (#{@organizations.total_count})" %>
+
+<%= render 'admin/university/organizations/list', organizations: @organizations %>
+<%= paginate @organizations, theme: 'bootstrap-5' %>
+
+<% content_for :action_bar_right do %>
+  <%= create_link University::Organization %>
+<% end %>
diff --git a/app/views/admin/university/organizations/new.html.erb b/app/views/admin/university/organizations/new.html.erb
new file mode 100644
index 000000000..96d61c535
--- /dev/null
+++ b/app/views/admin/university/organizations/new.html.erb
@@ -0,0 +1,3 @@
+<% content_for :title, University::Organization.model_name.human %>
+
+<%= render 'form', organization: @organization %>
diff --git a/app/views/admin/university/organizations/show.html.erb b/app/views/admin/university/organizations/show.html.erb
new file mode 100644
index 000000000..f8e7951a3
--- /dev/null
+++ b/app/views/admin/university/organizations/show.html.erb
@@ -0,0 +1,61 @@
+<% content_for :title, @organization %>
+
+<p>
+  <strong>Description:</strong>
+  <%= @organization.description %>
+</p>
+
+<p>
+  <strong>Address:</strong>
+  <%= @organization.address %>
+</p>
+
+<p>
+  <strong>Zipcode:</strong>
+  <%= @organization.zipcode %>
+</p>
+
+<p>
+  <strong>City:</strong>
+  <%= @organization.city %>
+</p>
+
+<p>
+  <strong>Country:</strong>
+  <%= @organization.country %>
+</p>
+
+<p>
+  <strong>Website:</strong>
+  <%= @organization.website %>
+</p>
+
+<p>
+  <strong>Phone:</strong>
+  <%= @organization.phone %>
+</p>
+
+<p>
+  <strong>Mail:</strong>
+  <%= @organization.mail %>
+</p>
+
+<p>
+  <strong>Active:</strong>
+  <%= @organization.active %>
+</p>
+
+<p>
+  <strong>Sirene:</strong>
+  <%= @organization.sirene %>
+</p>
+
+<p>
+  <strong>Kind:</strong>
+  <%= @organization.kind %>
+</p>
+
+<% content_for :action_bar_right do %>
+  <%= edit_link @organization %>
+  <%= destroy_link @organization %>
+<% end %>
diff --git a/app/views/admin/university/organizations/static.html.erb b/app/views/admin/university/organizations/static.html.erb
new file mode 100644
index 000000000..71dcdb237
--- /dev/null
+++ b/app/views/admin/university/organizations/static.html.erb
@@ -0,0 +1,20 @@
+---
+title: >
+  <%= @about.to_s %>
+long_name: >
+  <%= @about.long_name %>
+kind: "<%= @about.kind %>"
+sirene: "<%= @about.sirene %>"
+address: "<%= @about.address %>"
+zipcode: "<%= @about.zipcode %>"
+city: "<%= @about.city %>"
+country: "<%= @about.country %>"
+phone: "<%= @about.phone %>"
+email: "<%= @about.email %>"
+website: "<%= @about.website %>"
+<% if @about.logo.attached? %>
+logo: "<%= @about.logo.blob.id %>"
+<% end %>
+description: >
+  <%= prepare_text_for_static @about.description %>
+---
diff --git a/config/admin_navigation.rb b/config/admin_navigation.rb
index d86963c69..9e8ffc691 100644
--- a/config/admin_navigation.rb
+++ b/config/admin_navigation.rb
@@ -9,6 +9,7 @@ SimpleNavigation::Configuration.run do |navigation|
     if can?(:read, User) || can?(:read, University::Person)
       primary.item :university, University.model_name.human, nil, { kind: :header }
       primary.item :university, University::Person.model_name.human(count: 2), admin_university_people_path, { icon: 'users-cog' }
+      primary.item :university, University::Organization.model_name.human(count: 2), admin_university_organizations_path, { icon: 'building' }
     end
 
     if can?(:read, Education::Program)
diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml
index 2d414f1c1..de3374063 100644
--- a/config/locales/university/en.yml
+++ b/config/locales/university/en.yml
@@ -41,6 +41,9 @@ en:
         description: Mission (in this context)
         person: Person
         target_id: ''
+      university/organization:
+        name: Name
+        long_name: Long name
       university/role:
         description: Description (SEO)
         people: People
@@ -54,6 +57,9 @@ en:
       university/person/involvement:
         one: Involvement
         other: Involvements
+      university/organization:
+        one: Third party
+        other: Third parties
       university/role:
         one: Role
         other: Roles
diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml
index 6a81eabc7..6be4c7d73 100644
--- a/config/locales/university/fr.yml
+++ b/config/locales/university/fr.yml
@@ -41,6 +41,9 @@ fr:
         description: Mission (dans ce contexte)
         person: Personne
         target_id: ''
+      university/organization:
+        name: Nom
+        long_name: Nom complet
       university/role:
         description: Description (SEO)
         people: Personnes
@@ -54,6 +57,9 @@ fr:
       university/person/involvement:
         one: Implication
         other: Implications
+      university/organization:
+        one: Tierce partie
+        other: Tierces parties
       university/role:
         one: Rôle
         other: Rôles
diff --git a/config/routes.rb b/config/routes.rb
index f58bf5c2a..7bf2ee0b0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -29,6 +29,8 @@ Rails.application.routes.draw do
     root to: 'dashboard#index'
   end
 
+  draw 'extranet'
+
   get '/media/:signed_id/:filename_with_transformations' => 'media#show', as: :medium
 
   root to: 'home#index'
diff --git a/config/routes/admin/university.rb b/config/routes/admin/university.rb
index 29714435a..25328e0bc 100644
--- a/config/routes/admin/university.rb
+++ b/config/routes/admin/university.rb
@@ -1,3 +1,3 @@
 namespace :university do
-  resources :people
+  resources :people, :organizations
 end
diff --git a/config/routes/extranet.rb b/config/routes/extranet.rb
new file mode 100644
index 000000000..2741f6f22
--- /dev/null
+++ b/config/routes/extranet.rb
@@ -0,0 +1,3 @@
+namespace :university do
+  resources :organizations, only: [:index, :show]
+end
diff --git a/db/migrate/20220307053000_create_university_organizations.rb b/db/migrate/20220307053000_create_university_organizations.rb
new file mode 100644
index 000000000..890151d3d
--- /dev/null
+++ b/db/migrate/20220307053000_create_university_organizations.rb
@@ -0,0 +1,22 @@
+class CreateUniversityOrganizations < ActiveRecord::Migration[6.1]
+  def change
+    create_table :university_organizations, id: :uuid do |t|
+      t.references :university, null: false, foreign_key: true, type: :uuid
+      t.string :name
+      t.string :long_name
+      t.text :description
+      t.string :address
+      t.string :zipcode
+      t.string :city
+      t.string :country
+      t.string :website
+      t.string :phone
+      t.string :mail
+      t.boolean :active, default: true
+      t.string :sirene
+      t.integer :kind, default: 10
+
+      t.timestamps
+    end
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 3853ceb63..26287d96d 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_03_03_145900) do
+ActiveRecord::Schema.define(version: 2022_03_07_053000) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -445,6 +445,23 @@ ActiveRecord::Schema.define(version: 2022_03_03_145900) do
     t.index ["university_id"], name: "index_education_schools_on_university_id"
   end
 
+  create_table "external_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+    t.string "title"
+    t.text "description"
+    t.string "address"
+    t.string "zipcode"
+    t.string "city"
+    t.string "country"
+    t.string "website"
+    t.string "phone"
+    t.string "mail"
+    t.boolean "active"
+    t.string "sirene"
+    t.integer "kind"
+    t.datetime "created_at", precision: 6, null: false
+    t.datetime "updated_at", precision: 6, null: false
+  end
+
   create_table "languages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
     t.string "name"
     t.string "iso_code"
@@ -572,6 +589,26 @@ ActiveRecord::Schema.define(version: 2022_03_03_145900) do
     t.string "invoice_amount"
   end
 
+  create_table "university_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+    t.uuid "university_id", null: false
+    t.string "name"
+    t.string "long_name"
+    t.text "description"
+    t.string "address"
+    t.string "zipcode"
+    t.string "city"
+    t.string "country"
+    t.string "website"
+    t.string "phone"
+    t.string "mail"
+    t.boolean "active", default: true
+    t.string "sirene"
+    t.integer "kind", default: 10
+    t.datetime "created_at", precision: 6, null: false
+    t.datetime "updated_at", precision: 6, null: false
+    t.index ["university_id"], name: "index_university_organizations_on_university_id"
+  end
+
   create_table "university_people", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
     t.uuid "university_id", null: false
     t.uuid "user_id"
@@ -726,6 +763,7 @@ ActiveRecord::Schema.define(version: 2022_03_03_145900) do
   add_foreign_key "research_theses", "universities"
   add_foreign_key "research_theses", "university_people", column: "author_id"
   add_foreign_key "research_theses", "university_people", column: "director_id"
+  add_foreign_key "university_organizations", "universities"
   add_foreign_key "university_people", "universities"
   add_foreign_key "university_people", "users"
   add_foreign_key "university_person_involvements", "universities"
diff --git a/test/controllers/university/organizations_controller_test.rb b/test/controllers/university/organizations_controller_test.rb
new file mode 100644
index 000000000..99b5e81e4
--- /dev/null
+++ b/test/controllers/university/organizations_controller_test.rb
@@ -0,0 +1,48 @@
+require "test_helper"
+
+class University::OrganizationsControllerTest < ActionDispatch::IntegrationTest
+  setup do
+    @university_organization = university_organizations(:one)
+  end
+
+  test "should get index" do
+    get university_organizations_url
+    assert_response :success
+  end
+
+  test "should get new" do
+    get new_university_organization_url
+    assert_response :success
+  end
+
+  test "should create university_organization" do
+    assert_difference('University::Organization.count') do
+      post university_organizations_url, params: { university_organization: { active: @university_organization.active, address: @university_organization.address, city: @university_organization.city, country: @university_organization.country, description: @university_organization.description, kind: @university_organization.kind, mail: @university_organization.mail, phone: @university_organization.phone, sirene: @university_organization.sirene, title: @university_organization.title, website: @university_organization.website, zipcode: @university_organization.zipcode } }
+    end
+
+    assert_redirected_to university_organization_url(University::Organization.last)
+  end
+
+  test "should show university_organization" do
+    get university_organization_url(@university_organization)
+    assert_response :success
+  end
+
+  test "should get edit" do
+    get edit_university_organization_url(@university_organization)
+    assert_response :success
+  end
+
+  test "should update university_organization" do
+    patch university_organization_url(@university_organization), params: { university_organization: { active: @university_organization.active, address: @university_organization.address, city: @university_organization.city, country: @university_organization.country, description: @university_organization.description, kind: @university_organization.kind, mail: @university_organization.mail, phone: @university_organization.phone, sirene: @university_organization.sirene, title: @university_organization.title, website: @university_organization.website, zipcode: @university_organization.zipcode } }
+    assert_redirected_to university_organization_url(@university_organization)
+  end
+
+  test "should destroy university_organization" do
+    assert_difference('University::Organization.count', -1) do
+      delete university_organization_url(@university_organization)
+    end
+
+    assert_redirected_to university_organizations_url
+  end
+end
diff --git a/test/fixtures/university/organizations.yml b/test/fixtures/university/organizations.yml
new file mode 100644
index 000000000..fee586714
--- /dev/null
+++ b/test/fixtures/university/organizations.yml
@@ -0,0 +1,58 @@
+# == Schema Information
+#
+# Table name: university_organizations
+#
+#  id            :uuid             not null, primary key
+#  active        :boolean          default(TRUE)
+#  address       :string
+#  city          :string
+#  country       :string
+#  description   :text
+#  kind          :integer          default("company")
+#  long_name     :string
+#  mail          :string
+#  name          :string
+#  phone         :string
+#  sirene        :string
+#  website       :string
+#  zipcode       :string
+#  created_at    :datetime         not null
+#  updated_at    :datetime         not null
+#  university_id :uuid             not null, indexed
+#
+# Indexes
+#
+#  index_university_organizations_on_university_id  (university_id)
+#
+# Foreign Keys
+#
+#  fk_rails_35fcd198e0  (university_id => universities.id)
+#
+
+one:
+  title: MyString
+  description: MyText
+  address: MyString
+  zipcode: MyString
+  city: MyString
+  country: MyString
+  website: MyString
+  phone: MyString
+  mail: MyString
+  active: false
+  sirene: MyString
+  kind: 1
+
+two:
+  title: MyString
+  description: MyText
+  address: MyString
+  zipcode: MyString
+  city: MyString
+  country: MyString
+  website: MyString
+  phone: MyString
+  mail: MyString
+  active: false
+  sirene: MyString
+  kind: 1
diff --git a/test/models/university/organization_test.rb b/test/models/university/organization_test.rb
new file mode 100644
index 000000000..1616f324c
--- /dev/null
+++ b/test/models/university/organization_test.rb
@@ -0,0 +1,37 @@
+# == Schema Information
+#
+# Table name: university_organizations
+#
+#  id            :uuid             not null, primary key
+#  active        :boolean          default(TRUE)
+#  address       :string
+#  city          :string
+#  country       :string
+#  description   :text
+#  kind          :integer          default("company")
+#  long_name     :string
+#  mail          :string
+#  name          :string
+#  phone         :string
+#  sirene        :string
+#  website       :string
+#  zipcode       :string
+#  created_at    :datetime         not null
+#  updated_at    :datetime         not null
+#  university_id :uuid             not null, indexed
+#
+# Indexes
+#
+#  index_university_organizations_on_university_id  (university_id)
+#
+# Foreign Keys
+#
+#  fk_rails_35fcd198e0  (university_id => universities.id)
+#
+require "test_helper"
+
+class University::OrganizationTest < ActiveSupport::TestCase
+  # test "the truth" do
+  #   assert true
+  # end
+end
diff --git a/test/system/university/organizations_test.rb b/test/system/university/organizations_test.rb
new file mode 100644
index 000000000..1a94a1c5e
--- /dev/null
+++ b/test/system/university/organizations_test.rb
@@ -0,0 +1,65 @@
+require "application_system_test_case"
+
+class University::OrganizationsTest < ApplicationSystemTestCase
+  setup do
+    @university_organization = university_organizations(:one)
+  end
+
+  test "visiting the index" do
+    visit university_organizations_url
+    assert_selector "h1", text: "University/Organizations"
+  end
+
+  test "creating a Organization" do
+    visit university_organizations_url
+    click_on "New University/Organization"
+
+    check "Active" if @university_organization.active
+    fill_in "Address", with: @university_organization.address
+    fill_in "City", with: @university_organization.city
+    fill_in "Country", with: @university_organization.country
+    fill_in "Description", with: @university_organization.description
+    fill_in "Kind", with: @university_organization.kind
+    fill_in "Mail", with: @university_organization.mail
+    fill_in "Phone", with: @university_organization.phone
+    fill_in "Sirene", with: @university_organization.sirene
+    fill_in "Title", with: @university_organization.title
+    fill_in "Website", with: @university_organization.website
+    fill_in "Zipcode", with: @university_organization.zipcode
+    click_on "Create Organization"
+
+    assert_text "Organization was successfully created"
+    click_on "Back"
+  end
+
+  test "updating a Organization" do
+    visit university_organizations_url
+    click_on "Edit", match: :first
+
+    check "Active" if @university_organization.active
+    fill_in "Address", with: @university_organization.address
+    fill_in "City", with: @university_organization.city
+    fill_in "Country", with: @university_organization.country
+    fill_in "Description", with: @university_organization.description
+    fill_in "Kind", with: @university_organization.kind
+    fill_in "Mail", with: @university_organization.mail
+    fill_in "Phone", with: @university_organization.phone
+    fill_in "Sirene", with: @university_organization.sirene
+    fill_in "Title", with: @university_organization.title
+    fill_in "Website", with: @university_organization.website
+    fill_in "Zipcode", with: @university_organization.zipcode
+    click_on "Update Organization"
+
+    assert_text "Organization was successfully updated"
+    click_on "Back"
+  end
+
+  test "destroying a Organization" do
+    visit university_organizations_url
+    page.accept_confirm do
+      click_on "Destroy", match: :first
+    end
+
+    assert_text "Organization was successfully destroyed"
+  end
+end
-- 
GitLab