about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-04-28 19:24:18 +0200
committerGitHub <noreply@github.com>2022-04-28 19:24:18 +0200
commit78f7f23ad21359893cb022b7c2f7644d5c22cb43 (patch)
tree77b919683a8656a361d7d62c8745233bc8b2d310 /spec
parent6a9d1549484a6fb02d7d01e884577a7185302046 (diff)
parentf23f784f1811a5e7ae82faaf8868e389e9608f5d (diff)
Merge pull request #1756 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/concerns/user_tracking_concern_spec.rb8
-rw-r--r--spec/lib/activitypub/activity/move_spec.rb4
-rw-r--r--spec/lib/delivery_failure_tracker_spec.rb2
-rw-r--r--spec/lib/feed_manager_spec.rb28
-rw-r--r--spec/models/home_feed_spec.rb4
-rw-r--r--spec/rails_helper.rb4
-rw-r--r--spec/services/after_block_service_spec.rb8
-rw-r--r--spec/services/batched_remove_status_service_spec.rb6
-rw-r--r--spec/services/fan_out_on_write_service_spec.rb22
-rw-r--r--spec/services/mute_service_spec.rb4
-rw-r--r--spec/services/precompute_feed_service_spec.rb4
-rw-r--r--spec/workers/scheduler/feed_cleanup_scheduler_spec.rb16
12 files changed, 55 insertions, 55 deletions
diff --git a/spec/controllers/concerns/user_tracking_concern_spec.rb b/spec/controllers/concerns/user_tracking_concern_spec.rb
index 1e5620221..b2548d5c0 100644
--- a/spec/controllers/concerns/user_tracking_concern_spec.rb
+++ b/spec/controllers/concerns/user_tracking_concern_spec.rb
@@ -65,22 +65,22 @@ describe ApplicationController, type: :controller do
         get :show
 
         expect_updated_sign_in_at(user)
-        expect(Redis.current.get("account:#{user.account_id}:regeneration")).to eq 'true'
+        expect(redis.get("account:#{user.account_id}:regeneration")).to eq 'true'
         expect(RegenerationWorker).to have_received(:perform_async)
       end
 
       it 'sets the regeneration marker to expire' do
         allow(RegenerationWorker).to receive(:perform_async)
         get :show
-        expect(Redis.current.ttl("account:#{user.account_id}:regeneration")).to be >= 0
+        expect(redis.ttl("account:#{user.account_id}:regeneration")).to be >= 0
       end
 
       it 'regenerates feed when sign in is older than two weeks' do
         get :show
 
         expect_updated_sign_in_at(user)
-        expect(Redis.current.zcard(FeedManager.instance.key(:home, user.account_id))).to eq 3
-        expect(Redis.current.get("account:#{user.account_id}:regeneration")).to be_nil
+        expect(redis.zcard(FeedManager.instance.key(:home, user.account_id))).to eq 3
+        expect(redis.get("account:#{user.account_id}:regeneration")).to be_nil
       end
     end
 
diff --git a/spec/lib/activitypub/activity/move_spec.rb b/spec/lib/activitypub/activity/move_spec.rb
index 2d1d276c5..c468fdeff 100644
--- a/spec/lib/activitypub/activity/move_spec.rb
+++ b/spec/lib/activitypub/activity/move_spec.rb
@@ -84,9 +84,9 @@ RSpec.describe ActivityPub::Activity::Move do
 
     context 'when a Move has been recently processed' do
       around do |example|
-        Redis.current.set("move_in_progress:#{old_account.id}", true, nx: true, ex: 7.days.seconds)
+        redis.set("move_in_progress:#{old_account.id}", true, nx: true, ex: 7.days.seconds)
         example.run
-        Redis.current.del("move_in_progress:#{old_account.id}")
+        redis.del("move_in_progress:#{old_account.id}")
       end
 
       it 'does not set moved account on old account' do
