+
+
+
<%= link_to proposal.title, namespaced_proposal_path(proposal) %>
- <% proposals[0..2].each do |proposal| %>
-
-
-
-
-
-
<%= link_to proposal.title, namespaced_proposal_path(proposal) %>
-
-
- <% if proposal.author.hidden? || proposal.author.erased? %>
- <%= t("proposals.show.author_deleted") %>
- <% else %>
- <%= proposal.author.name %>
- <% if proposal.author.official? %>
-
- <%= proposal.author.official_position %>
-
+
+ <% if proposal.author.hidden? || proposal.author.erased? %>
+ <%= t("proposals.show.author_deleted") %>
+ <% else %>
+ <%= proposal.author.name %>
+ <% if proposal.author.official? %>
+
+ <%= proposal.author.official_position %>
+
+ <% end %>
<% end %>
- <% end %>
-
+
-
- <%= link_to proposal.description, namespaced_proposal_path(proposal) %>
-
+
+ <%= link_to proposal.description, namespaced_proposal_path(proposal) %>
+
+
-
- <% end %>
+ <% end %>
+
<% end %>
diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb
index 4d1de0af1..ad746a5a9 100644
--- a/spec/features/proposals_spec.rb
+++ b/spec/features/proposals_spec.rb
@@ -1162,4 +1162,69 @@ feature 'Proposals' do
end
end
end
+
+ context "Summary" do
+
+ scenario "Displays proposals grouped by category" do
+ create(:tag, kind: 'category', name: 'Culture')
+ create(:tag, kind: 'category', name: 'Social Services')
+
+ 3.times { create(:proposal, tag_list: 'Culture') }
+ 3.times { create(:proposal, tag_list: 'Social Services') }
+
+ create(:proposal, tag_list: 'Random')
+
+ visit summary_proposals_path
+
+ within("#culture") do
+ expect(page).to have_content("Culture")
+ expect(page).to have_css(".proposal", count: 3)
+ end
+
+ within("#social-services") do
+ expect(page).to have_content("Social Services")
+ expect(page).to have_css(".proposal", count: 3)
+ end
+ end
+
+ scenario "Displays a maximum of 3 proposals per category" do
+ create(:tag, kind: 'category', name: 'Culture')
+ 4.times { create(:proposal, tag_list: 'Culture') }
+
+ visit summary_proposals_path
+
+ expect(page).to have_css(".proposal", count: 3)
+ end
+
+ scenario "Orders proposals by votes" do
+ create(:tag, kind: 'category', name: 'Culture')
+ create(:proposal, title: 'Best', tag_list: 'Culture').update_column(:confidence_score, 10)
+ create(:proposal, title: 'Worst', tag_list: 'Culture').update_column(:confidence_score, 2)
+ create(:proposal, title: 'Medium', tag_list: 'Culture').update_column(:confidence_score, 5)
+
+ visit summary_proposals_path
+
+ expect('Best').to appear_before('Medium')
+ expect('Medium').to appear_before('Worst')
+ end
+
+ scenario "Displays proposals from last week" do
+ create(:tag, kind: 'category', name: 'Culture')
+ proposal1 = create(:proposal, tag_list: 'Culture', created_at: 1.day.ago)
+ proposal2 = create(:proposal, tag_list: 'Culture', created_at: 5.days.ago)
+ proposal3 = create(:proposal, tag_list: 'Culture', created_at: 8.days.ago)
+
+ visit summary_proposals_path
+
+ within("#proposals") do
+ expect(page).to have_css('.proposal', count: 2)
+
+ expect(page).to have_content(proposal1.title)
+ expect(page).to have_content(proposal2.title)
+ expect(page).to_not have_content(proposal3.title)
+ end
+ end
+
+ end
+
end
diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb
index 8a61afcaf..45d139503 100644
--- a/spec/models/proposal_spec.rb
+++ b/spec/models/proposal_spec.rb
@@ -633,12 +633,39 @@ describe Proposal do
describe "#last_week" do
it "should return proposals created this week" do
proposal = create(:proposal)
- expect(Proposal.last_week.all).to include (proposal)
+ expect(Proposal.last_week).to include(proposal)
end
- it "should not show proposals created more than a week ago" do
+ it "should not return proposals created more than a week ago" do
proposal = create(:proposal, created_at: 8.days.ago)
- expect(Proposal.last_week.all).to_not include (proposal)
+ expect(Proposal.last_week).to_not include(proposal)
+ end
+ end
+
+ describe "grouped_by_categories" do
+ it "should return proposals tagged with a category" do
+ create(:tag, kind: 'category', name: 'Culture')
+ proposal = create(:proposal, tag_list: 'Culture')
+
+ expect(Proposal.grouped_by_categories.values.flatten).to include(proposal)
+ end
+
+ it "should not return proposals tagged without a category" do
+ create(:tag, kind: 'category', name: 'Culture')
+ proposal = create(:proposal, tag_list: 'Parks')
+
+ expect(Proposal.grouped_by_categories.values.flatten).to_not include(proposal)
+ end
+
+ it "should return proposals grouped by tag" do
+ create(:tag, kind: 'category', name: 'Culture')
+ create(:tag, kind: 'category', name: 'Health')
+
+ proposal1 = create(:proposal, tag_list: 'Culture')
+ proposal2 = create(:proposal, tag_list: 'Culture')
+ proposal3 = create(:proposal, tag_list: 'Health')
+
+ expect(Proposal.grouped_by_categories).to include('Culture' => [proposal2, proposal1], 'Health' => [proposal3])
end
end