From b2686cc6d141cd3c08baab7d858d6ea4f6b51a6f Mon Sep 17 00:00:00 2001 From: pardoam Date: Wed, 2 Dec 2015 14:48:41 +0000 Subject: [PATCH 1/3] five_last_week --- app/controllers/concerns/commentable_actions.rb | 2 +- app/models/debate.rb | 2 +- app/models/proposal.rb | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) 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', From b3ee6d492179de84b997f4b76e362310ca8b1430 Mon Sep 17 00:00:00 2001 From: MaiteHdezRivas Date: Thu, 14 Jan 2016 13:12:34 +0100 Subject: [PATCH 2/3] adds specs --- spec/models/debate_spec.rb | 14 ++++++++++++++ spec/models/proposal_spec.rb | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index a90423645..9f60e8cca 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -675,6 +675,20 @@ describe Debate do 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 end + \ No newline at end of file diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index db9c356d0..e6e5b2f6f 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -613,6 +613,18 @@ describe Proposal do end + describe "#last_week" do + it "should return proposal 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 end From d31c846a1ffe8e88192a77460fc1a8e7268a97ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 15 Jan 2016 11:10:58 +0100 Subject: [PATCH 3/3] cleans format --- spec/models/debate_spec.rb | 19 ++++++++----------- spec/models/proposal_spec.rb | 19 +++++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 9f60e8cca..6be6b0ac9 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -674,21 +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 - + 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 - \ No newline at end of file diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index e6e5b2f6f..1a6994622 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -612,19 +612,18 @@ describe Proposal do end end + end - describe "#last_week" do - it "should return proposal 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 - + 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