Do not show unpublished proposals on the homepage

The chances of an unpublished proposal appearing on the homepage was
very low because only the proposals with the most votes appear there and
unpublished proposals don't have any votes. However, it was technically
possible on new sites where only a few proposals had been created.
This commit is contained in:
taitus
2021-08-23 13:10:52 +02:00
committed by Javi Martín
parent e5cd763385
commit 7e826a9cb4
2 changed files with 9 additions and 1 deletions

View File

@@ -21,7 +21,7 @@ class Widget::Feed < ApplicationRecord
end
def proposals
Proposal.sort_by_hot_score.limit(limit)
Proposal.published.sort_by_hot_score.limit(limit)
end
def debates

View File

@@ -28,6 +28,14 @@ describe Widget::Feed do
expect(feed.proposals).to eq([best_proposal, medium_proposal, worst_proposal])
end
it "does not return unpublished proposals" do
create(:proposal, :draft, title: "Draft proposal")
feed = build(:widget_feed, kind: "proposals")
expect(feed.proposals).to be_empty
end
end
describe "#debates" do