Merge branch 'main' into glitch-soc/merge-upstream

Conflicts:
- `app/views/admin/tags/index.html.haml`:
  Removed upstream while it had changes in glitch-soc to accomodate for the
  theming system.

Additional changes to accomodate for the theming system:
- `app/views/admin/trends/links/preview_card_providers/index.html.haml`
- `app/views/admin/trends/links/index.html.haml`
- `app/views/admin/trends/tags/index.html.haml`
- `app/views/admin/tags/show.html.haml`
This commit is contained in:
Claire
2021-11-25 23:49:17 +01:00
100 changed files with 2119 additions and 725 deletions

View File

@@ -9,18 +9,6 @@ RSpec.describe Admin::TagsController, type: :controller do
sign_in Fabricate(:user, admin: true)
end
describe 'GET #index' do
let!(:tag) { Fabricate(:tag) }
before do
get :index
end
it 'returns status 200' do
expect(response).to have_http_status(200)
end
end
describe 'GET #show' do
let!(:tag) { Fabricate(:tag) }

View File

@@ -0,0 +1,22 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Trends::TagsController, type: :controller do
render_views
describe 'GET #index' do
before do
trending_tags = double()
allow(trending_tags).to receive(:get).and_return(Fabricate.times(10, :tag))
allow(Trends).to receive(:tags).and_return(trending_tags)
get :index
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
end

View File

@@ -1,18 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::TrendsController, type: :controller do
render_views
describe 'GET #index' do
before do
allow(TrendingTags).to receive(:get).and_return(Fabricate.times(10, :tag))
get :index
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
end

View File

@@ -2,20 +2,15 @@
require 'rails_helper'
describe SettingsHelper do
describe LanguagesHelper do
describe 'the HUMAN_LOCALES constant' do
it 'includes all I18n locales' do
options = I18n.available_locales
expect(described_class::HUMAN_LOCALES.keys).to include(*options)
expect(described_class::HUMAN_LOCALES.keys).to include(*I18n.available_locales)
end
end
describe 'human_locale' do
it 'finds the human readable local description from a key' do
# Ensure the value is as we expect
expect(described_class::HUMAN_LOCALES[:en]).to eq('English')
expect(helper.human_locale(:en)).to eq('English')
end
end

View File

@@ -5,4 +5,14 @@ class AdminMailerPreview < ActionMailer::Preview
def new_pending_account
AdminMailer.new_pending_account(Account.first, User.pending.first)
end
# Preview this email at http://localhost:3000/rails/mailers/admin_mailer/new_trending_tags
def new_trending_tags
AdminMailer.new_trending_tags(Account.first, Tag.limit(3))
end
# Preview this email at http://localhost:3000/rails/mailers/admin_mailer/new_trending_links
def new_trending_links
AdminMailer.new_trending_links(Account.first, PreviewCard.limit(3))
end
end

View File

@@ -1,68 +0,0 @@
require 'rails_helper'
RSpec.describe TrendingTags do
describe '.record_use!' do
pending
end
describe '.update!' do
let!(:at_time) { Time.now.utc }
let!(:tag1) { Fabricate(:tag, name: 'Catstodon', trendable: true) }
let!(:tag2) { Fabricate(:tag, name: 'DogsOfMastodon', trendable: true) }
let!(:tag3) { Fabricate(:tag, name: 'OCs', trendable: true) }
before do
allow(Redis.current).to receive(:pfcount) do |key|
case key
when "activity:tags:#{tag1.id}:#{(at_time - 1.day).beginning_of_day.to_i}:accounts"
2
when "activity:tags:#{tag1.id}:#{at_time.beginning_of_day.to_i}:accounts"
16
when "activity:tags:#{tag2.id}:#{(at_time - 1.day).beginning_of_day.to_i}:accounts"
0
when "activity:tags:#{tag2.id}:#{at_time.beginning_of_day.to_i}:accounts"
4
when "activity:tags:#{tag3.id}:#{(at_time - 1.day).beginning_of_day.to_i}:accounts"
13
end
end
Redis.current.zadd('trending_tags', 0.9, tag3.id)
Redis.current.sadd("trending_tags:used:#{at_time.beginning_of_day.to_i}", [tag1.id, tag2.id])
tag3.update(max_score: 0.9, max_score_at: (at_time - 1.day).beginning_of_day + 12.hours)
described_class.update!(at_time)
end
it 'calculates and re-calculates scores' do
expect(described_class.get(10, filtered: false)).to eq [tag1, tag3]
end
it 'omits hashtags below threshold' do
expect(described_class.get(10, filtered: false)).to_not include(tag2)
end
it 'decays scores' do
expect(Redis.current.zscore('trending_tags', tag3.id)).to be < 0.9
end
end
describe '.trending?' do
let(:tag) { Fabricate(:tag) }
before do
10.times { |i| Redis.current.zadd('trending_tags', i + 1, Fabricate(:tag).id) }
end
it 'returns true if the hashtag is within limit' do
Redis.current.zadd('trending_tags', 11, tag.id)
expect(described_class.trending?(tag)).to be true
end
it 'returns false if the hashtag is outside the limit' do
Redis.current.zadd('trending_tags', 0, tag.id)
expect(described_class.trending?(tag)).to be false
end
end
end

