adds not_archived scope to proposal

This commit is contained in:
Juanjo Bazán
2016-09-13 12:10:31 +02:00
parent da03311f99
commit 8d48eccfed
3 changed files with 10 additions and 2 deletions

View File

@@ -46,6 +46,7 @@ class Proposal < ActiveRecord::Base
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :sort_by_archival_date, -> { archived.order(created_at: :desc) }
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)}
scope :retired, -> { where.not(retired_at: nil) }
scope :not_retired, -> { where(retired_at: nil) }

View File

@@ -164,7 +164,7 @@ FactoryGirl.define do
end
trait :archived do
created_at (Setting["months_to_archive_proposals"].to_i + 1).months.ago
created_at 25.months.ago
end
trait :with_hot_score do

View File

@@ -819,7 +819,7 @@ describe Proposal do
end
describe "archived" do
before(:all) do
before(:each) do
@new_proposal = create(:proposal)
@archived_proposal = create(:proposal, :archived)
end
@@ -835,6 +835,13 @@ describe Proposal do
expect(archived.size).to eq(1)
expect(archived.first).to eq(@archived_proposal)
end
it "scope archived" do
not_archived = Proposal.not_archived
expect(not_archived.size).to eq(1)
expect(not_archived.first).to eq(@new_proposal)
end
end
end