Merge branch 'pardoam-five_last_week'

This commit is contained in:
Juanjo Bazán
2016-01-15 11:11:54 +01:00
5 changed files with 26 additions and 3 deletions

View File

@@ -64,7 +64,7 @@ module CommentableActions
end
def tag_cloud
resource_model.tag_counts.order("#{resource_name.pluralize}_count": :desc, name: :asc).limit(20)
resource_model.last_week.tag_counts.order("#{resource_name.pluralize}_count": :desc, name: :asc).limit(5)
end
def load_featured_tags

View File

@@ -34,7 +34,7 @@ class Debate < 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 :last_week, -> { where("created_at >= ?", 7.days.ago)}
# Ahoy setup
visitable # Ahoy will automatically assign visit_id on create

View File

@@ -40,7 +40,8 @@ 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 :last_week, -> { where("created_at >= ?", 7.days.ago)}
pg_search_scope :pg_search, {
against: {
title: 'A',

View File

@@ -674,7 +674,18 @@ describe Debate do
end
end
end
describe "#last_week" do
it "should return debates created this week" do
debate = create(:debate)
expect(Debate.last_week.all).to include (debate)
end
it "should not show debates created more than a week ago" do
debate = create(:debate, created_at: 8.days.ago)
expect(Debate.last_week.all).to_not include (debate)
end
end
end

View File

@@ -612,7 +612,18 @@ describe Proposal do
end
end
end
describe "#last_week" do
it "should return proposals created this week" do
proposal = create(:proposal)
expect(Proposal.last_week.all).to include (proposal)
end
it "should not show proposals created more than a week ago" do
proposal = create(:proposal, created_at: 8.days.ago)
expect(Proposal.last_week.all).to_not include (proposal)
end
end
end