Commit 797eb35d authored by Alexandre Friquet's avatar Alexandre Friquet
Browse files

Admin can manage simple club novels: refs #100.

parent 4a12362e
class ClubNovelsController < ApplicationController
before_action :authorize, except: [:index, :show]
def index
@title = Menu.find_by(uid: 'club_novels')&.title
@club_novels = ClubNovel.paginate(page: params[:page])
end
def show
@club_novel = ClubNovel.find(params[:id])
end
def new
@club_novel = ClubNovel.new
end
def create
@club_novel = ClubNovel.new(club_novel_params)
if @club_novel.save
flash[:notice] = 'Info club créée avec succès.'
redirect_to @club_novel
else
render :new
end
end
def edit
@club_novel = ClubNovel.find(params[:id])
end
def update
@club_novel = ClubNovel.find(params[:id])
if @club_novel.update_attributes(club_novel_params)
flash[:notice] = 'Info club modifiée avec succès.'
redirect_to @club_novel
else
render :edit
end
end
def destroy
ClubNovel.find(params[:id]).destroy
flash[:notice] = 'Info club supprimée avec succès.'
redirect_to club_novels_path
end
private
def club_novel_params
params.require(:club_novel).permit(:title, :content)
end
end
class ClubNovel < ApplicationRecord
end
<%
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2018 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
<p><%= redcloth_help %></p>
<%= simple_nested_form_for @club_novel do |f| %>
<div class="tabs">
<ul>
<li><a href="#general">Général</a></li>
</ul>
<div id="general">
<%= f.input :title, input_html: {class: "small_text"} %>
<%= f.input :content %>
</div>
</div>
<p><%= f.button :submit %></p>
<% end %>
<%
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2018 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
<% title "Edition d'une info club" %>
<div class="card-block">
<h1><%= yield :title %></h1>
<p class="AdminCard-globalActions">
<%= custom_show_link @club_novel, 'Afficher' %>
<%= custom_list_link club_novels_path %>
</p>
<%= render :partial => 'form' %>
</div>
......@@ -2,4 +2,35 @@
<div class="card-block">
<h1><%= yield :title %></h1>
<% if admin? %>
<p class="AdminCard-globalActions">
<%= custom_add_link 'Nouvelle info club', new_club_novel_path %>
</p>
<% end -%>
</div>
<% unless @club_novels.empty? %>
<section id="club_novels">
<ul>
<% @club_novels.each do |club_novel| %>
<li class="club_novel">
<div class="desc">
<h2>
<% if admin? %>
<span class="no_print">
<%= custom_edit_link edit_club_novel_path(club_novel), :short, class: %w(tight) %>
<%= custom_delete_link club_novel, :short, class: %w(tight) %>
</span>
<% end -%>
<%= raw textilize_without_paragraph club_novel.title %>
</h2>
<%= textilize raw club_novel.content %>
</li>
<% end %>
</ul>
<%= will_paginate @club_novels %>
</section>
<% end %>
<%
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2018 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
<% title 'Nouvelle info club' %>
<div class="card-block">
<h1><%= yield :title %></h1>
<p class="AdminCard-globalActions">
<%= custom_list_link club_novels_path %>
</p>
<%= render 'form' %>
</div>
<%
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2018 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
<% title @club_novel.title %>
<article class="card-block">
<h1><%= yield :title %></h1>
<% if admin? %>
<p class="AdminCard-globalActions">
<%= custom_delete_link @club_novel, :short %>
<%= custom_edit_link edit_club_novel_path(@club_novel), :short %>
<%= custom_list_link club_novels_path %>
</p>
<% end %>
<%= textilize raw @club_novel.content %>
</article>
......@@ -211,6 +211,9 @@ fr:
other_medicosocial_org: "Autre structure médico-sociale"
subscription:
performances: "Séances"
club_novel:
title: "Intitulé"
content: "Contenu"
helpers:
submit:
create: "Créer"
......
class CreateClubNovels < ActiveRecord::Migration[5.1]
def change
create_table :club_novels do |t|
t.string :title
t.text :content
t.datetime :updated_at
t.timestamps
end
end
end
......@@ -32,7 +32,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190812122439) do
ActiveRecord::Schema.define(version: 20190813084942) do
create_table "activities", force: :cascade do |t|
t.string "title", limit: 255
......@@ -104,6 +104,13 @@ ActiveRecord::Schema.define(version: 20190812122439) do
t.datetime "file_updated_at"
end
create_table "club_novels", force: :cascade do |t|
t.string "title"
t.text "content"
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
end
create_table "contact_types", force: :cascade do |t|
t.string "title", limit: 255
t.datetime "created_at", null: false
......
FactoryGirl.define do
factory :club_novel do
title { "Item #{Faker::Lorem.unique.word}" }
content { |i| "Contenu de #{i.title}" }
updated_at nil
end
end
......@@ -30,11 +30,68 @@ feature "Manage club novels" do
before { login_as_admin }
scenario "I can create one"
scenario "I can delete one"
scenario "I can create one" do
new_club_novel = build :club_novel
scenario "I can change its info"
scenario "I can publish one"
visit club_novels_path
within "section#content" do
click_link "Nouvelle info club"
end
expect(current_path).to eq(new_club_novel_path)
within "form" do
fill_in "Intitulé", with: new_club_novel.title
fill_in "Contenu", with: new_club_novel.content
click_create_button
end
expect(current_path).to eq(club_novel_path(ClubNovel.first))
within "article" do
expect(page).to have_selector("h1", text: new_club_novel.title)
expect(page).to have_content new_club_novel.content
end
end
context "regarding edition" do
let!(:club_novel) { create :club_novel }
scenario "I can change its info" do
new_title = "Nouveau titre"
visit club_novels_path
within "section#club_novels" do
click_edit_link
end
expect(current_path).to eq(edit_club_novel_path(club_novel))
within "form" do
fill_in "Intitulé", with: new_title
click_update_button
end
expect(current_path).to eq(club_novel_path(ClubNovel.first))
within "article" do
expect(page).to have_selector("h1", text: new_title)
end
end
scenario "I can publish one"
end
scenario "I can delete one" do
club_novel = create :club_novel
visit club_novels_path
expect(page).to have_content(club_novel.title)
within "section#club_novels" do
click_delete_link
end
expect(current_path).to eq club_novels_path
expect(page).not_to have_content(club_novel.title)
end
end
context "as a guest" do
......
require 'rails_helper'
RSpec.describe ClubNovel, type: :model do
context "validations" do
it "default factory is valid" do
expect(build(:club_novel)).to be_valid
end
end
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