Files
.circleci
.github
app
bin
config
db
dist
lib
log
nanobox
public
spec
controllers
fabricators
features
fixtures
helpers
lib
activitypub
ostatus
settings
delivery_failure_tracker_spec.rb
extractor_spec.rb
feed_manager_spec.rb
formatter_spec.rb
hash_object_spec.rb
language_detector_spec.rb
request_spec.rb
status_filter_spec.rb
status_finder_spec.rb
tag_manager_spec.rb
user_settings_decorator_spec.rb
webfinger_resource_spec.rb
mailers
models
policies
presenters
requests
routing
services
support
validators
views
workers
rails_helper.rb
spec_helper.rb
streaming
vendor
.buildpacks
.codeclimate.yml
.dockerignore
.editorconfig
.env.nanobox
.env.production.sample
.env.test
.env.vagrant
.eslintignore
.eslintrc.js
.foreman
.gitattributes
.gitignore
.haml-lint.yml
.nanoignore
.nvmrc
.profile
.rspec
.rubocop.yml
.ruby-version
.scss-lint.yml
.slugignore
.yarnclean
AUTHORS.md
Aptfile
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Capfile
Dockerfile
Gemfile
Gemfile.lock
LICENSE
Procfile
Procfile.dev
README.md
Rakefile
Vagrantfile
app.json
babel.config.js
boxfile.yml
config.ru
docker-compose.yml
jest.config.js
package.json
postcss.config.js
priv-config
scalingo.json
yarn.lock
hometown/spec/lib/delivery_failure_tracker_spec.rb
Eugen Rochko f4ca116ea8 After 7 days of repeated delivery failures, give up on inbox ()
- A successful delivery cancels it out
- An incoming delivery from account of the inbox cancels it out
2017-09-29 03:16:20 +02:00

72 lines
2.1 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe DeliveryFailureTracker do
subject { described_class.new('http://example.com/inbox') }
describe '#track_success!' do
before do
subject.track_failure!
subject.track_success!
end
it 'marks URL as available again' do
expect(described_class.available?('http://example.com/inbox')).to be true
end
it 'resets days to 0' do
expect(subject.days).to be_zero
end
end
describe '#track_failure!' do
it 'marks URL as unavailable after 7 days of being called' do
6.times { |i| Redis.current.sadd('exhausted_deliveries:http://example.com/inbox', i) }
subject.track_failure!
expect(subject.days).to eq 7
expect(described_class.unavailable?('http://example.com/inbox')).to be true
end
it 'repeated calls on the same day do not count' do
subject.track_failure!
subject.track_failure!
expect(subject.days).to eq 1
end
end
describe '.filter' do
before do
Redis.current.sadd('unavailable_inboxes', 'http://example.com/unavailable/inbox')
end
it 'removes URLs that are unavailable' do
result = described_class.filter(['http://example.com/good/inbox', 'http://example.com/unavailable/inbox'])
expect(result).to include('http://example.com/good/inbox')
expect(result).to_not include('http://example.com/unavailable/inbox')
end
end
describe '.track_inverse_success!' do
let(:from_account) { Fabricate(:account, inbox_url: 'http://example.com/inbox', shared_inbox_url: 'http://example.com/shared/inbox') }
before do
Redis.current.sadd('unavailable_inboxes', 'http://example.com/inbox')
Redis.current.sadd('unavailable_inboxes', 'http://example.com/shared/inbox')
described_class.track_inverse_success!(from_account)
end
it 'marks inbox URL as available again' do
expect(described_class.available?('http://example.com/inbox')).to be true
end
it 'marks shared inbox URL as available again' do
expect(described_class.available?('http://example.com/shared/inbox')).to be true
end
end
end