Merge pull request #1227 from consul/archived-proposals-order

sorts archived proposals by votes
This commit is contained in:
Raimond Garcia
2016-09-16 20:08:41 +02:00
committed by GitHub
2 changed files with 16 additions and 1 deletions

View File

@@ -44,7 +44,7 @@ class Proposal < ActiveRecord::Base
scope :sort_by_random, -> { reorder("RANDOM()") }
scope :sort_by_relevance, -> { all }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :sort_by_archival_date, -> { archived.order(created_at: :desc) }
scope :sort_by_archival_date, -> { archived.sort_by_confidence_score }
scope :archived, -> { where("proposals.created_at <= ?", Setting["months_to_archive_proposals"].to_i.months.ago)}
scope :not_archived, -> { where("proposals.created_at > ?", Setting["months_to_archive_proposals"].to_i.months.ago)}
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}

View File

@@ -765,6 +765,21 @@ feature 'Proposals' do
end
end
scenario "Order by votes" do
create(:proposal, :archived, title: "Least voted").update_column(:confidence_score, 10)
create(:proposal, :archived, title: "Most voted").update_column(:confidence_score, 50)
create(:proposal, :archived, title: "Some votes").update_column(:confidence_score, 25)
visit proposals_path
click_link 'Archived'
within("#proposals-list") do
expect(all(".proposal")[0].text).to match "Most voted"
expect(all(".proposal")[1].text).to match "Some votes"
expect(all(".proposal")[2].text).to match "Least voted"
end
end
end
context "Search" do