diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index df232069b..e04b275d1 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -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 diff --git a/app/models/debate.rb b/app/models/debate.rb index 086bd5ae4..7b264d036 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -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 diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 22fb55cbd..86d063a36 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -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', diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index a90423645..6be6b0ac9 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -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 diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index db9c356d0..1a6994622 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -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