Fix Bug: Series index page showing series with 0 articles -#9658 (#11227)
* added join to index collections controller * + collections test to not show empty series
This commit is contained in:
parent
e3495be608
commit
9e439fcf6e
2 changed files with 14 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
|||
class CollectionsController < ApplicationController
|
||||
def index
|
||||
@user = User.find_by!(username: params[:username])
|
||||
@collections = @user.collections.order(created_at: :desc)
|
||||
@collections = @user.collections.joins(:articles).distinct.order(created_at: :desc)
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
|||
|
|
@ -2,17 +2,26 @@ require "rails_helper"
|
|||
|
||||
RSpec.describe "Visiting collections", type: :system do
|
||||
let(:user) { create(:user) }
|
||||
let!(:collection1) { create(:collection, :with_articles, user: user) }
|
||||
let!(:collection2) { create(:collection, user: user) }
|
||||
let!(:collection1_with_articles) { create(:collection, :with_articles, user: user) }
|
||||
let!(:collection2_with_articles) { create(:collection, :with_articles, user: user) }
|
||||
|
||||
let!(:collection1_without_articles) { create(:collection, user: user) }
|
||||
let!(:collection2_without_articles) { create(:collection, user: user) }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
visit user_series_path(user.username)
|
||||
end
|
||||
|
||||
it "shows all collections", :aggregate_failures do
|
||||
[collection1, collection2].each do |collection|
|
||||
it "shows all collections with articles", :aggregate_failures do
|
||||
[collection1_with_articles, collection2_with_articles].each do |collection|
|
||||
expect(page.body).to have_link("#{collection.slug} (#{collection.articles.published.size} Part Series)")
|
||||
end
|
||||
end
|
||||
|
||||
it "does not show collections without articles", :aggregate_failures do
|
||||
[collection1_without_articles, collection2_without_articles].each do |collection|
|
||||
expect(page.body).not_to have_link("#{collection.slug} (#{collection.articles.published.size} Part Series)")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue