Fix bullet issue with includes commentable (#19145)
* Fix bullet issue with includes commentable * Flatten view logic * Restore user comment section logic (but bullet-friendly) * Try fixing podcast_episode -> podcast * Add test that would have caught the logic bug * View specs need describe to specific the path * Remove unnecessary _comments argument * Ooops, missed saving this
This commit is contained in:
parent
047a68cc66
commit
8086ef68ac
6 changed files with 135 additions and 20 deletions
|
|
@ -928,6 +928,7 @@ RSpec/DescribeClass:
|
|||
- 'spec/requests/**/*'
|
||||
- 'spec/system/**/*'
|
||||
- 'spec/tasks/**/*'
|
||||
- 'spec/views/**/*'
|
||||
|
||||
RSpec/DescribedClassModuleWrapping:
|
||||
Description: Avoid opening modules and defining specs within them.
|
||||
|
|
|
|||
|
|
@ -287,12 +287,13 @@ class StoriesController < ApplicationController
|
|||
|
||||
def assign_user_comments
|
||||
comment_count = helpers.comment_count(params[:view])
|
||||
@comments = if @user.comments_count.positive?
|
||||
@user.comments.where(deleted: false)
|
||||
.order(created_at: :desc).includes(:commentable).limit(comment_count)
|
||||
else
|
||||
[]
|
||||
end
|
||||
@comments = []
|
||||
return unless user_signed_in? && @user.comments_count.positive?
|
||||
|
||||
@comments = @user.comments.where(deleted: false)
|
||||
.order(created_at: :desc)
|
||||
.includes(commentable: [:podcast])
|
||||
.limit(comment_count)
|
||||
end
|
||||
|
||||
def assign_user_stories
|
||||
|
|
|
|||
12
app/helpers/users_helper.rb
Normal file
12
app/helpers/users_helper.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
module UsersHelper
|
||||
USER_COMMENTS_PARTIAL = "users/comments_section".freeze
|
||||
COMMENTS_LOCKED_PARTIAL = "users/comments_locked_cta".freeze
|
||||
|
||||
def user_comments_section
|
||||
if user_signed_in?
|
||||
USER_COMMENTS_PARTIAL
|
||||
else
|
||||
COMMENTS_LOCKED_PARTIAL
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -13,19 +13,9 @@
|
|||
<% end %>
|
||||
<% if @stories.present? %>
|
||||
<%= render "articles/single_story", story: @stories.first, featured: false %>
|
||||
<% if @comments.present? %>
|
||||
<% if user_signed_in? %>
|
||||
<%= render "users/comments_section" %>
|
||||
<% else %>
|
||||
<%= render "users/comments_locked_cta" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= render user_comments_section if @user.comments_count.positive? %>
|
||||
<%= render partial: "articles/single_story", collection: @stories[1, @stories.size], as: :story, locals: { featured: false } %>
|
||||
<div class="placeholder-div"></div>
|
||||
<% elsif @comments.present? %>
|
||||
<% if user_signed_in? %>
|
||||
<%= render "users/comments_section" %>
|
||||
<% else %>
|
||||
<%= render "users/comments_locked_cta" %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render user_comments_section if @user.comments_count.positive? %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@
|
|||
<% else %>
|
||||
<%= render "users/comments_locked_cta" %>
|
||||
<% end %>
|
||||
<% elsif @stories.any? || @comments.any? || @pinned_stories.any? %>
|
||||
<% elsif @stories.any? || @user.comments_count.positive? || @pinned_stories.any? %>
|
||||
<%= render "users/main_feed" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
111
spec/views/users/main_feed_spec.rb
Normal file
111
spec/views/users/main_feed_spec.rb
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "users/show" do
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
without_partial_double_verification do
|
||||
allow(view).to receive(:internal_navigation?).and_return(false)
|
||||
allow(view).to receive(:feed_style_preference).and_return("basic")
|
||||
end
|
||||
assign(:user, user)
|
||||
assign(:badges_limit, 6)
|
||||
assign(:stories, [])
|
||||
assign(:comments, [])
|
||||
assign(:pinned_stories, [])
|
||||
assign(:profile, user.profile.decorate)
|
||||
assign(:is_user_flagged, false)
|
||||
end
|
||||
|
||||
context "when signed-in" do
|
||||
before do
|
||||
visitor = create(:user)
|
||||
sign_in visitor
|
||||
end
|
||||
|
||||
context "when there are posts" do
|
||||
let(:posts) { create_list(:article, 3) }
|
||||
|
||||
before { assign :stories, posts.map(&:decorate) }
|
||||
|
||||
it "renders no featured stories" do
|
||||
render
|
||||
expect(rendered).not_to have_css(".featured-story-marker")
|
||||
expect(rendered).to have_css(".crayons-story__body")
|
||||
end
|
||||
end
|
||||
|
||||
context "when there are comments" do
|
||||
let(:comments) do
|
||||
article = create(:article, published: true)
|
||||
|
||||
Array.new(3) do
|
||||
create(:comment, user: user, commentable: article, deleted: false)
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
user.comments_count = 3
|
||||
assign :comments, comments.map(&:decorate)
|
||||
end
|
||||
|
||||
it "renders comments as required" do
|
||||
render
|
||||
expect(rendered).not_to have_css(".crayons-story__body")
|
||||
expect(rendered).not_to have_css("#comments-locked-cta")
|
||||
expect(rendered).to have_css(".profile-comment-row")
|
||||
end
|
||||
end
|
||||
|
||||
# context "when there are pinned stories" do
|
||||
#
|
||||
# end
|
||||
end
|
||||
|
||||
context "when there are posts" do
|
||||
let(:posts) { create_list(:article, 3) }
|
||||
|
||||
before { assign :stories, posts.map(&:decorate) }
|
||||
|
||||
it "renders no featured stories" do
|
||||
render
|
||||
expect(rendered).not_to have_css(".featured-story-marker")
|
||||
expect(rendered).to have_css(".crayons-story__body")
|
||||
expect(rendered).not_to have_css("#comments-locked-cta")
|
||||
end
|
||||
end
|
||||
|
||||
context "when there are comments" do
|
||||
let(:comments) do
|
||||
article = create(:article, published: true)
|
||||
|
||||
Array.new(3) do
|
||||
create(:comment, user: user, commentable: article, deleted: false)
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
user.comments_count = 3
|
||||
assign :comments, comments.map(&:decorate)
|
||||
end
|
||||
|
||||
it "does not render comments, but sign-in CTA" do
|
||||
render
|
||||
expect(rendered).not_to have_css(".profile-comment-row")
|
||||
expect(rendered).to have_css("#comments-locked-cta")
|
||||
end
|
||||
end
|
||||
|
||||
it "renders without exception" do
|
||||
render
|
||||
expect(rendered).to have_css(".profile-header")
|
||||
expect(rendered).not_to have_css(".featured-story-marker")
|
||||
expect(rendered).not_to have_css(".crayons-story__body")
|
||||
expect(rendered).not_to have_css(".profile-comment-row")
|
||||
expect(rendered).not_to have_css("#comments-locked-cta")
|
||||
end
|
||||
|
||||
# context "when there are pinned stories" do
|
||||
#
|
||||
# end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue