Skip to content
Snippets Groups Projects
Commit e27f792c authored by Akihiko Odaki (@fn_aki@pawoo.net)'s avatar Akihiko Odaki (@fn_aki@pawoo.net) Committed by Eugen Rochko
Browse files

Some minor change and spec for Account (#3813)

* Introduce domains method to Account relation

Account had followers_domains method, which was excessively specific.
Let relation of Account have domains method instead.

* Move follow_mapping in Account to AccountInteractions

* Introduce shared examples for AccountAvatar inclusion

* Cover Account more
parent 98fab24b
No related branches found
No related tags found
No related merge requests found
......@@ -124,10 +124,6 @@ class Account < ApplicationRecord
subscription_expires_at.present?
end
def followers_domains
followers.reorder(nil).pluck('distinct accounts.domain')
end
def keypair
OpenSSL::PKey::RSA.new(private_key || public_key)
end
......@@ -163,6 +159,10 @@ class Account < ApplicationRecord
end
class << self
def domains
reorder(nil).pluck('distinct accounts.domain')
end
def triadic_closures(account, limit: 5, offset: 0)
sql = <<-SQL.squish
WITH first_degree AS (
......@@ -236,10 +236,6 @@ class Account < ApplicationRecord
[textsearch, query]
end
def follow_mapping(query, field)
query.pluck(field).each_with_object({}) { |id, mapping| mapping[id] = true }
end
end
before_create :generate_keys
......
......@@ -29,6 +29,12 @@ module AccountInteractions
blocked_domains = AccountDomainBlock.where(account_id: account_id, domain: accounts_map.values).pluck(:domain)
accounts_map.map { |id, domain| [id, blocked_domains.include?(domain)] }.to_h
end
private
def follow_mapping(query, field)
query.pluck(field).each_with_object({}) { |id, mapping| mapping[id] = true }
end
end
included do
......
......@@ -33,7 +33,7 @@ class Pubsubhubbub::DistributionWorker
return if stream_entries.empty?
@payload = AtomSerializer.render(AtomSerializer.new.feed(@account, stream_entries))
@domains = @account.followers_domains
@domains = @account.followers.domains
Pubsubhubbub::DeliveryWorker.push_bulk(@subscriptions.reject { |s| !allowed_to_receive?(s.callback_url) }) do |subscription|
[subscription.id, @payload]
......
This diff is collapsed.
# frozen_string_literal: true
shared_examples 'AccountAvatar' do |fabricator|
describe 'static avatars' do
describe 'when GIF' do
it 'creates a png static style' do
account = Fabricate(fabricator, avatar: attachment_fixture('avatar.gif'))
expect(account.avatar_static_url).to_not eq account.avatar_original_url
end
end
describe 'when non-GIF' do
it 'does not create extra static style' do
account = Fabricate(fabricator, avatar: attachment_fixture('attachment.jpg'))
expect(account.avatar_static_url).to eq account.avatar_original_url
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment