mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-24 01:57:46 -05:00
Merge pull request #4154 from Growstuff/finish-expired-seeds-task
Add maintenance task to finish expired seeds
This commit is contained in:
committed by
GitHub
parent
749134a7de
commit
4d3c4ca10d
@@ -59,6 +59,7 @@ class Seed < ApplicationRecord
|
||||
scope :has_location, -> { joins(:owner).where.not('members.location': nil) }
|
||||
scope :recent, -> { order(created_at: :desc) }
|
||||
scope :active, -> { where('finished <> true').where('finished_at IS NULL OR finished_at < ?', Time.zone.now) }
|
||||
scope :expired, -> { active.where('plant_before < ?', Time.zone.today) }
|
||||
|
||||
def tradable
|
||||
tradable_to != 'nowhere'
|
||||
|
||||
@@ -53,4 +53,12 @@ namespace :growstuff do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "Mark seeds as finished when plant-before date expires"
|
||||
# usage: rake growstuff:finish_expired_seeds
|
||||
task finish_expired_seeds: :environment do
|
||||
Seed.expired.find_each do |seed|
|
||||
seed.update(finished: true, finished_at: Time.zone.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -132,6 +132,20 @@ describe Seed do
|
||||
end
|
||||
end
|
||||
|
||||
context 'expired' do
|
||||
it 'returns seeds with a plant_before date in the past' do
|
||||
expired_seed = FactoryBot.create(:seed, plant_before: 1.day.ago)
|
||||
not_expired_seed = FactoryBot.create(:seed, plant_before: 1.day.from_now)
|
||||
described_class.expired.should include expired_seed
|
||||
described_class.expired.should_not include not_expired_seed
|
||||
end
|
||||
|
||||
it 'does not return finished seeds' do
|
||||
expired_seed = FactoryBot.create(:seed, plant_before: 1.day.ago, finished: true)
|
||||
described_class.expired.should_not include expired_seed
|
||||
end
|
||||
end
|
||||
|
||||
context 'interesting' do
|
||||
it 'lists interesting seeds' do
|
||||
# to be interesting a seed must:
|
||||
|
||||
Reference in New Issue
Block a user