@@ -1,3 +1,7 @@
|
||||
class Geozone < ActiveRecord::Base
|
||||
validates :name, presence: true
|
||||
|
||||
def self.names
|
||||
Geozone.pluck(:name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -71,9 +71,12 @@ class Proposal < ActiveRecord::Base
|
||||
|
||||
def self.for_summary
|
||||
summary = {}
|
||||
categories = ActsAsTaggableOn::Tag.category_names
|
||||
categories.each do |category|
|
||||
summary[category] = search(category).last_week.sort_by_confidence_score.limit(3)
|
||||
categories = ActsAsTaggableOn::Tag.category_names.sort
|
||||
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
|
||||
|
||||
@@ -16,7 +16,7 @@ class TagCloud
|
||||
end
|
||||
|
||||
def category_names
|
||||
ActsAsTaggableOn::Tag.category_names
|
||||
ActsAsTaggableOn::Tag.category_names.map(&:downcase)
|
||||
end
|
||||
|
||||
def geozone_names
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<% @proposals.each do |group_name, proposals| %>
|
||||
<div id="<%= group_name.parameterize %>">
|
||||
<h2 class="margin-top"><%= group_name.capitalize %></h2>
|
||||
<h2 class="margin-top"><%= group_name %></h2>
|
||||
|
||||
<% proposals[0..2].each do |proposal| %>
|
||||
<div class="proposal clear">
|
||||
|
||||
@@ -35,7 +35,7 @@ module ActsAsTaggableOn
|
||||
end
|
||||
|
||||
def self.category_names
|
||||
Tag.where("kind = 'category'").map {|tag| tag.name.downcase }
|
||||
Tag.where("kind = 'category'").pluck(:name)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1166,11 +1166,11 @@ feature 'Proposals' do
|
||||
context "Summary" do
|
||||
|
||||
scenario "Displays proposals grouped by category" do
|
||||
create(:tag, kind: 'category', name: 'culture')
|
||||
create(:tag, kind: 'category', name: 'social services')
|
||||
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') }
|
||||
3.times { create(:proposal, tag_list: 'Culture') }
|
||||
3.times { create(:proposal, tag_list: 'Social Services') }
|
||||
|
||||
create(:proposal, tag_list: 'Random')
|
||||
|
||||
@@ -1183,7 +1183,28 @@ feature 'Proposals' do
|
||||
end
|
||||
|
||||
within("#social-services") do
|
||||
expect(page).to have_content("Social services")
|
||||
expect(page).to have_content("Social Services")
|
||||
expect(page).to have_css(".proposal", count: 3)
|
||||
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
|
||||
|
||||
@@ -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
|
||||
@@ -669,7 +690,7 @@ describe Proposal do
|
||||
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
|
||||
end
|
||||
|
||||
it "should order by votes" do
|
||||
it "should order proposals by votes" do
|
||||
create(:tag, kind: 'category', name: 'culture')
|
||||
create(:proposal, tag_list: 'culture').update_column(:confidence_score, 2)
|
||||
create(:proposal, tag_list: 'culture').update_column(:confidence_score, 10)
|
||||
@@ -682,6 +703,22 @@ describe Proposal do
|
||||
expect(results.third.confidence_score).to be(2)
|
||||
end
|
||||
|
||||
it "should order groups alphabetically" do
|
||||
create(:tag, kind: 'category', name: 'health')
|
||||
create(:tag, kind: 'category', name: 'culture')
|
||||
create(:tag, kind: 'category', name: 'social services')
|
||||
|
||||
health_proposal = create(:proposal, tag_list: 'health')
|
||||
culture_proposal = create(:proposal, tag_list: 'culture')
|
||||
social_proposal = create(:proposal, tag_list: 'social services')
|
||||
|
||||
results = Proposal.for_summary.values.flatten
|
||||
|
||||
expect(results.first).to eq(culture_proposal)
|
||||
expect(results.second).to eq(health_proposal)
|
||||
expect(results.third).to eq(social_proposal)
|
||||
end
|
||||
|
||||
it "should return proposals grouped by tag" do
|
||||
create(:tag, kind: 'category', name: 'culture')
|
||||
create(:tag, kind: 'category', name: 'health')
|
||||
|
||||
Reference in New Issue
Block a user