From bbeb02e9a9a849ecc51ef30124073deaacf58623 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 19 Feb 2016 17:55:49 +0100 Subject: [PATCH] orders summary groups alphabetically --- app/models/proposal.rb | 2 +- spec/models/proposal_spec.rb | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 3bd1d9a72..b8d3a76be 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -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 diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index b96246fdc..134f1fbaa 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -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')