Commit 4254fb45 authored by Alexandre Friquet's avatar Alexandre Friquet
Browse files

Separate published club novels with not ones: refs #100.

parent 3bbc9890
......@@ -3,7 +3,8 @@ class ClubNovelsController < ApplicationController
def index
@title = Menu.find_by(uid: 'club_novels')&.title
@club_novels = ClubNovel.paginate(page: params[:page])
@unpublished_club_novels = ClubNovel.unpublished.paginate(page: params[:page])
@published_club_novels = ClubNovel.published.ordered.paginate(page: params[:page])
end
def new
......
class ClubNovel < ApplicationRecord
scope :published, -> { where.not(published_at: nil) }
scope :unpublished, -> { where(published_at: nil) }
scope :ordered, -> { order(published_at: :desc)}
def self.per_page
4
end
def published
published_at.present?
end
......
<li class="club_novel">
<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>
<span>Publique :</span> <%= club_novel.public_label %>
<%= textilize raw club_novel.content %>
</li>
......@@ -10,30 +10,20 @@
<% 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 -%>
<% if admin? && !@unpublished_club_novels.empty? %>
<ul id="unpublished">
<%= render partial: 'club_novel', collection: @unpublished_club_novels %>
</ul>
<%= raw textilize_without_paragraph club_novel.title %>
</h2>
<%= will_paginate @unpublished_club_novels %>
<% end %>
<span>Publique :</span> <%= club_novel.public_label %>
<% unless @published_club_novels.empty? %>
<ul id="published">
<%= render partial: 'club_novel', collection: @published_club_novels %>
</ul>
<%= textilize raw club_novel.content %>
</li>
<% end %>
</ul>
<%= will_paginate @club_novels %>
<%= will_paginate @published_club_novels %>
<% end %>
</section>
<% end %>
......@@ -112,10 +112,31 @@ feature "Manage club novels" do
expect(current_path).to eq club_novels_path
expect(page).not_to have_content(club_novel.title)
end
scenario "I can see all club_novels" do
published_club_novel = create :club_novel, :published
unpublished_club_novel = create :club_novel
visit club_novels_path
within "section#club_novels" do
within "ul#unpublished" do
expect(all("li").length).to eq 1
expect(page).to have_selector("h2", text: unpublished_club_novel.title)
end
within "ul#published" do
expect(all("li").length).to eq 1
expect(page).to have_selector("h2", text: published_club_novel.title)
end
end
end
end
context "as a guest" do
scenario "I have access to the 4 latest ones" do
scenario "I have access to the 4 latest published ones" do
3.times { create :club_novel }
6.times { create :club_novel, :published }
visit root_path
within "nav#main-nav" do
click_link "Info des clubs Sport Adapté Girondins"
......@@ -124,11 +145,18 @@ feature "Manage club novels" do
expect(current_path).to eq club_novels_path
within "section#content" do
expect(page).to have_content "Info des clubs Sport Adapté Girondins"
expect(page).not_to have_selector("ul#unpublished")
within "ul#published" do
expect(all("li").length).to eq 4
end
click_link "Suivants"
expect(page).not_to have_selector("ul#unpublished")
within "ul#published" do
pending "capybara may not reset its page: ok in UI"
expect(all("li").length).to eq 2
end
end
end
scenario "I can access to a published one"
scenario "I cannot access to a private one"
scenario "I can access to the atom feed of published novels"
end
end
......@@ -29,4 +29,38 @@ RSpec.describe ClubNovel, type: :model do
end
end
end
context "scopes" do
context "regarding publication status" do
let!(:published) { create :club_novel, :published }
let!(:unpublished) { create :club_novel }
it ".published returns only published club novels" do
# Given
# When
result = ClubNovel.published
# Then
expect(result).to eq [published]
end
it ".unpublished returns only not published club novels" do
# Given
# When
result = ClubNovel.unpublished
# Then
expect(result).to eq [unpublished]
end
end
it ".ordered returns club novels by descending publication date" do
# Given
oldest = create :club_novel, published_at: Time.zone.now - 1.hour
newest = create :club_novel, published_at: Time.zone.now
# When
result = ClubNovel.ordered
# Then
expect(result).to eq [newest, oldest]
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