Skip to content

Commit 5843920

Browse files
the-codetraneMichael Cain
authored and
Michael Cain
committed
add/test whenever schedule object
1 parent 9432f64 commit 5843920

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

config/schedule.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Use this file to easily define all of your cron jobs.
2+
#
3+
# It's helpful, but not entirely necessary to understand cron before proceeding.
4+
# http://en.wikipedia.org/wiki/Cron
5+
6+
# Example:
7+
#
8+
# set :output, "/path/to/my/cron_log.log"
9+
#
10+
# every 2.hours do
11+
# command "/usr/bin/some_great_command"
12+
# runner "MyModel.some_method"
13+
# rake "some:great:rake:task"
14+
# end
15+
#
16+
# every 4.days do
17+
# runner "AnotherModel.prune_old_records"
18+
# end
19+
20+
# Learn more: http://github.com/javan/whenever
21+
22+
every 1.week do
23+
rake 'vacate_searches:vacate'
24+
end

lib/tasks/vacate_searches.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace :vacate_searches do
2-
desc "Vacate week-old searches"
2+
desc 'Vacate week-old searches'
33
task vacate: :environment do
44
Search.where('created_at < ?', (Date.today - 7.days)).destroy_all
55
end

spec/whenever/schedule_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# spec/whenever_spec.rb
2+
require 'spec_helper'
3+
4+
describe 'Whenever Schedule' do
5+
before do
6+
load 'Rakefile' # Makes sure rake tasks are loaded so you can assert in rake jobs
7+
end
8+
9+
it 'should have a rake task that runs every week' do
10+
schedule = Whenever::Test::Schedule.new(file: 'config/schedule.rb')
11+
task_name = schedule.jobs[:rake].first[:task]
12+
task_name.should include('vacate_searches:vacate')
13+
end
14+
end

0 commit comments

Comments
 (0)