diff --git a/spec/lib/delivery_failure_tracker_spec.rb b/spec/lib/delivery_failure_tracker_spec.rb
index 52a1a92f0..c8179ebd9 100644
--- a/spec/lib/delivery_failure_tracker_spec.rb
+++ b/spec/lib/delivery_failure_tracker_spec.rb
@@ -22,7 +22,7 @@ describe DeliveryFailureTracker do
 
   describe '#track_failure!' do
     it 'marks URL as unavailable after 7 days of being called' do
-      6.times { |i| Redis.current.sadd('exhausted_deliveries:example.com', i) }
+      6.times { |i| redis.sadd('exhausted_deliveries:example.com', i) }
       subject.track_failure!
 
       expect(subject.days).to eq 7
diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb
index 2217ad272..1b04916a1 100644
--- a/spec/lib/feed_manager_spec.rb
+++ b/spec/lib/feed_manager_spec.rb
@@ -202,11 +202,11 @@ RSpec.describe FeedManager do
       account = Fabricate(:account)
       status = Fabricate(:status)
       members = FeedManager::MAX_ITEMS.times.map { |count| [count, count] }
-      Redis.current.zadd("feed:home:#{account.id}", members)
+      redis.zadd("feed:home:#{account.id}", members)
 
       FeedManager.instance.push_to_home(account, status)
 
-      expect(Redis.current.zcard("feed:home:#{account.id}")).to eq FeedManager::MAX_ITEMS
+      expect(redis.zcard("feed:home:#{account.id}")).to eq FeedManager::MAX_ITEMS
     end
 
     context 'reblogs' do
@@ -431,7 +431,7 @@ RSpec.describe FeedManager do
 
       FeedManager.instance.merge_into_home(account, reblog.account)
 
-      expect(Redis.current.zscore("feed:home:0", reblog.id)).to eq nil
+      expect(redis.zscore("feed:home:0", reblog.id)).to eq nil
     end
   end
 
@@ -447,13 +447,13 @@ RSpec.describe FeedManager do
       FeedManager.instance.push_to_home(receiver, status)
 
       # The reblogging status should show up under normal conditions.
-      expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s)
+      expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s)
 
       FeedManager.instance.unpush_from_home(receiver, status)
 
       # Restore original status
-      expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to_not include(status.id.to_s)
-      expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to include(reblogged.id.to_s)
+      expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to_not include(status.id.to_s)
+      expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to include(reblogged.id.to_s)
     end
 
     it 'removes a reblogged status if it was only reblogged once' do
@@ -463,11 +463,11 @@ RSpec.describe FeedManager do
       FeedManager.instance.push_to_home(receiver, status)
 
       # The reblogging status should show up under normal conditions.
-      expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [status.id.to_s]
+      expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [status.id.to_s]
 
       FeedManager.instance.unpush_from_home(receiver, status)
 
-      expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to be_empty
+      expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to be_empty
     end
 
     it 'leaves a multiply-reblogged status if another reblog was in feed' do
@@ -479,13 +479,13 @@ RSpec.describe FeedManager do
       end
 
       # The reblogging status should show up under normal conditions.
-      expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.first.id.to_s]
+      expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.first.id.to_s]
 
       reblogs[0...-1].each do |reblog|
         FeedManager.instance.unpush_from_home(receiver, reblog)
       end
 
-      expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.last.id.to_s]
+      expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.last.id.to_s]
     end
 
     it 'sends push updates' do
@@ -493,11 +493,11 @@ RSpec.describe FeedManager do
 
       FeedManager.instance.push_to_home(receiver, status)
 
-      allow(Redis.current).to receive_messages(publish: nil)
+      allow(redis).to receive_messages(publish: nil)
       FeedManager.instance.unpush_from_home(receiver, status)
 
       deletion = Oj.dump(event: :delete, payload: status.id.to_s)
-      expect(Redis.current).to have_received(:publish).with("timeline:#{receiver.id}", deletion)
+      expect(redis).to have_received(:publish).with("timeline:#{receiver.id}", deletion)
     end
   end
 
@@ -515,14 +515,14 @@ RSpec.describe FeedManager do
 
     before do
       [status_1, status_3, status_5, status_6, status_7].each do |status|
-        Redis.current.zadd("feed:home:#{account.id}", status.id, status.id)
+        redis.zadd("feed:home:#{account.id}", status.id, status.id)
       end
     end
 
     it 'correctly cleans the home timeline' do
       FeedManager.instance.clear_from_home(account, target_account)
 
-      expect(Redis.current.zrange("feed:home:#{account.id}", 0, -1)).to eq [status_1.id.to_s, status_7.id.to_s]
+      expect(redis.zrange("feed:home:#{account.id}", 0, -1)).to eq [status_1.id.to_s, status_7.id.to_s]
     end
   end
 end
diff --git a/spec/models/home_feed_spec.rb b/spec/models/home_feed_spec.rb
index ee7a83960..80f6edbff 100644
--- a/spec/models/home_feed_spec.rb
+++ b/spec/models/home_feed_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe HomeFeed, type: :model do
 
     context 'when feed is generated' do
       before do
-        Redis.current.zadd(
+        redis.zadd(
           FeedManager.instance.key(:home, account.id),
           [[4, 4], [3, 3], [2, 2], [1, 1]]
         )
@@ -31,7 +31,7 @@ RSpec.describe HomeFeed, type: :model do
 
     context 'when feed is being generated' do
       before do
-        Redis.current.set("account:#{account.id}:regeneration", true)
+        redis.set("account:#{account.id}:regeneration", true)
       end
 
       it 'returns nothing' do
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 217a8f2f8..02827a388 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -13,7 +13,6 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
 
 ActiveRecord::Migration.maintain_test_schema!
 WebMock.disable_net_connect!(allow: Chewy.settings[:host])
-Redis.current = Redis::Namespace.new("mastodon_test#{ENV['TEST_ENV_NUMBER']}", redis: Redis.current)
 Sidekiq::Testing.inline!
 Sidekiq.logger = nil
 
@@ -44,6 +43,7 @@ RSpec.configure do |config|
   config.include Devise::Test::ControllerHelpers, type: :view
   config.include Paperclip::Shoulda::Matchers
   config.include ActiveSupport::Testing::TimeHelpers
+  config.include Redisable
 
   config.before :each, type: :feature do
     https = ENV['LOCAL_HTTPS'] == 'true'
@@ -60,7 +60,7 @@ RSpec.configure do |config|
 
   config.after :each do
     Rails.cache.clear
-    Redis.current.del(Redis.current.keys)
+    redis.del(redis.keys)
   end
 end
 
diff --git a/spec/services/after_block_service_spec.rb b/spec/services/after_block_service_spec.rb
index c09425d7c..337766d06 100644
--- a/spec/services/after_block_service_spec.rb
+++ b/spec/services/after_block_service_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe AfterBlockService, type: :service do
     let(:home_timeline_key) { FeedManager.instance.key(:home, account.id) }
 
     before do
-      Redis.current.del(home_timeline_key)
+      redis.del(home_timeline_key)
     end
 
     it "clears account's statuses" do
@@ -23,7 +23,7 @@ RSpec.describe AfterBlockService, type: :service do
       FeedManager.instance.push_to_home(account, other_account_reblog)
 
       expect { subject }.to change {
-        Redis.current.zrange(home_timeline_key, 0, -1)
+        redis.zrange(home_timeline_key, 0, -1)
       }.from([status.id.to_s, other_account_status.id.to_s, other_account_reblog.id.to_s]).to([other_account_status.id.to_s])
     end
   end
@@ -33,7 +33,7 @@ RSpec.describe AfterBlockService, type: :service do
     let(:list_timeline_key) { FeedManager.instance.key(:list, list.id) }
 
     before do
-      Redis.current.del(list_timeline_key)
+      redis.del(list_timeline_key)
     end
 
     it "clears account's statuses" do
@@ -42,7 +42,7 @@ RSpec.describe AfterBlockService, type: :service do
       FeedManager.instance.push_to_list(list, other_account_reblog)
 
       expect { subject }.to change {
-        Redis.current.zrange(list_timeline_key, 0, -1)
+        redis.zrange(list_timeline_key, 0, -1)
       }.from([status.id.to_s, other_account_status.id.to_s, other_account_reblog.id.to_s]).to([other_account_status.id.to_s])
     end
   end
diff --git a/spec/services/batched_remove_status_service_spec.rb b/spec/services/batched_remove_status_service_spec.rb
index 8f38908cd..920edeb13 100644
--- a/spec/services/batched_remove_status_service_spec.rb
+++ b/spec/services/batched_remove_status_service_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe BatchedRemoveStatusService, type: :service do
   let(:status2) { PostStatusService.new.call(alice, text: 'Another status') }
 
   before do
-    allow(Redis.current).to receive_messages(publish: nil)
+    allow(redis).to receive_messages(publish: nil)
 
     stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
 
@@ -40,11 +40,11 @@ RSpec.describe BatchedRemoveStatusService, type: :service do
   end
 
   it 'notifies streaming API of followers' do
-    expect(Redis.current).to have_received(:publish).with("timeline:#{jeff.id}", any_args).at_least(:once)
+    expect(redis).to have_received(:publish).with("timeline:#{jeff.id}", any_args).at_least(:once)
   end
 
   it 'notifies streaming API of public timeline' do
-    expect(Redis.current).to have_received(:publish).with('timeline:public', any_args).at_least(:once)
+    expect(redis).to have_received(:publish).with('timeline:public', any_args).at_least(:once)
   end
 
   it 'sends delete activity to followers' do
diff --git a/spec/services/fan_out_on_write_service_spec.rb b/spec/services/fan_out_on_write_service_spec.rb
index aaf179ce5..59e15d230 100644
--- a/spec/services/fan_out_on_write_service_spec.rb
+++ b/spec/services/fan_out_on_write_service_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe FanOutOnWriteService, type: :service do
     ProcessMentionsService.new.call(status)
     ProcessHashtagsService.new.call(status)
 
-    allow(Redis.current).to receive(:publish)
+    allow(redis).to receive(:publish)
 
     subject.call(status)
   end
@@ -40,13 +40,13 @@ RSpec.describe FanOutOnWriteService, type: :service do
     end
 
     it 'is broadcast to the hashtag stream' do
-      expect(Redis.current).to have_received(:publish).with('timeline:hashtag:hoge', anything)
-      expect(Redis.current).to have_received(:publish).with('timeline:hashtag:hoge:local', anything)
+      expect(redis).to have_received(:publish).with('timeline:hashtag:hoge', anything)
+      expect(redis).to have_received(:publish).with('timeline:hashtag:hoge:local', anything)
     end
 
     it 'is broadcast to the public stream' do
-      expect(Redis.current).to have_received(:publish).with('timeline:public', anything)
-      expect(Redis.current).to have_received(:publish).with('timeline:public:local', anything)
+      expect(redis).to have_received(:publish).with('timeline:public', anything)
+      expect(redis).to have_received(:publish).with('timeline:public:local', anything)
     end
   end
 
@@ -66,8 +66,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
     end
 
     it 'is not broadcast publicly' do
-      expect(Redis.current).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
-      expect(Redis.current).to_not have_received(:publish).with('timeline:public', anything)
+      expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
+      expect(redis).to_not have_received(:publish).with('timeline:public', anything)
     end
   end
 
@@ -84,8 +84,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
     end
 
     it 'is not broadcast publicly' do
-      expect(Redis.current).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
-      expect(Redis.current).to_not have_received(:publish).with('timeline:public', anything)
+      expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
+      expect(redis).to_not have_received(:publish).with('timeline:public', anything)
     end
   end
 
@@ -105,8 +105,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
     end
 
     it 'is not broadcast publicly' do
-      expect(Redis.current).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
-      expect(Redis.current).to_not have_received(:publish).with('timeline:public', anything)
+      expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
+      expect(redis).to_not have_received(:publish).with('timeline:public', anything)
     end
   end
 end
diff --git a/spec/services/mute_service_spec.rb b/spec/services/mute_service_spec.rb
index bdec1c67b..57d8c41de 100644
--- a/spec/services/mute_service_spec.rb
+++ b/spec/services/mute_service_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe MuteService, type: :service do
     let(:home_timeline_key) { FeedManager.instance.key(:home, account.id) }
 
     before do
-      Redis.current.del(home_timeline_key)
+      redis.del(home_timeline_key)
     end
 
     it "clears account's statuses" do
@@ -20,7 +20,7 @@ RSpec.describe MuteService, type: :service do
       FeedManager.instance.push_to_home(account, other_account_status)
 
       expect { subject }.to change {
-        Redis.current.zrange(home_timeline_key, 0, -1)
+        redis.zrange(home_timeline_key, 0, -1)
       }.from([status.id.to_s, other_account_status.id.to_s]).to([other_account_status.id.to_s])
     end
   end
diff --git a/spec/services/precompute_feed_service_spec.rb b/spec/services/precompute_feed_service_spec.rb
index 1f6b6ed88..86b93b5d2 100644
--- a/spec/services/precompute_feed_service_spec.rb
+++ b/spec/services/precompute_feed_service_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe PrecomputeFeedService, type: :service do
 
       subject.call(account)
 
-      expect(Redis.current.zscore(FeedManager.instance.key(:home, account.id), status.id)).to be_within(0.1).of(status.id.to_f)
+      expect(redis.zscore(FeedManager.instance.key(:home, account.id), status.id)).to be_within(0.1).of(status.id.to_f)
     end
 
     it 'does not raise an error even if it could not find any status' do
@@ -30,7 +30,7 @@ RSpec.describe PrecomputeFeedService, type: :service do
 
       subject.call(account)
 
-      expect(Redis.current.zscore(FeedManager.instance.key(:home, account.id), reblog.id)).to eq nil
+      expect(redis.zscore(FeedManager.instance.key(:home, account.id), reblog.id)).to eq nil
     end
   end
 end
diff --git a/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb b/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb
index 914eed829..82d794594 100644
--- a/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb
+++ b/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb
@@ -7,17 +7,17 @@ describe Scheduler::FeedCleanupScheduler do
   let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) }
 
   it 'clears feeds of inactives' do
-    Redis.current.zadd(feed_key_for(inactive_user), 1, 1)
-    Redis.current.zadd(feed_key_for(active_user), 1, 1)
-    Redis.current.zadd(feed_key_for(inactive_user, 'reblogs'), 2, 2)
-    Redis.current.sadd(feed_key_for(inactive_user, 'reblogs:2'), 3)
+    redis.zadd(feed_key_for(inactive_user), 1, 1)
+    redis.zadd(feed_key_for(active_user), 1, 1)
+    redis.zadd(feed_key_for(inactive_user, 'reblogs'), 2, 2)
+    redis.sadd(feed_key_for(inactive_user, 'reblogs:2'), 3)
 
     subject.perform
 
-    expect(Redis.current.zcard(feed_key_for(inactive_user))).to eq 0
-    expect(Redis.current.zcard(feed_key_for(active_user))).to eq 1
-    expect(Redis.current.exists?(feed_key_for(inactive_user, 'reblogs'))).to be false
-    expect(Redis.current.exists?(feed_key_for(inactive_user, 'reblogs:2'))).to be false
+    expect(redis.zcard(feed_key_for(inactive_user))).to eq 0
+    expect(redis.zcard(feed_key_for(active_user))).to eq 1
+    expect(redis.exists?(feed_key_for(inactive_user, 'reblogs'))).to be false
+    expect(redis.exists?(feed_key_for(inactive_user, 'reblogs:2'))).to be false
   end
 
   def feed_key_for(user, subtype = nil)