From 80823f6d6a41e5aff646ff7f2adf3ed7f2736be1 Mon Sep 17 00:00:00 2001 From: KMY Date: Fri, 19 Apr 2024 08:47:34 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20=E3=82=A4=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=B9=E3=81=A7=E5=88=A9=E7=94=A8=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E3=81=AA=E6=A9=9F=E8=83=BD=E3=82=92=E6=A4=9C=E5=87=BA?= =?UTF-8?q?=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/instance_info.rb | 15 +++++++++------ spec/models/instance_info_spec.rb | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/models/instance_info.rb b/app/models/instance_info.rb index 20769b11137eac..cfcf6204b494d5 100644 --- a/app/models/instance_info.rb +++ b/app/models/instance_info.rb @@ -77,15 +77,18 @@ def local_features def feature_available?(info, softwares, feature_name) return false if info.nil? - return true if softwares.include?(info['software']) - return false unless info.data.is_a?(Hash) - return false unless info.data['metadata'].is_a?(Hash) + softwares.include?(software_name(info)) || metadata_features(info)&.include?(feature_name) || false + end + + def metadata_features(info) + return nil unless info.data.is_a?(Hash) && info.data['metadata'].is_a?(Hash) && info.data['metadata']['features'].is_a?(Array) - features = info.data.dig('metadata', 'features') - return false unless features.is_a?(Array) + info.data['metadata']['features'] + end - features.include?(feature_name) + def software_name(info) + info.software end end diff --git a/spec/models/instance_info_spec.rb b/spec/models/instance_info_spec.rb index 6d3c5b4ff16585..32208ee8f8af9a 100644 --- a/spec/models/instance_info_spec.rb +++ b/spec/models/instance_info_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe InstanceInfo do - describe '.available_features' do + describe '.available_features#emoji_reaction' do subject { described_class.available_features('example.com')[:emoji_reaction] } it 'availables if local account' do @@ -45,4 +45,18 @@ expect(subject).to be false end end + + describe '.available_features#circle' do + subject { described_class.available_features('example.com')[:circle] } + + it 'does not available if misskey server' do + Fabricate(:instance_info, domain: 'example.com', software: 'misskey') + expect(subject).to be false + end + + it 'availables if misskey server with features' do + Fabricate(:instance_info, domain: 'example.com', software: 'misskey', data: { metadata: { features: ['circle'] } }) + expect(subject).to be true + end + end end