diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb index 9c3e0febd5d7ab67ff86cbf432f517ef5f987dad..777f3157b93d64fff50bb2cb22bb82d7246c9f85 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 52d6f60cff8343207ad34271d923c4791c6c0494..7c57ae0be3016f5246491216966e68d169b7bc68 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 0000000000000000000000000000000000000000..61e3703710cc44172bad495ee4702c147b3f625d --- /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 0000000000000000000000000000000000000000..f0525b49f16469966683cb68a56022ba72f126f1 --- /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 db04246a2f3ecf8aecf3d7e44ade75666cd0e7c1..37b45b1aa60cbec53cb126a0ac8f4e154871f4ec 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 5ce8ff734e27d09aa6ab8234bd15411c61d04c42..db5c3985cdfb90fbfedcf76fe0674b088e0efff0 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 0000000000000000000000000000000000000000..56d568e4ef621fc9916eef717eeef382f2a4c9a0 --- /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 873e9f2aa7109dbc2911cf0176c7a0e62ff7cd51..0756dba4487d693c7d8d4ca2857af3b18092bea5 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 0000000000000000000000000000000000000000..9e61c6117d4585cf9db0b4bc49b51679ffb4dcab --- /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 0000000000000000000000000000000000000000..097d859060b778e20278a7ccf0eb489fdb41aea9 --- /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 0000000000000000000000000000000000000000..cc2cb06851b32d25e4baf86bd74e20c0db06890e --- /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 0000000000000000000000000000000000000000..512b1e2dcb8db3e80081bd0840f5c2a8384eff79 --- /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 0000000000000000000000000000000000000000..37a3e995b225eb7d6291ce3340e67f3f7a4c33d3 --- /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 8464b5e84efa4335c7609f61c3b4b7342190a337..61dd2eb3c92790d220f8eda1518c99ebf66aa064 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 402322b85eb126733b9ac7dd278f028429179e49..01840bc0c4685c5c2d18f58456c10023a24f9c9b 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 0000000000000000000000000000000000000000..dccb276fb27ec63a808aee28d701559c19171c6c --- /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 0000000000000000000000000000000000000000..6308ba227d8094b85a580897367ccdba3e3f9f44 --- /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 0000000000000000000000000000000000000000..2f50f62c784732bebe0dd231511f64337ad06739 --- /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 0000000000000000000000000000000000000000..eea345529cef9c7cc2387c35d187d2954083dfce --- /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 0000000000000000000000000000000000000000..6b2cdca9a68a0319ee31c1d0feddbaecd9e05c03 --- /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 dccb276fb27ec63a808aee28d701559c19171c6c..30603618bd8640298c65688aecdc1ace5af256ea 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 ace032fb16a504f5317eba378781fd2028d4a2bd..ec07c92fa125d748850068d1c4e950627b6bba1e 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 3ae703e7d7e78771e700f4b59c8ffe87a2802f4d..298b2d7d48038e041d811580421b7aa0a49bb280 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 2c6f746f43e897f717e209c96a73cb71a5c6287c..707d4f0ce7d3bff706c0eada31a9e7a8e159b68e 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 a43070ca7b563c94c382ea326d7760dfff8ee253..1dd8bbd7c7fcd402c6b39561e9c9311056590992 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 37e091786b07bf6673a1c99774ca6052276edfbf..ddb8da436aeb392080adab87de96b140701d82ba 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 5cba513043d613c2245612b5443d2cc38e36055e..c8a258bab32cbfaaf20850e411dcc9102f2cf69c 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 0000000000000000000000000000000000000000..b8f017a77a1ef4be6d8999650b19eec57da6d30d --- /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 8c29914d8299d0892d6ee8db5f5596359ce0eaa4..ae7f6577e00945fdd9099cd23a9b6b643dc3bfd9 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 0000000000000000000000000000000000000000..2736b491fc4719c67e51059839844f835462e7df --- /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 0000000000000000000000000000000000000000..3c4bb6bd2edff7015e39629011bdf46ff84ab17e --- /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 0000000000000000000000000000000000000000..d84b3165143a4a4494719ec0fc6e36c0c0a9646e --- /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 0000000000000000000000000000000000000000..f3ec7b46e2abced666eae18e482b09225f85dece --- /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