summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Jankowski <matt@jankowski.online>2023-06-10 12:37:36 -0400
committerGitHub <noreply@github.com>2023-06-10 18:37:36 +0200
commitb5675e265e95e043018140cb3b23fe19b1608eff (patch)
tree1b7b457cf52b67b29c22e5038ad9ae18d36362c8
parent07933db7881843f7378b6a02692e1750dd522f69 (diff)
Add coverage for `CLI::Feeds` command (#25319)
-rw-r--r--lib/mastodon/cli/feeds.rb8
-rw-r--r--spec/lib/mastodon/cli/feeds_spec.rb56
2 files changed, 63 insertions, 1 deletions
diff --git a/lib/mastodon/cli/feeds.rb b/lib/mastodon/cli/feeds.rb
index 34617e75388..3467dd427cf 100644
--- a/lib/mastodon/cli/feeds.rb
+++ b/lib/mastodon/cli/feeds.rb
@@ -19,7 +19,7 @@ module Mastodon::CLI
LONG_DESC
def build(username = nil)
if options[:all] || username.nil?
- processed, = parallelize_with_progress(Account.joins(:user).merge(User.active)) do |account|
+ processed, = parallelize_with_progress(active_user_accounts) do |account|
PrecomputeFeedService.new.call(account) unless dry_run?
end
@@ -47,5 +47,11 @@ module Mastodon::CLI
redis.del(keys)
say('OK', :green)
end
+
+ private
+
+ def active_user_accounts
+ Account.joins(:user).merge(User.active)
+ end
end
end
diff --git a/spec/lib/mastodon/cli/feeds_spec.rb b/spec/lib/mastodon/cli/feeds_spec.rb
index 4e1e214effb..030f0872124 100644
--- a/spec/lib/mastodon/cli/feeds_spec.rb
+++ b/spec/lib/mastodon/cli/feeds_spec.rb
@@ -4,9 +4,65 @@ require 'rails_helper'
require 'mastodon/cli/feeds'
describe Mastodon::CLI::Feeds do
+ let(:cli) { described_class.new }
+
describe '.exit_on_failure?' do
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
+
+ describe '#build' do
+ before { Fabricate(:account) }
+
+ context 'with --all option' do
+ let(:options) { { all: true } }
+
+ it 'regenerates feeds for all accounts' do
+ expect { cli.invoke(:build, [], options) }.to output(
+ a_string_including('Regenerated feeds')
+ ).to_stdout
+ end
+ end
+
+ context 'with a username' do
+ before { Fabricate(:account, username: 'alice') }
+
+ let(:arguments) { ['alice'] }
+
+ it 'regenerates feeds for the account' do
+ expect { cli.invoke(:build, arguments) }.to output(
+ a_string_including('OK')
+ ).to_stdout
+ end
+ end
+
+ context 'with invalid username' do
+ let(:arguments) { ['invalid-username'] }
+
+ it 'displays an error and exits' do
+ expect { cli.invoke(:build, arguments) }.to output(
+ a_string_including('No such account')
+ ).to_stdout.and raise_error(SystemExit)
+ end
+ end
+ end
+
+ describe '#clear' do
+ before do
+ allow(redis).to receive(:del).with(key_namespace)
+ end
+
+ it 'clears the redis `feed:*` namespace' do
+ expect { cli.invoke(:clear) }.to output(
+ a_string_including('OK')
+ ).to_stdout
+
+ expect(redis).to have_received(:del).with(key_namespace).once
+ end
+
+ def key_namespace
+ redis.keys('feed:*')
+ end
+ end
end