Commit 26f3ed9e authored by Alexandre Friquet's avatar Alexandre Friquet
Browse files

Admin can manage attached files for a club novel: refs #100.

parent dadebb65
......@@ -47,6 +47,7 @@ class ClubNovelsController < ApplicationController
def club_novel_params
params.require(:club_novel).permit(:title, :content, :published_at,
attached_files_attributes: attached_file_permitted_attributes,
images_attributes: image_permitted_attributes)
end
......
class ClubNovel < ApplicationRecord
has_many :attached_files, :as => :attachable, :dependent => :destroy
accepts_nested_attributes_for :attached_files, :allow_destroy => true
has_many :images, :as => :imageable, :dependent => :destroy
accepts_nested_attributes_for :images, :allow_destroy => true
......
......@@ -14,6 +14,13 @@
<%= textilize raw club_novel.content %>
<% unless club_novel.attached_files.empty? %>
<h3>Pièces jointes</h3>
<dl class="attachments">
<%= render partial: 'attachment', collection: club_novel.attached_files %>
</dl>
<% end -%>
<div class="item_aside">
<ul class="gallery">
<% club_novel.images.each do |img| %>
......
......@@ -28,12 +28,16 @@
<ul>
<li><a href="#general">Général</a></li>
<li><a href="#images">Images</a></li>
<li><a href="#attachments">Pièces jointes</a></li>
</ul>
<div id="general">
<%= f.input :title, input_html: {class: "small_text"} %>
<%= f.input :content %>
<%= f.input :published, as: :boolean, checked_value: true, unchecked_value: false %>
</div>
<div id="attachments">
<%= render 'attached_files_form', f: f %>
</div>
<div id="images">
<%= render 'images_form', f: f %>
</div>
......
......@@ -215,6 +215,8 @@ fr:
title: "Intitulé"
content: "Contenu"
published: "Publiée"
attached_files:
<<: *attached_file_labels
images:
<<: *image_labels
helpers:
......
......@@ -146,6 +146,40 @@ feature "Manage club novels" do
end
end
end
context "regarding attached_files" do
scenario "I can attach a file", :js do
attached_file = build :attached_file
visit edit_club_novel_path club_novel
within "form" do
click_link "Pièces jointes"
click_link "Ajouter une pièce jointe"
fill_in "Nom", with: attached_file.name
attach_file "Fichier", sample_text_path
click_update_button
end
expect(current_path).to eq club_novels_path
within "section#content li", text: club_novel.title do
expect(page).to have_selector("a", text: attached_file.name)
end
end
scenario "I can remove a file", :js do
attached_file = create :attached_file, attachable: club_novel
visit edit_club_novel_path club_novel
within "form" do
click_link "Pièces jointes"
click_link "Supprimer la pièce jointe"
click_update_button
end
expect(current_path).to eq club_novels_path
within "section#content li", text: club_novel.title do
expect(page).not_to have_selector("a", text: attached_file.name)
end
end
end
end
scenario "I can delete one" do
......
......@@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe ClubNovel, type: :model do
context "associations" do
#it { is_expected.to have_many(:attached_files) }
it { is_expected.to have_many(:attached_files) }
it { is_expected.to have_many(:images) }
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment