Commit 2c7a5b54 authored by Alexandre Friquet's avatar Alexandre Friquet
Browse files

Admin can associate activities to a club novel: refs #100.

parent 26f3ed9e
......@@ -46,7 +46,7 @@ class ClubNovelsController < ApplicationController
private
def club_novel_params
params.require(:club_novel).permit(:title, :content, :published_at,
params.require(:club_novel).permit(:title, :content, :published_at, activity_ids: [],
attached_files_attributes: attached_file_permitted_attributes,
images_attributes: image_permitted_attributes)
end
......
class ClubNovel < ApplicationRecord
has_and_belongs_to_many :activities
has_many :attached_files, :as => :attachable, :dependent => :destroy
accepts_nested_attributes_for :attached_files, :allow_destroy => true
has_many :images, :as => :imageable, :dependent => :destroy
......
......@@ -22,6 +22,17 @@
<% end -%>
<div class="item_aside">
<ul class="activities">
<% club_novel.activities.each do |activity| %>
<li>
<% if activity.poster? %>
<%= image_tag activity.poster.url(:standard), title: activity.title %>
<% else %>
<%= activity.title %>
<% end %>
</li>
<% end %>
</ul>
<ul class="gallery">
<% club_novel.images.each do |img| %>
<li>
......
......@@ -27,6 +27,7 @@
<div class="tabs">
<ul>
<li><a href="#general">Général</a></li>
<li><a href="#activities">Activités</a></li>
<li><a href="#images">Images</a></li>
<li><a href="#attachments">Pièces jointes</a></li>
</ul>
......@@ -35,6 +36,9 @@
<%= f.input :content %>
<%= f.input :published, as: :boolean, checked_value: true, unchecked_value: false %>
</div>
<div id="activities">
<%= f.association :activities, as: :check_boxes %>
</div>
<div id="attachments">
<%= render 'attached_files_form', f: f %>
</div>
......
class CreateActivitiesClubNovelsJoinTable < ActiveRecord::Migration[5.1]
def change
create_join_table :activities, :club_novels
end
end
......@@ -32,7 +32,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190813132459) do
ActiveRecord::Schema.define(version: 20190814132057) do
create_table "activities", force: :cascade do |t|
t.string "title", limit: 255
......@@ -53,6 +53,11 @@ ActiveRecord::Schema.define(version: 20190813132459) do
t.integer "activity_category_id"
end
create_table "activities_club_novels", id: false, force: :cascade do |t|
t.integer "activity_id", null: false
t.integer "club_novel_id", null: false
end
create_table "activities_events", id: false, force: :cascade do |t|
t.integer "activity_id"
t.integer "event_id"
......
......@@ -180,6 +180,31 @@ feature "Manage club novels" do
end
end
end
scenario "I can dis-associate activities to any" do
act1 = create :activity
act2 = create :activity
club_novel.activities << act1
visit edit_club_novel_path club_novel
within "form" do
click_link "Activités"
within "span.checkbox", text: act1.title do
expect(find("input[type=checkbox]")).to be_checked
end
within "span.checkbox", text: act2.title do
expect(find("input[type=checkbox]")).not_to be_checked
end
check act2.title
uncheck act1.title
click_update_button
end
expect(current_path).to eq club_novels_path
within "section#content" do
expect(page).not_to have_content act1.title
expect(page).to have_content act2.title
end
end
end
scenario "I can delete one" do
......
......@@ -5,6 +5,7 @@ RSpec.describe ClubNovel, type: :model do
context "associations" do
it { is_expected.to have_many(:attached_files) }
it { is_expected.to have_many(:images) }
it { is_expected.to have_and_belong_to_many(:activities) }
end
context "validations" do
......
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