displays summary for districts

This commit is contained in:
rgarcia
2016-02-19 18:15:18 +01:00
parent bbeb02e9a9
commit 6fde504e67
4 changed files with 59 additions and 10 deletions

View File

@@ -1,3 +1,7 @@
class Geozone < ActiveRecord::Base
validates :name, presence: true
def self.names
Geozone.all.map(&:name)
end
end

View File

@@ -72,8 +72,11 @@ class Proposal < ActiveRecord::Base
def self.for_summary
summary = {}
categories = ActsAsTaggableOn::Tag.category_names.sort
categories.each do |category|
summary[category] = search(category).last_week.sort_by_confidence_score.limit(3)
geozones = Geozone.names.sort
groups = categories + geozones
groups.each do |group|
summary[group] = search(group).last_week.sort_by_confidence_score.limit(3)
end
summary
end

View File

@@ -1188,6 +1188,27 @@ feature 'Proposals' do
end
end
scenario "Displays proposals grouped by district" do
california = create(:geozone, name: 'California')
new_york = create(:geozone, name: 'New York')
3.times { create(:proposal, geozone: california) }
3.times { create(:proposal, geozone: new_york) }
visit proposals_path
click_link "The most supported proposals by category"
within("#california") do
expect(page).to have_content("California")
expect(page).to have_css(".proposal", count: 3)
end
within("#new-york") do
expect(page).to have_content("New York")
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') }

View File

@@ -643,18 +643,39 @@ describe Proposal do
end
describe "for_summary" do
it "should return proposals tagged with a category" do
create(:tag, kind: 'category', name: 'culture')
proposal = create(:proposal, tag_list: 'culture')
expect(Proposal.for_summary.values.flatten).to include(proposal)
context "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.for_summary.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.for_summary.values.flatten).to_not include(proposal)
end
end
it "should not return proposals tagged without a category" do
create(:tag, kind: 'category', name: 'culture')
proposal = create(:proposal, tag_list: 'parks')
context "districts" do
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
it "should return proposals with a geozone" do
california = create(:geozone, name: 'california')
proposal = create(:proposal, geozone: california)
expect(Proposal.for_summary.values.flatten).to include(proposal)
end
it "should not return proposals without a geozone" do
create(:geozone, name: 'california')
proposal = create(:proposal)
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
end
end
it "should return proposals created this week" do