diff options
author | Matt Jankowski <mjankowski@thoughtbot.com> | 2017-05-22 13:36:21 -0400 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-22 19:36:21 +0200 |
commit | ec34ec63b195d94a1ee43ac584ff74d84822222f (patch) | |
tree | f135626f8a790e78fc86a2102d58f5f433e2b080 /spec | |
parent | 4a4733b397c9a5d3a69d7b2156f4f8aa62ff0c32 (diff) |
Specs for cleanup workers (#3235)
* Add spec files for feed and media cleanup workers * Add coverage for feed and media cleanup schedulers * Clean up feed and media cleanup workers
Diffstat (limited to 'spec')
-rw-r--r-- | spec/workers/scheduler/feed_cleanup_scheduler_spec.rb | 19 | ||||
-rw-r--r-- | spec/workers/scheduler/media_cleanup_scheduler_spec.rb | 15 |
2 files changed, 34 insertions, 0 deletions
diff --git a/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb b/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb new file mode 100644 index 000000000..4c709a2c9 --- /dev/null +++ b/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +describe Scheduler::FeedCleanupScheduler do + subject { described_class.new } + + let!(:active_user) { Fabricate(:user, current_sign_in_at: 2.days.ago) } + let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) } + + it 'clears feeds of inactives' do + expect_any_instance_of(Redis).to receive(:del).with(feed_key_for(inactive_user)) + expect_any_instance_of(Redis).not_to receive(:del).with(feed_key_for(active_user)) + + subject.perform + end + + def feed_key_for(user) + FeedManager.instance.key(:home, user.account_id) + end +end diff --git a/spec/workers/scheduler/media_cleanup_scheduler_spec.rb b/spec/workers/scheduler/media_cleanup_scheduler_spec.rb new file mode 100644 index 000000000..8a0da67e1 --- /dev/null +++ b/spec/workers/scheduler/media_cleanup_scheduler_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +describe Scheduler::MediaCleanupScheduler do + subject { described_class.new } + + let!(:old_media) { Fabricate(:media_attachment, account_id: nil, created_at: 10.days.ago) } + let!(:new_media) { Fabricate(:media_attachment, account_id: nil, created_at: 1.hour.ago) } + + it 'removes old media records' do + subject.perform + + expect { old_media.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect(new_media.reload).to be_persisted + end +end |