View File

@@ -0,0 +1,67 @@
require 'rails_helper'
RSpec.describe Trends::Tags do
subject { described_class.new(threshold: 5, review_threshold: 10) }
let!(:at_time) { DateTime.new(2021, 11, 14, 10, 15, 0) }
describe '#add' do
let(:tag) { Fabricate(:tag) }
before do
subject.add(tag, 1, at_time)
end
it 'records history' do
expect(tag.history.get(at_time).accounts).to eq 1
end
it 'records use' do
expect(subject.send(:recently_used_ids, at_time)).to eq [tag.id]
end
end
describe '#get' do
pending
end
describe '#refresh' do
let!(:today) { at_time }
let!(:yesterday) { today - 1.day }
let!(:tag1) { Fabricate(:tag, name: 'Catstodon', trendable: true) }
let!(:tag2) { Fabricate(:tag, name: 'DogsOfMastodon', trendable: true) }
let!(:tag3) { Fabricate(:tag, name: 'OCs', trendable: true) }
before do
2.times { |i| subject.add(tag1, i, yesterday) }
13.times { |i| subject.add(tag3, i, yesterday) }
16.times { |i| subject.add(tag1, i, today) }
4.times { |i| subject.add(tag2, i, today) }
end
context do
before do
subject.refresh(yesterday + 12.hours)
subject.refresh(at_time)
end
it 'calculates and re-calculates scores' do
expect(subject.get(false, 10)).to eq [tag1, tag3]
end
it 'omits hashtags below threshold' do
expect(subject.get(false, 10)).to_not include(tag2)
end
end
it 'decays scores' do
subject.refresh(yesterday + 12.hours)
original_score = subject.score(tag3.id)
expect(original_score).to eq 144.0
subject.refresh(yesterday + 12.hours + subject.options[:max_score_halflife])
decayed_score = subject.score(tag3.id)
expect(decayed_score).to be <= original_score / 2
end
end
end

View File

@@ -64,8 +64,9 @@ RSpec.describe NotifyService, type: :service do
is_expected.to_not change(Notification, :count)
end
context 'if the message chain initiated by recipient, but is not direct message' do
context 'if the message chain is initiated by recipient, but is not direct message' do
let(:reply_to) { Fabricate(:status, account: recipient) }
let!(:mention) { Fabricate(:mention, account: sender, status: reply_to) }
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) }
it 'does not notify' do
@@ -73,8 +74,20 @@ RSpec.describe NotifyService, type: :service do
end
end
context 'if the message chain initiated by recipient and is direct message' do
context 'if the message chain is initiated by recipient, but without a mention to the sender, even if the sender sends multiple messages in a row' do
let(:reply_to) { Fabricate(:status, account: recipient) }
let!(:mention) { Fabricate(:mention, account: sender, status: reply_to) }
let(:dummy_reply) { Fabricate(:status, account: sender, visibility: :direct, thread: reply_to) }
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: dummy_reply)) }
it 'does not notify' do
is_expected.to_not change(Notification, :count)
end
end
context 'if the message chain is initiated by the recipient with a mention to the sender' do
let(:reply_to) { Fabricate(:status, account: recipient, visibility: :direct) }
let!(:mention) { Fabricate(:mention, account: sender, status: reply_to) }
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) }
it 'does notify' do