Refactor: InstanceInfo
と絵文字リアクション利用可能判定テスト (#534)
* Refactor: `InstanceInfo`と絵文字リアクション利用可能判定テスト * Fix: 新規登録のテストが特定時刻で落ちる問題
This commit is contained in:
parent
e317edecb8
commit
ba776d3677
4 changed files with 68 additions and 37 deletions
|
@ -30,24 +30,31 @@ class InstanceInfo < ApplicationRecord
|
||||||
sharkey
|
sharkey
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
def self.emoji_reaction_available?(domain)
|
class << self
|
||||||
|
def emoji_reaction_available?(domain)
|
||||||
return Setting.enable_emoji_reaction if domain.nil?
|
return Setting.enable_emoji_reaction if domain.nil?
|
||||||
|
|
||||||
Rails.cache.fetch("emoji_reaction_available_domain:#{domain}") { fetch_emoji_reaction_available(domain) }
|
Rails.cache.fetch("emoji_reaction_available_domain:#{domain}") { load_emoji_reaction_available(domain) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.fetch_emoji_reaction_available(domain)
|
private
|
||||||
|
|
||||||
|
def load_emoji_reaction_available(domain)
|
||||||
info = InstanceInfo.find_by(domain: domain)
|
info = InstanceInfo.find_by(domain: domain)
|
||||||
return false if info.nil?
|
return false if info.nil?
|
||||||
|
|
||||||
return true if EMOJI_REACTION_AVAILABLE_SOFTWARES.include?(info['software'])
|
return true if EMOJI_REACTION_AVAILABLE_SOFTWARES.include?(info['software'])
|
||||||
return false if info.data['metadata'].nil? || !info.data['metadata'].is_a?(Hash)
|
|
||||||
|
return false unless info.data.is_a?(Hash)
|
||||||
|
return false unless info.data['metadata'].is_a?(Hash)
|
||||||
|
|
||||||
features = info.data.dig('metadata', 'features')
|
features = info.data.dig('metadata', 'features')
|
||||||
return false if features.nil? || !features.is_a?(Array)
|
return false unless features.is_a?(Array)
|
||||||
|
|
||||||
features.include?('emoji_reaction')
|
features.include?('emoji_reaction')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def reset_cache
|
def reset_cache
|
||||||
Rails.cache.delete("emoji_reaction_available_domain:#{domain}")
|
Rails.cache.delete("emoji_reaction_available_domain:#{domain}")
|
||||||
|
|
|
@ -407,7 +407,10 @@ RSpec.describe Auth::RegistrationsController do
|
||||||
Setting.registrations_secondary_end_hour = secondary_end_hour
|
Setting.registrations_secondary_end_hour = secondary_end_hour
|
||||||
request.headers['Accept-Language'] = accept_language
|
request.headers['Accept-Language'] = accept_language
|
||||||
|
|
||||||
travel_to Time.now.utc.beginning_of_day + 10.hours
|
current = Time.now.utc
|
||||||
|
today = current.beginning_of_day
|
||||||
|
today += 1.day if current.hour > 10
|
||||||
|
travel_to today + 10.hours
|
||||||
end
|
end
|
||||||
|
|
||||||
if result
|
if result
|
||||||
|
|
|
@ -1,3 +1,44 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe InstanceInfo do
|
||||||
|
describe '.emoji_reaction_availables_map' do
|
||||||
|
subject { described_class.emoji_reaction_available?('example.com') }
|
||||||
|
|
||||||
|
it 'availables if features contains emoji_reaction' do
|
||||||
|
Fabricate(:instance_info, domain: 'example.com', software: 'mastodon', data: { metadata: { features: ['emoji_reaction'] } })
|
||||||
|
expect(subject).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'unavailables if features does not contain emoji_reaction' do
|
||||||
|
Fabricate(:instance_info, domain: 'example.com', software: 'mastodon', data: { metadata: { features: ['ohagi'] } })
|
||||||
|
expect(subject).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'unavailables if features is not valid' do
|
||||||
|
Fabricate(:instance_info, domain: 'example.com', software: 'mastodon', data: { metadata: { features: 'good_for_ohagi' } })
|
||||||
|
expect(subject).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'unavailables if features is nil' do
|
||||||
|
Fabricate(:instance_info, domain: 'example.com', software: 'mastodon', data: { metadata: { features: nil } })
|
||||||
|
expect(subject).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'unavailables if mastodon server' do
|
||||||
|
Fabricate(:instance_info, domain: 'example.com', software: 'mastodon')
|
||||||
|
expect(subject).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'availables if misskey server' do
|
||||||
|
Fabricate(:instance_info, domain: 'example.com', software: 'misskey')
|
||||||
|
expect(subject).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'unavailables if old mastodon server' do
|
||||||
|
Fabricate(:instance_info, domain: 'example.com', software: 'mastodon', data: { metadata: [] })
|
||||||
|
expect(subject).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -463,34 +463,18 @@ RSpec.describe Status do
|
||||||
describe '.emoji_reaction_availables_map' do
|
describe '.emoji_reaction_availables_map' do
|
||||||
subject { described_class.emoji_reaction_availables_map(domains) }
|
subject { described_class.emoji_reaction_availables_map(domains) }
|
||||||
|
|
||||||
let(:domains) { %w(features_available.com features_unavailable.com features_invalid.com features_nil.com no_info.com mastodon.com misskey.com old_mastodon.com) }
|
let(:domains) { %w(features_available.com mastodon.com misskey.com) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Fabricate(:instance_info, domain: 'features_available.com', software: 'mastodon', data: { metadata: { features: ['emoji_reaction'] } })
|
Fabricate(:instance_info, domain: 'features_available.com', software: 'mastodon', data: { metadata: { features: ['emoji_reaction'] } })
|
||||||
Fabricate(:instance_info, domain: 'features_unavailable.com', software: 'mastodon', data: { metadata: { features: ['ohagi'] } })
|
|
||||||
Fabricate(:instance_info, domain: 'features_invalid.com', software: 'mastodon', data: { metadata: { features: 'good_for_ohagi' } })
|
|
||||||
Fabricate(:instance_info, domain: 'features_nil.com', software: 'mastodon', data: { metadata: { features: nil } })
|
|
||||||
Fabricate(:instance_info, domain: 'mastodon.com', software: 'mastodon')
|
Fabricate(:instance_info, domain: 'mastodon.com', software: 'mastodon')
|
||||||
Fabricate(:instance_info, domain: 'misskey.com', software: 'misskey')
|
Fabricate(:instance_info, domain: 'misskey.com', software: 'misskey')
|
||||||
Fabricate(:instance_info, domain: 'old_mastodon.com', software: 'mastodon', data: { metadata: [] })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'availables if features contains emoji_reaction' do
|
it 'availables if features contains emoji_reaction' do
|
||||||
expect(subject['features_available.com']).to be true
|
expect(subject['features_available.com']).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'unavailables if features does not contain emoji_reaction' do
|
|
||||||
expect(subject['features_unavailable.com']).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'unavailables if features is not valid' do
|
|
||||||
expect(subject['features_invalid.com']).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'unavailables if features is nil' do
|
|
||||||
expect(subject['features_nil.com']).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'unavailables if mastodon server' do
|
it 'unavailables if mastodon server' do
|
||||||
expect(subject['mastodon.com']).to be false
|
expect(subject['mastodon.com']).to be false
|
||||||
end
|
end
|
||||||
|
@ -498,10 +482,6 @@ RSpec.describe Status do
|
||||||
it 'availables if misskey server' do
|
it 'availables if misskey server' do
|
||||||
expect(subject['misskey.com']).to be true
|
expect(subject['misskey.com']).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'unavailables if old mastodon server' do
|
|
||||||
expect(subject['old_mastodon.com']).to be false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.tagged_with' do
|
describe '.tagged_with' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue