orders summary groups alphabetically

This commit is contained in:
rgarcia
2016-02-19 17:55:49 +01:00
parent a276bea528
commit bbeb02e9a9
2 changed files with 18 additions and 2 deletions

View File

@@ -71,7 +71,7 @@ class Proposal < ActiveRecord::Base
def self.for_summary
summary = {}
categories = ActsAsTaggableOn::Tag.category_names
categories = ActsAsTaggableOn::Tag.category_names.sort
categories.each do |category|
summary[category] = search(category).last_week.sort_by_confidence_score.limit(3)
end

View File

@@ -669,7 +669,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 +682,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')