From dd2f6543590704e6ed93396f3e4b594e94ab377a Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 13 Aug 2021 13:06:20 +0200
Subject: [PATCH] articles

---
 .../admin/application_controller.rb           |  4 +-
 .../journal/application_controller.rb         |  6 +-
 .../research/journal/articles_controller.rb   | 59 +++++++++++++++++++
 .../research/journal/articles_controller.rb   | 33 +++++++++++
 .../research/journal/volumes_controller.rb    |  4 +-
 app/models/research/journal.rb                |  1 +
 app/models/research/journal/article.rb        | 35 +++++++++++
 app/models/research/journal/volume.rb         |  3 +-
 .../research/journal/articles/_form.html.erb  | 15 +++++
 .../research/journal/articles/edit.html.erb   |  3 +
 .../research/journal/articles/index.html.erb  | 27 +++++++++
 .../research/journal/articles/new.html.erb    |  3 +
 .../research/journal/articles/show.html.erb   | 12 ++++
 .../research/journal/volumes/index.html.erb   |  6 +-
 .../admin/research/journals/show.html.erb     |  6 +-
 .../journal/articles/_volume.html.erb         |  9 +++
 .../research/journal/articles/index.html.erb  | 13 ++++
 .../journal/articles/index.json.jbuilder      |  4 ++
 .../research/journal/articles/show.html.erb   |  7 +++
 .../journal/articles/show.json.jbuilder       |  8 +++
 .../research/journal/volumes/_volume.html.erb | 15 +++--
 .../research/journal/volumes/show.html.erb    | 21 +++++--
 .../journal/volumes/show.json.jbuilder        |  6 +-
 app/views/research/journals/show.html.erb     | 12 ++++
 .../research/journals/show.json.jbuilder      |  4 ++
 config/locales/research/journal.yml           |  3 +
 config/routes/admin.rb                        |  1 +
 ...101246_create_research_journal_articles.rb | 14 +++++
 db/schema.rb                                  | 19 +++++-
 .../journal/articles_controller_test.rb       | 48 +++++++++++++++
 test/fixtures/research/journal/articles.yml   | 43 ++++++++++++++
 test/models/research/journal/article_test.rb  | 33 +++++++++++
 test/system/research/journal/articles_test.rb | 53 +++++++++++++++++
 33 files changed, 500 insertions(+), 30 deletions(-)
 create mode 100644 app/controllers/admin/research/journal/articles_controller.rb
 create mode 100644 app/controllers/research/journal/articles_controller.rb
 create mode 100644 app/models/research/journal/article.rb
 create mode 100644 app/views/admin/research/journal/articles/_form.html.erb
 create mode 100644 app/views/admin/research/journal/articles/edit.html.erb
 create mode 100644 app/views/admin/research/journal/articles/index.html.erb
 create mode 100644 app/views/admin/research/journal/articles/new.html.erb
 create mode 100644 app/views/admin/research/journal/articles/show.html.erb
 create mode 100644 app/views/research/journal/articles/_volume.html.erb
 create mode 100644 app/views/research/journal/articles/index.html.erb
 create mode 100644 app/views/research/journal/articles/index.json.jbuilder
 create mode 100644 app/views/research/journal/articles/show.html.erb
 create mode 100644 app/views/research/journal/articles/show.json.jbuilder
 create mode 100644 db/migrate/20210813101246_create_research_journal_articles.rb
 create mode 100644 test/controllers/research/journal/articles_controller_test.rb
 create mode 100644 test/fixtures/research/journal/articles.yml
 create mode 100644 test/models/research/journal/article_test.rb
 create mode 100644 test/system/research/journal/articles_test.rb

diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb
index 9c3e0febd..777f3157b 100644
--- a/app/controllers/admin/application_controller.rb
+++ b/app/controllers/admin/application_controller.rb
@@ -9,9 +9,9 @@ class Admin::ApplicationController < ApplicationController
     add_breadcrumb 'Tableau de bord', :admin_root_path
   end
 
-  def breadcrumb_for(object)
+  def breadcrumb_for(object, **options)
     return unless object
-    object.persisted? ? add_breadcrumb(object, [:admin, object])
+    object.persisted? ? add_breadcrumb(object, [:admin, object, options])
                       : add_breadcrumb('Créer')
   end
 end
