mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 09:21:11 +00:00
Avoid name conflict with AR::Persistence methods in FeaturedTag
This commit is contained in:
parent
f16f8b51b8
commit
f0eece5bdf
|
@ -179,7 +179,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||||
return if @tags.empty? || !status.distributable?
|
return if @tags.empty? || !status.distributable?
|
||||||
|
|
||||||
@account.featured_tags.where(tag_id: @tags.pluck(:id)).find_each do |featured_tag|
|
@account.featured_tags.where(tag_id: @tags.pluck(:id)).find_each do |featured_tag|
|
||||||
featured_tag.increment(status.created_at)
|
featured_tag.increment_count(status.created_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,11 @@ class FeaturedTag < ApplicationRecord
|
||||||
attributes['name'] || tag.display_name
|
attributes['name'] || tag.display_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment(timestamp)
|
def increment_count(timestamp)
|
||||||
update(statuses_count: statuses_count + 1, last_status_at: timestamp)
|
update(statuses_count: statuses_count + 1, last_status_at: timestamp)
|
||||||
end
|
end
|
||||||
|
|
||||||
def decrement(deleted_status)
|
def decrement_count(deleted_status)
|
||||||
if statuses_count <= 1
|
if statuses_count <= 1
|
||||||
update(statuses_count: 0, last_status_at: nil)
|
update(statuses_count: 0, last_status_at: nil)
|
||||||
elsif last_status_at.present? && last_status_at > deleted_status.created_at
|
elsif last_status_at.present? && last_status_at > deleted_status.created_at
|
||||||
|
|
|
@ -206,7 +206,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
||||||
|
|
||||||
unless added_tags.empty?
|
unless added_tags.empty?
|
||||||
@account.featured_tags.where(tag_id: added_tags.pluck(:id)).find_each do |featured_tag|
|
@account.featured_tags.where(tag_id: added_tags.pluck(:id)).find_each do |featured_tag|
|
||||||
featured_tag.increment(@status.created_at)
|
featured_tag.increment_count(@status.created_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
||||||
|
|
||||||
unless removed_tags.empty?
|
unless removed_tags.empty?
|
||||||
@account.featured_tags.where(tag_id: removed_tags.pluck(:id)).find_each do |featured_tag|
|
@account.featured_tags.where(tag_id: removed_tags.pluck(:id)).find_each do |featured_tag|
|
||||||
featured_tag.decrement(@status)
|
featured_tag.decrement_count(@status)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,7 @@ class ProcessHashtagsService < BaseService
|
||||||
|
|
||||||
unless added_tags.empty?
|
unless added_tags.empty?
|
||||||
@account.featured_tags.where(tag_id: added_tags.map(&:id)).find_each do |featured_tag|
|
@account.featured_tags.where(tag_id: added_tags.map(&:id)).find_each do |featured_tag|
|
||||||
featured_tag.increment(@status.created_at)
|
featured_tag.increment_count(@status.created_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class ProcessHashtagsService < BaseService
|
||||||
|
|
||||||
unless removed_tags.empty?
|
unless removed_tags.empty?
|
||||||
@account.featured_tags.where(tag_id: removed_tags.map(&:id)).find_each do |featured_tag|
|
@account.featured_tags.where(tag_id: removed_tags.map(&:id)).find_each do |featured_tag|
|
||||||
featured_tag.decrement(@status)
|
featured_tag.decrement_count(@status)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -118,7 +118,7 @@ class RemoveStatusService < BaseService
|
||||||
|
|
||||||
def remove_from_hashtags
|
def remove_from_hashtags
|
||||||
@account.featured_tags.where(tag_id: @status.tags.map(&:id)).find_each do |featured_tag|
|
@account.featured_tags.where(tag_id: @status.tags.map(&:id)).find_each do |featured_tag|
|
||||||
featured_tag.decrement(@status)
|
featured_tag.decrement_count(@status)
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless @status.public_visibility?
|
return unless @status.public_visibility?
|
||||||
|
|
|
@ -114,18 +114,18 @@ RSpec.describe FeaturedTag do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#increment' do
|
describe '#increment_count' do
|
||||||
it 'increases the count and updates the last_status_at timestamp' do
|
it 'increases the count and updates the last_status_at timestamp' do
|
||||||
featured_tag = Fabricate :featured_tag
|
featured_tag = Fabricate :featured_tag
|
||||||
timestamp = 5.days.ago
|
timestamp = 5.days.ago
|
||||||
|
|
||||||
expect { featured_tag.increment(timestamp) }
|
expect { featured_tag.increment_count(timestamp) }
|
||||||
.to change(featured_tag, :statuses_count).from(0).to(1)
|
.to change(featured_tag, :statuses_count).from(0).to(1)
|
||||||
.and change(featured_tag, :last_status_at).from(nil).to(be_within(0.1).of(timestamp))
|
.and change(featured_tag, :last_status_at).from(nil).to(be_within(0.1).of(timestamp))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#decrement' do
|
describe '#decrement_count' do
|
||||||
let(:tag) { Fabricate(:tag, name: 'test') }
|
let(:tag) { Fabricate(:tag, name: 'test') }
|
||||||
let(:account) { Fabricate(:account) }
|
let(:account) { Fabricate(:account) }
|
||||||
let(:featured_tag) { Fabricate(:featured_tag, name: 'test', account: account) }
|
let(:featured_tag) { Fabricate(:featured_tag, name: 'test', account: account) }
|
||||||
|
@ -138,7 +138,7 @@ RSpec.describe FeaturedTag do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'decreases the count and updates the last_status_at timestamp' do
|
it 'decreases the count and updates the last_status_at timestamp' do
|
||||||
expect { featured_tag.decrement(status) }
|
expect { featured_tag.decrement_count(status) }
|
||||||
.to change(featured_tag, :statuses_count).from(1).to(0)
|
.to change(featured_tag, :statuses_count).from(1).to(0)
|
||||||
.and change(featured_tag, :last_status_at).to(nil)
|
.and change(featured_tag, :last_status_at).to(nil)
|
||||||
end
|
end
|
||||||
|
@ -154,7 +154,7 @@ RSpec.describe FeaturedTag do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'decreases the count and updates the last_status_at timestamp' do
|
it 'decreases the count and updates the last_status_at timestamp' do
|
||||||
expect { featured_tag.decrement(previous_status) }
|
expect { featured_tag.decrement_count(previous_status) }
|
||||||
.to change(featured_tag, :statuses_count).from(2).to(1)
|
.to change(featured_tag, :statuses_count).from(2).to(1)
|
||||||
.and not_change(featured_tag, :last_status_at)
|
.and not_change(featured_tag, :last_status_at)
|
||||||
end
|
end
|
||||||
|
@ -170,7 +170,7 @@ RSpec.describe FeaturedTag do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'decreases the count and updates the last_status_at timestamp' do
|
it 'decreases the count and updates the last_status_at timestamp' do
|
||||||
expect { featured_tag.decrement(status) }
|
expect { featured_tag.decrement_count(status) }
|
||||||
.to change(featured_tag, :statuses_count).from(2).to(1)
|
.to change(featured_tag, :statuses_count).from(2).to(1)
|
||||||
.and change(featured_tag, :last_status_at)
|
.and change(featured_tag, :last_status_at)
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,9 +13,7 @@ RSpec.describe REST::FeaturedTagSerializer do
|
||||||
let(:featured_tag) { Fabricate :featured_tag }
|
let(:featured_tag) { Fabricate :featured_tag }
|
||||||
|
|
||||||
context 'when last_status_at is populated' do
|
context 'when last_status_at is populated' do
|
||||||
before do
|
before { featured_tag.update last_status_at: DateTime.new(2024, 11, 28, 16, 20, 0) }
|
||||||
featured_tag.increment(DateTime.new(2024, 11, 28, 16, 20, 0))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is serialized as yyyy-mm-dd' do
|
it 'is serialized as yyyy-mm-dd' do
|
||||||
expect(subject['last_status_at']).to eq('2024-11-28')
|
expect(subject['last_status_at']).to eq('2024-11-28')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user