diff --git a/app/controllers/admin/research/journal/application_controller.rb b/app/controllers/admin/research/journal/application_controller.rb
index 52d6f60cf..7c57ae0be 100644
--- a/app/controllers/admin/research/journal/application_controller.rb
+++ b/app/controllers/admin/research/journal/application_controller.rb
@@ -5,12 +5,12 @@ class Admin::Research::Journal::ApplicationController < Admin::Research::Applica
 
   def breadcrumb
     super
-    add_breadcrumb Research::Journal.model_name.human(count: 2), admin_research_journals_path
-    breadcrumb_for @journal
+    add_breadcrumb Research::Journal.model_name.human(count: 2), admin_research_journals_path(journal_id: nil)
+    breadcrumb_for @journal, journal_id: nil
   end
 
   def default_url_options
-    return unless params.has_key? :journal_id
+    return {} unless params.has_key? :journal_id
     {
       journal_id: params[:journal_id]
     }
diff --git a/app/controllers/admin/research/journal/articles_controller.rb b/app/controllers/admin/research/journal/articles_controller.rb
new file mode 100644
index 000000000..61e370371
--- /dev/null
+++ b/app/controllers/admin/research/journal/articles_controller.rb
@@ -0,0 +1,59 @@
+class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::ApplicationController
+  load_and_authorize_resource class: Research::Journal::Article
+
+  def index
+    breadcrumb
+  end
+
+  def show
+    breadcrumb
+  end
+
+  def new
+    breadcrumb
+  end
+
+  def edit
+    breadcrumb
+    add_breadcrumb t('edit')
+  end
+
+  def create
+    @journal = current_university.research_journals.find params[:journal_id]
+    @article.journal = @journal
+    @article.university = @journal.university
+    if @article.save
+      redirect_to admin_research_journal_article_path(@article), notice: "Article was successfully created."
+    else
+      breadcrumb
+      render :new, status: :unprocessable_entity
+    end
+  end
+
+  def update
+    if @article.update(article_params)
+      redirect_to admin_research_journal_article_path(@article), notice: "Article was successfully updated."
+    else
+      breadcrumb
+      render :edit, status: :unprocessable_entity
+  end
+  end
+
+  def destroy
+    @journal = @article.journal
+    @article.destroy
+    redirect_to admin_research_journal_path(@journal), notice: "Article was successfully destroyed."
+  end
+
+  private
+
+  def breadcrumb
+    super
+    add_breadcrumb Research::Journal::Article.model_name.human(count: 2), admin_research_journal_articles_path
+    breadcrumb_for @article
+  end
+
+  def article_params
+    params.require(:research_journal_article).permit(:title, :text, :published_at, :research_journal_volume_id)
+  end
+end
diff --git a/app/controllers/research/journal/articles_controller.rb b/app/controllers/research/journal/articles_controller.rb
new file mode 100644
index 000000000..f0525b49f
--- /dev/null
+++ b/app/controllers/research/journal/articles_controller.rb
@@ -0,0 +1,33 @@
+class Research::Journal::ArticlesController < ApplicationController
+  def index
+    @journal = current_university.research_journals.find params[:journal_id]
+    @articles = @journal.articles
+    breadcrumb
+  end
+
+  def show
+    @journal = current_university.research_journals.find params[:journal_id]
+    @article = @journal.articles.find params[:id]
+    @volume = @article.volume
+    breadcrumb
+  end
+
+  protected
+
+  def breadcrumb
+    super
+    add_breadcrumb Research.model_name.human
+    add_breadcrumb Research::Journal.model_name.human(count: 2), research_journals_path
+    add_breadcrumb @journal, @journal
+    if @article
+      if @volume
+        add_breadcrumb @volume, research_journal_volume_path(journal_id: @journal.id, id: @volume.id)
+      else
+        add_breadcrumb Research::Journal::Article.model_name.human(count: 2), research_journal_articles_path(journal_id: @journal)
+      end
+      add_breadcrumb @article
+    else
+      add_breadcrumb Research::Journal::Article.model_name.human(count: 2)
+    end
+  end
+end
diff --git a/app/controllers/research/journal/volumes_controller.rb b/app/controllers/research/journal/volumes_controller.rb
index db04246a2..37b45b1aa 100644
--- a/app/controllers/research/journal/volumes_controller.rb
+++ b/app/controllers/research/journal/volumes_controller.rb
@@ -8,8 +8,8 @@ class Research::Journal::VolumesController < ApplicationController
   def show
     @journal = current_university.research_journals.find params[:journal_id]
     @volume = @journal.volumes.find params[:id]
+    @articles = @volume.articles
     breadcrumb
-    add_breadcrumb @volume
   end
 
   protected
@@ -19,6 +19,6 @@ class Research::Journal::VolumesController < ApplicationController
     add_breadcrumb Research.model_name.human
     add_breadcrumb Research::Journal.model_name.human(count: 2), research_journals_path
     add_breadcrumb @journal, @journal
-    add_breadcrumb Research::Journal::Volume.model_name.human(count: 2), research_journal_volumes_path(journal_id: @journal)
+    add_breadcrumb @volume if @volume
   end
 end
diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb
index 5ce8ff734..db5c3985c 100644
--- a/app/models/research/journal.rb
+++ b/app/models/research/journal.rb
@@ -20,6 +20,7 @@
 class Research::Journal < ApplicationRecord
   belongs_to :university
   has_many :volumes, foreign_key: :research_journal_id
+  has_many :articles, foreign_key: :research_journal_id
 
   def to_s
     "#{title}"
diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb
new file mode 100644
index 000000000..56d568e4e
--- /dev/null
+++ b/app/models/research/journal/article.rb
@@ -0,0 +1,35 @@
+# == Schema Information
+#
+# Table name: research_journal_articles
+#
+#  id                         :uuid             not null, primary key
+#  published_at               :datetime
+#  text                       :text
+#  title                      :string
+#  created_at                 :datetime         not null
+#  updated_at                 :datetime         not null
+#  research_journal_id        :uuid             not null
+#  research_journal_volume_id :uuid
+#  university_id              :uuid             not null
+#
+# Indexes
+#
+#  index_research_journal_articles_on_research_journal_id         (research_journal_id)
+#  index_research_journal_articles_on_research_journal_volume_id  (research_journal_volume_id)
+#  index_research_journal_articles_on_university_id               (university_id)
+#
+# Foreign Keys
+#
+#  fk_rails_...  (research_journal_id => research_journals.id)
+#  fk_rails_...  (research_journal_volume_id => research_journal_volumes.id)
+#  fk_rails_...  (university_id => universities.id)
+#
+class Research::Journal::Article < ApplicationRecord
+  belongs_to :university
+  belongs_to :journal, foreign_key: :research_journal_id
+  belongs_to :volume, foreign_key: :research_journal_volume_id, optional: true
+
+  def to_s
+    "#{ title }"
+  end
+end
diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb
index 873e9f2aa..0756dba44 100644
--- a/app/models/research/journal/volume.rb
+++ b/app/models/research/journal/volume.rb
@@ -24,8 +24,9 @@
 class Research::Journal::Volume < ApplicationRecord
   belongs_to :university
   belongs_to :journal, foreign_key: :research_journal_id
+  has_many :articles, foreign_key: :research_journal_volume_id
 
   def to_s
-    "##{number} #{title}"
+    "##{ number } #{ title }"
   end
 end
diff --git a/app/views/admin/research/journal/articles/_form.html.erb b/app/views/admin/research/journal/articles/_form.html.erb
new file mode 100644
index 000000000..9e61c6117
--- /dev/null
+++ b/app/views/admin/research/journal/articles/_form.html.erb
@@ -0,0 +1,15 @@
+<%= simple_form_for [:admin, article] do |f| %>
+  <div class="row">
+    <div class="col-md-4">
+      <%= f.input :title %>
+      <%= f.association :volume, collection: @journal.volumes %>
+      <%= f.input :published_at, html5: true %>
+    </div>
+    <div class="col-md-8">
+      <%= f.input :text, input_html: { rows: 100 } %>
+    </div>
+  </div>
+  <% content_for :buttons do %>
+    <%= submit f %>
+  <% end %>
+<% end %>
diff --git a/app/views/admin/research/journal/articles/edit.html.erb b/app/views/admin/research/journal/articles/edit.html.erb
new file mode 100644
index 000000000..097d85906
--- /dev/null
+++ b/app/views/admin/research/journal/articles/edit.html.erb
@@ -0,0 +1,3 @@
+<% content_for :title, @article %>
+
+<%= render 'form', article: @article %>
diff --git a/app/views/admin/research/journal/articles/index.html.erb b/app/views/admin/research/journal/articles/index.html.erb
new file mode 100644
index 000000000..cc2cb0685
--- /dev/null
+++ b/app/views/admin/research/journal/articles/index.html.erb
@@ -0,0 +1,27 @@
+<% content_for :title, Research::Journal::Article.model_name.human(count: 2) %>
+
+<table class="table">
+  <thead>
+    <tr>
+      <th><%= Research::Journal::Article.model_name.human %></th>
+      <th>Published at</th>
+      <th></th>
+    </tr>
+  </thead>
+  <tbody>
+    <% @articles.each do |article| %>
+      <tr>
+        <td><%= link_to article, [:admin, article] %></td>
+        <td><%= article.published_at %></td>
+        <td class="text-end">
+          <%= edit_link article %>
+          <%= destroy_link article %>
+        </td>
+      </tr>
+    <% end %>
+  </tbody>
+</table>
+
+<% content_for :buttons do %>
+  <%= create_link Research::Journal::Article %>
+<% end %>
diff --git a/app/views/admin/research/journal/articles/new.html.erb b/app/views/admin/research/journal/articles/new.html.erb
new file mode 100644
index 000000000..512b1e2dc
--- /dev/null
+++ b/app/views/admin/research/journal/articles/new.html.erb
@@ -0,0 +1,3 @@
+<% content_for :title, Research::Journal::Article.model_name.human %>
+
+<%= render 'form', article: @article %>
diff --git a/app/views/admin/research/journal/articles/show.html.erb b/app/views/admin/research/journal/articles/show.html.erb
new file mode 100644
index 000000000..37a3e995b
--- /dev/null
+++ b/app/views/admin/research/journal/articles/show.html.erb
@@ -0,0 +1,12 @@
+<% content_for :title, @article %>
+
+<p>
+  <strong>Published at:</strong>
+  <%= @article.published_at&.to_date %>
+</p>
+
+<%= @article.text %>
+
+<% content_for :buttons do %>
+  <%= edit_link @article %>
+<% end %>
diff --git a/app/views/admin/research/journal/volumes/index.html.erb b/app/views/admin/research/journal/volumes/index.html.erb
index 8464b5e84..61dd2eb3c 100644
--- a/app/views/admin/research/journal/volumes/index.html.erb
+++ b/app/views/admin/research/journal/volumes/index.html.erb
@@ -11,11 +11,11 @@
   <tbody>
     <% @volumes.each do |volume| %>
       <tr>
-        <td><%= link_to volume, [:admin, volume] %></td>
+        <td><%= link_to volume, admin_research_journal_volume_path(journal_id: @journal, id: volume) %></td>
         <td><%= volume.published_at %></td>
         <td class="text-end">
-          <%= edit_link volume %>
-          <%= destroy_link volume %>
+          <%= edit_link volume, { journal_id: @journal.id } %>
+          <%#= destroy_link volume, journal_id: @journal.id %>
         </td>
       </tr>
     <% end %>
diff --git a/app/views/admin/research/journals/show.html.erb b/app/views/admin/research/journals/show.html.erb
index 402322b85..01840bc0c 100644
--- a/app/views/admin/research/journals/show.html.erb
+++ b/app/views/admin/research/journals/show.html.erb
@@ -5,16 +5,16 @@
 <h2 class="mt-5"><%= Research::Journal::Volume.model_name.human(count: 2) %></h2>
 
 <%= link_to t('create'),
-            new_admin_research_journal_volume_path,
+            new_admin_research_journal_volume_path(journal_id: @journal),
             class: button_classes %>
 
 <%= link_to 'Tous les volumes',
-            admin_research_journal_volumes_path %>
+            admin_research_journal_volumes_path(journal_id: @journal) %>
 
 <div class="row">
   <% @journal.volumes.each do |volume| %>
     <div class="col-md-3 mt-4">
-      <%= link_to volume, [:admin, volume] %>
+      <%= link_to volume, admin_research_journal_volume_path(journal_id: @journal, id: volume) %>
     </div>
   <% end %>
 </div>
diff --git a/app/views/research/journal/articles/_volume.html.erb b/app/views/research/journal/articles/_volume.html.erb
new file mode 100644
index 000000000..dccb276fb
--- /dev/null
+++ b/app/views/research/journal/articles/_volume.html.erb
@@ -0,0 +1,9 @@
+<article class="card mt-4">
+  <div class="card-body">
+    <h1 class="h4">
+      <%= link_to volume,
+      research_journal_volume_path(journal_id: volume.journal, id: volume),
+      class: 'stretched-link' %>
+    </h1>
+  </div>
+</article>
diff --git a/app/views/research/journal/articles/index.html.erb b/app/views/research/journal/articles/index.html.erb
new file mode 100644
index 000000000..6308ba227
--- /dev/null
+++ b/app/views/research/journal/articles/index.html.erb
@@ -0,0 +1,13 @@
+<% content_for :title, Research::Journal::Article.model_name.human(count: 2) %>
+
+<h1><%= Research::Journal::Article.model_name.human(count: 2) %></h1>
+
+<table class="table">
+  <tbody>
+    <% @articles.each do |article| %>
+      <tr>
+        <td><%= link_to article, research_journal_article_path(journal_id: @journal.id, id: article.id) %></td>
+      </tr>
+    <% end %>
+  </tbody>
+</table>
diff --git a/app/views/research/journal/articles/index.json.jbuilder b/app/views/research/journal/articles/index.json.jbuilder
new file mode 100644
index 000000000..2f50f62c7
--- /dev/null
+++ b/app/views/research/journal/articles/index.json.jbuilder
@@ -0,0 +1,4 @@
+json.array! @articles do |article|
+  json.extract! article, :id, :title, :text, :published_at
+  json.url research_journal_article_url(journal_id: article.journal, id: article, format: :json)
+end
diff --git a/app/views/research/journal/articles/show.html.erb b/app/views/research/journal/articles/show.html.erb
new file mode 100644
index 000000000..eea345529
--- /dev/null
+++ b/app/views/research/journal/articles/show.html.erb
@@ -0,0 +1,7 @@
+<% content_for :title, @article %>
+
+<h1><%= @article.title %></h1>
+
+<p><%= @article.published_at %></p>
+
+<%= @article.text.html_safe %>
diff --git a/app/views/research/journal/articles/show.json.jbuilder b/app/views/research/journal/articles/show.json.jbuilder
new file mode 100644
index 000000000..6b2cdca9a
--- /dev/null
+++ b/app/views/research/journal/articles/show.json.jbuilder
@@ -0,0 +1,8 @@
+json.extract! @article, :id, :title, :text, :published_at
+if @article.volume
+  json.volume do
+    json.extract! @article.volume, :id, :title, :number, :published_at
+    json.url research_journal_volume_url(journal: @volume.journal, id: @volume, format: :json)
+
+  end
+end
diff --git a/app/views/research/journal/volumes/_volume.html.erb b/app/views/research/journal/volumes/_volume.html.erb
index dccb276fb..30603618b 100644
--- a/app/views/research/journal/volumes/_volume.html.erb
+++ b/app/views/research/journal/volumes/_volume.html.erb
@@ -1,9 +1,8 @@
-<article class="card mt-4">
-  <div class="card-body">
-    <h1 class="h4">
-      <%= link_to volume,
-      research_journal_volume_path(journal_id: volume.journal, id: volume),
-      class: 'stretched-link' %>
-    </h1>
-  </div>
+<article class="card mt-4 border-0">
+  <img src="https://picsum.photos/200/300" alt="<%= volume %>">
+  <h1 class="h5 mt-3">
+    <%= link_to volume,
+                research_journal_volume_path(journal_id: volume.journal, id: volume),
+                class: 'stretched-link' %>
+  </h1>
 </article>
diff --git a/app/views/research/journal/volumes/show.html.erb b/app/views/research/journal/volumes/show.html.erb
index ace032fb1..ec07c92fa 100644
--- a/app/views/research/journal/volumes/show.html.erb
+++ b/app/views/research/journal/volumes/show.html.erb
@@ -1,11 +1,20 @@
 <% content_for :title, @volume %>
 
-<p>
-  <strong>Number:</strong>
-  <%= @volume.number %>
-</p>
+<h1><%= @volume.title %></h1>
+
+<p>#<%= @volume.number %></p>
 
 <p>
-  <strong>Published at:</strong>
-  <%= @volume.published_at %>
+  <%= @volume.published_at&.to_date %>
 </p>
+
+<h2><%= Research::Journal::Article.model_name.human(count: 2) %></h2>
+<table class="table">
+  <tbody>
+    <% @articles.each do |article| %>
+      <tr>
+        <td><%= link_to article, research_journal_article_path(journal_id: @journal.id, id: article.id) %></td>
+      </tr>
+    <% end %>
+  </tbody>
+</table>
diff --git a/app/views/research/journal/volumes/show.json.jbuilder b/app/views/research/journal/volumes/show.json.jbuilder
index 3ae703e7d..298b2d7d4 100644
--- a/app/views/research/journal/volumes/show.json.jbuilder
+++ b/app/views/research/journal/volumes/show.json.jbuilder
@@ -1,2 +1,6 @@
-json.extract! @volume, :id, :title, :number, :published_at, :created_at, :updated_at
+json.extract! @volume, :id, :title, :number, :published_at
 json.url research_journal_volume_url(journal: @volume.journal, id: @volume, format: :json)
+json.articles @volume.articles do |article|
+  json.extract! article, :id, :title, :published_at
+  json.url research_journal_article_url(journal_id: article.journal, id: article, format: :json)
+end
diff --git a/app/views/research/journals/show.html.erb b/app/views/research/journals/show.html.erb
index 2c6f746f4..707d4f0ce 100644
--- a/app/views/research/journals/show.html.erb
+++ b/app/views/research/journals/show.html.erb
@@ -7,6 +7,7 @@
   </div>
 </div>
 
+<h2><%= Research::Journal::Volume.model_name.human(count: 2) %></h2>
 <div class="row">
   <% @journal.volumes.each do |volume| %>
     <div class="col-md-3">
@@ -14,3 +15,14 @@
     </div>
   <% end %>
 </div>
+
+<h2><%= Research::Journal::Article.model_name.human(count: 2) %></h2>
+<table class="table">
+  <tbody>
+    <% @journal.articles.each do |article| %>
+      <tr>
+        <td><%= link_to article, research_journal_article_path(journal_id: @journal.id, id: article.id) %></td>
+      </tr>
+    <% end %>
+  </tbody>
+</table>
diff --git a/app/views/research/journals/show.json.jbuilder b/app/views/research/journals/show.json.jbuilder
index a43070ca7..1dd8bbd7c 100644
--- a/app/views/research/journals/show.json.jbuilder
+++ b/app/views/research/journals/show.json.jbuilder
@@ -4,3 +4,7 @@ json.volumes @journal.volumes do |volume|
   json.extract! volume, :id, :title, :published_at
   json.url research_journal_volume_url(journal_id: volume.journal, id: volume, format: :json)
 end
+json.articles @journal.articles do |article|
+  json.extract! article, :id, :title, :published_at
+  json.url research_journal_article_url(journal_id: article.journal, id: article, format: :json)
+end
diff --git a/config/locales/research/journal.yml b/config/locales/research/journal.yml
index 37e091786..ddb8da436 100644
--- a/config/locales/research/journal.yml
+++ b/config/locales/research/journal.yml
@@ -7,6 +7,9 @@ fr:
       research/journal/volume:
         one: Volume
         other: Volumes
+      research/journal/article:
+        one: Article
+        other: Articles
     attributes:
       research/journal:
         title: Titre
diff --git a/config/routes/admin.rb b/config/routes/admin.rb
index 5cba51304..c8a258bab 100644
--- a/config/routes/admin.rb
+++ b/config/routes/admin.rb
@@ -10,6 +10,7 @@ namespace :admin do
   namespace :research do
     resources :journals do
       resources :volumes, controller: 'journal/volumes'
+      resources :articles, controller: 'journal/articles'
     end
   end
 
diff --git a/db/migrate/20210813101246_create_research_journal_articles.rb b/db/migrate/20210813101246_create_research_journal_articles.rb
new file mode 100644
index 000000000..b8f017a77
--- /dev/null
+++ b/db/migrate/20210813101246_create_research_journal_articles.rb
@@ -0,0 +1,14 @@
+class CreateResearchJournalArticles < ActiveRecord::Migration[6.1]
+  def change
+    create_table :research_journal_articles, id: :uuid do |t|
+      t.string :title
+      t.text :text
+      t.datetime :published_at
+      t.references :university, null: false, foreign_key: true, type: :uuid
+      t.references :research_journal, null: false, foreign_key: true, type: :uuid
+      t.references :research_journal_volume, null: true, foreign_key: true, type: :uuid
+
+      t.timestamps
+    end
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 8c29914d8..ae7f6577e 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: 2021_08_12_094327) do
+ActiveRecord::Schema.define(version: 2021_08_13_101246) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -68,6 +68,20 @@ ActiveRecord::Schema.define(version: 2021_08_12_094327) do
     t.index ["university_id"], name: "index_features_websites_sites_on_university_id"
   end
 
+  create_table "research_journal_articles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+    t.string "title"
+    t.text "text"
+    t.datetime "published_at"
+    t.uuid "university_id", null: false
+    t.uuid "research_journal_id", null: false
+    t.uuid "research_journal_volume_id"
+    t.datetime "created_at", precision: 6, null: false
+    t.datetime "updated_at", precision: 6, null: false
+    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"
+  end
+
   create_table "research_journal_volumes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
     t.uuid "university_id", null: false
     t.uuid "research_journal_id", null: false
@@ -135,6 +149,9 @@ ActiveRecord::Schema.define(version: 2021_08_12_094327) do
   add_foreign_key "features_education_programs", "universities"
   add_foreign_key "features_education_qualiopi_indicators", "features_education_qualiopi_criterions", column: "criterion_id"
   add_foreign_key "features_websites_sites", "universities"
+  add_foreign_key "research_journal_articles", "research_journal_volumes"
+  add_foreign_key "research_journal_articles", "research_journals"
+  add_foreign_key "research_journal_articles", "universities"
   add_foreign_key "research_journal_volumes", "research_journals"
   add_foreign_key "research_journal_volumes", "universities"
   add_foreign_key "research_journals", "universities"
diff --git a/test/controllers/research/journal/articles_controller_test.rb b/test/controllers/research/journal/articles_controller_test.rb
new file mode 100644
index 000000000..2736b491f
--- /dev/null
+++ b/test/controllers/research/journal/articles_controller_test.rb
@@ -0,0 +1,48 @@
+require "test_helper"
+
+class Research::Journal::ArticlesControllerTest < ActionDispatch::IntegrationTest
+  setup do
+    @research_journal_article = research_journal_articles(:one)
+  end
+
+  test "should get index" do
+    get research_journal_articles_url
+    assert_response :success
+  end
+
+  test "should get new" do
+    get new_research_journal_article_url
+    assert_response :success
+  end
+
+  test "should create research_journal_article" do
+    assert_difference('Research::Journal::Article.count') do
+      post research_journal_articles_url, params: { research_journal_article: { published_at: @research_journal_article.published_at, research_journal_id: @research_journal_article.research_journal_id, research_journal_volume_id: @research_journal_article.research_journal_volume_id, text: @research_journal_article.text, title: @research_journal_article.title, university_id: @research_journal_article.university_id } }
+    end
+
+    assert_redirected_to research_journal_article_url(Research::Journal::Article.last)
+  end
+
+  test "should show research_journal_article" do
+    get research_journal_article_url(@research_journal_article)
+    assert_response :success
+  end
+
+  test "should get edit" do
+    get edit_research_journal_article_url(@research_journal_article)
+    assert_response :success
+  end
+
+  test "should update research_journal_article" do
+    patch research_journal_article_url(@research_journal_article), params: { research_journal_article: { published_at: @research_journal_article.published_at, research_journal_id: @research_journal_article.research_journal_id, research_journal_volume_id: @research_journal_article.research_journal_volume_id, text: @research_journal_article.text, title: @research_journal_article.title, university_id: @research_journal_article.university_id } }
+    assert_redirected_to research_journal_article_url(@research_journal_article)
+  end
+
+  test "should destroy research_journal_article" do
+    assert_difference('Research::Journal::Article.count', -1) do
+      delete research_journal_article_url(@research_journal_article)
+    end
+
+    assert_redirected_to research_journal_articles_url
+  end
+end
diff --git a/test/fixtures/research/journal/articles.yml b/test/fixtures/research/journal/articles.yml
new file mode 100644
index 000000000..3c4bb6bd2
--- /dev/null
+++ b/test/fixtures/research/journal/articles.yml
@@ -0,0 +1,43 @@
+# == Schema Information
+#
+# Table name: research_journal_articles
+#
+#  id                         :uuid             not null, primary key
+#  published_at               :datetime
+#  text                       :text
+#  title                      :string
+#  created_at                 :datetime         not null
+#  updated_at                 :datetime         not null
+#  research_journal_id        :uuid             not null
+#  research_journal_volume_id :uuid
+#  university_id              :uuid             not null
+#
+# Indexes
+#
+#  index_research_journal_articles_on_research_journal_id         (research_journal_id)
+#  index_research_journal_articles_on_research_journal_volume_id  (research_journal_volume_id)
+#  index_research_journal_articles_on_university_id               (university_id)
+#
+# Foreign Keys
+#
+#  fk_rails_...  (research_journal_id => research_journals.id)
+#  fk_rails_...  (research_journal_volume_id => research_journal_volumes.id)
+#  fk_rails_...  (university_id => universities.id)
+#
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+  title: MyString
+  text: MyText
+  published_at: 2021-08-13 12:12:48
+  university: one
+  research_journal: one
+  research_journal_volume: one
+
+two:
+  title: MyString
+  text: MyText
+  published_at: 2021-08-13 12:12:48
+  university: two
+  research_journal: two
+  research_journal_volume: two
diff --git a/test/models/research/journal/article_test.rb b/test/models/research/journal/article_test.rb
new file mode 100644
index 000000000..d84b31651
--- /dev/null
+++ b/test/models/research/journal/article_test.rb
@@ -0,0 +1,33 @@
+# == Schema Information
+#
+# Table name: research_journal_articles
+#
+#  id                         :uuid             not null, primary key
+#  published_at               :datetime
+#  text                       :text
+#  title                      :string
+#  created_at                 :datetime         not null
+#  updated_at                 :datetime         not null
+#  research_journal_id        :uuid             not null
+#  research_journal_volume_id :uuid
+#  university_id              :uuid             not null
+#
+# Indexes
+#
+#  index_research_journal_articles_on_research_journal_id         (research_journal_id)
+#  index_research_journal_articles_on_research_journal_volume_id  (research_journal_volume_id)
+#  index_research_journal_articles_on_university_id               (university_id)
+#
+# Foreign Keys
+#
+#  fk_rails_...  (research_journal_id => research_journals.id)
+#  fk_rails_...  (research_journal_volume_id => research_journal_volumes.id)
+#  fk_rails_...  (university_id => universities.id)
+#
+require "test_helper"
+
+class Research::Journal::ArticleTest < ActiveSupport::TestCase
+  # test "the truth" do
+  #   assert true
+  # end
+end
diff --git a/test/system/research/journal/articles_test.rb b/test/system/research/journal/articles_test.rb
new file mode 100644
index 000000000..f3ec7b46e
--- /dev/null
+++ b/test/system/research/journal/articles_test.rb
@@ -0,0 +1,53 @@
+require "application_system_test_case"
+
+class Research::Journal::ArticlesTest < ApplicationSystemTestCase
+  setup do
+    @research_journal_article = research_journal_articles(:one)
+  end
+
+  test "visiting the index" do
+    visit research_journal_articles_url
+    assert_selector "h1", text: "Research/Journal/Articles"
+  end
+
+  test "creating a Article" do
+    visit research_journal_articles_url
+    click_on "New Research/Journal/Article"
+
+    fill_in "Published at", with: @research_journal_article.published_at
+    fill_in "Research journal", with: @research_journal_article.research_journal_id
+    fill_in "Research journal volume", with: @research_journal_article.research_journal_volume_id
+    fill_in "Text", with: @research_journal_article.text
+    fill_in "Title", with: @research_journal_article.title
+    fill_in "University", with: @research_journal_article.university_id
+    click_on "Create Article"
+
+    assert_text "Article was successfully created"
+    click_on "Back"
+  end
+
+  test "updating a Article" do
+    visit research_journal_articles_url
+    click_on "Edit", match: :first
+
+    fill_in "Published at", with: @research_journal_article.published_at
+    fill_in "Research journal", with: @research_journal_article.research_journal_id
+    fill_in "Research journal volume", with: @research_journal_article.research_journal_volume_id
+    fill_in "Text", with: @research_journal_article.text
+    fill_in "Title", with: @research_journal_article.title
+    fill_in "University", with: @research_journal_article.university_id
+    click_on "Update Article"
+
+    assert_text "Article was successfully updated"
+    click_on "Back"
+  end
+
+  test "destroying a Article" do
+    visit research_journal_articles_url
+    page.accept_confirm do
+      click_on "Destroy", match: :first
+    end
+
+    assert_text "Article was successfully destroyed"
+  end
+end
-- 
GitLab