From b6602f68eb0dbe07ee2e9b8fb27ee048037c414e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 2 Mar 2023 04:04:14 -0500 Subject: [PATCH 1/5] Spec coverage for HomeHelper (#23907) --- app/helpers/home_helper.rb | 12 +--- spec/helpers/home_helper_spec.rb | 112 +++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 10 deletions(-) diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index f41104709e..ea21960865 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -41,9 +41,9 @@ module HomeHelper def obscured_counter(count) if count <= 0 - 0 + '0' elsif count == 1 - 1 + '1' else '1+' end @@ -57,14 +57,6 @@ module HomeHelper end end - def optional_link_to(condition, path, options = {}, &block) - if condition - link_to(path, options, &block) - else - content_tag(:div, &block) - end - end - def sign_up_message if closed_registrations? t('auth.registration_closed', instance: site_hostname) diff --git a/spec/helpers/home_helper_spec.rb b/spec/helpers/home_helper_spec.rb index 77db327c2d..3d2c5fe248 100644 --- a/spec/helpers/home_helper_spec.rb +++ b/spec/helpers/home_helper_spec.rb @@ -8,4 +8,116 @@ RSpec.describe HomeHelper, type: :helper do expect(helper.default_props).to eq locale: I18n.locale end end + + describe 'account_link_to' do + context 'with a missing account' do + let(:account) { nil } + + it 'returns a button' do + result = helper.account_link_to(account) + + expect(result).to match t('about.contact_missing') + end + end + + context 'with a valid account' do + let(:account) { Fabricate(:account) } + + it 'returns a link to the account' do + without_partial_double_verification do + allow(helper).to receive(:current_account).and_return(account) + allow(helper).to receive(:prefers_autoplay?).and_return(false) + result = helper.account_link_to(account) + + expect(result).to match "@#{account.acct}" + end + end + end + end + + describe 'obscured_counter' do + context 'with a value of less than zero' do + let(:count) { -10 } + + it 'returns the correct string' do + expect(helper.obscured_counter(count)).to eq '0' + end + end + + context 'with a value of zero' do + let(:count) { 0 } + + it 'returns the correct string' do + expect(helper.obscured_counter(count)).to eq '0' + end + end + + context 'with a value of one' do + let(:count) { 1 } + + it 'returns the correct string' do + expect(helper.obscured_counter(count)).to eq '1' + end + end + + context 'with a value of more than one' do + let(:count) { 10 } + + it 'returns the correct string' do + expect(helper.obscured_counter(count)).to eq '1+' + end + end + end + + describe 'custom_field_classes' do + context 'with a verified field' do + let(:field) { instance_double(Account::Field, verified?: true) } + + it 'returns verified string' do + result = helper.custom_field_classes(field) + expect(result).to eq 'verified' + end + end + + context 'with a non-verified field' do + let(:field) { instance_double(Account::Field, verified?: false) } + + it 'returns verified string' do + result = helper.custom_field_classes(field) + expect(result).to eq 'emojify' + end + end + end + + describe 'sign_up_messages' do + context 'with closed registrations' do + it 'returns correct sign up message' do + allow(helper).to receive(:closed_registrations?).and_return(true) + result = helper.sign_up_message + + expect(result).to eq t('auth.registration_closed', instance: 'cb6e6126.ngrok.io') + end + end + + context 'with open registrations' do + it 'returns correct sign up message' do + allow(helper).to receive(:closed_registrations?).and_return(false) + allow(helper).to receive(:open_registrations?).and_return(true) + result = helper.sign_up_message + + expect(result).to eq t('auth.register') + end + end + + context 'with approved registrations' do + it 'returns correct sign up message' do + allow(helper).to receive(:closed_registrations?).and_return(false) + allow(helper).to receive(:open_registrations?).and_return(false) + allow(helper).to receive(:approved_registrations?).and_return(true) + result = helper.sign_up_message + + expect(result).to eq t('auth.apply_for_account') + end + end + end end From d9271126ce9f1d270b7e1af9692b4622d987a1af Mon Sep 17 00:00:00 2001 From: Stanislav Dobrovolschii Date: Thu, 2 Mar 2023 10:05:05 +0100 Subject: [PATCH 2/5] Add rspecs for FollowRecommendationsScheduler (#23890) --- spec/fabricators/user_fabricator.rb | 3 +- .../follow_recommendations_scheduler_spec.rb | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 spec/workers/scheduler/follow_recommendations_scheduler_spec.rb diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 967347319c..9031d5cd04 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -5,5 +5,6 @@ Fabricator(:user) do email { sequence(:email) { |i| "#{i}#{Faker::Internet.email}" } } password '123456789' confirmed_at { Time.zone.now } - agreement true + current_sign_in_at { Time.zone.now } + agreement true end diff --git a/spec/workers/scheduler/follow_recommendations_scheduler_spec.rb b/spec/workers/scheduler/follow_recommendations_scheduler_spec.rb new file mode 100644 index 0000000000..18d5260e42 --- /dev/null +++ b/spec/workers/scheduler/follow_recommendations_scheduler_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Scheduler::FollowRecommendationsScheduler do + let!(:target_accounts) do + Fabricate.times(3, :account) do + statuses(count: 6) + end + end + let!(:follower_accounts) do + Fabricate.times(5, :account) do + statuses(count: 6) + end + end + + describe '#perform' do + subject(:scheduled_run) { described_class.new.perform } + + context 'when there are accounts to recommend' do + before do + # Follow the target accounts by follow accounts to make them recommendable + follower_accounts.each do |follower_account| + target_accounts.each do |target_account| + Fabricate(:follow, account: follower_account, target_account: target_account) + end + end + end + + it 'creates recommendations' do + expect { scheduled_run }.to change(FollowRecommendation, :count).from(0).to(target_accounts.size) + expect(redis.zrange('follow_recommendations:en', 0, -1)).to match_array(target_accounts.pluck(:id).map(&:to_s)) + end + end + + context 'when there are no accounts to recommend' do + it 'does not create follow recommendations' do + expect { scheduled_run }.to_not change(FollowRecommendation, :count) + expect(redis.zrange('follow_recommendations:en', 0, -1)).to be_empty + end + end + end +end From 6047c84468b145da8c38b2f5f0fa1723276acca6 Mon Sep 17 00:00:00 2001 From: Shlee Date: Thu, 2 Mar 2023 10:08:22 +0000 Subject: [PATCH 3/5] [Dependashlee] Bump color-blend from 3.0.1 to 4.0.0 (JS) (#23823) --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3d923bbacf..6493662444 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "blurhash": "^2.0.5", "classnames": "^2.3.2", "cocoon-js-vanilla": "^1.3.0", - "color-blend": "^3.0.1", + "color-blend": "^4.0.0", "compression-webpack-plugin": "^6.1.1", "cross-env": "^7.0.3", "css-loader": "^5.2.7", diff --git a/yarn.lock b/yarn.lock index 2fd3352cf1..d614f7ce73 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3373,10 +3373,10 @@ collection-visit@^1.0.0: map-visit "^1.0.0" object-visit "^1.0.0" -color-blend@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/color-blend/-/color-blend-3.0.1.tgz#3882ed1190ca18760ffe11570d8537960171172b" - integrity sha512-KueDvNiKHAvVeApic0SxHZLyy4x3NELfTLzMHRpRRLi+9e2kWhpeWvtuH3Sjb92mOJYEUhRjb8z7lr4OqDv17Q== +color-blend@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/color-blend/-/color-blend-4.0.0.tgz#e9950e9fa5d6e552ff8bb107c39f7e83a0c1a3bb" + integrity sha512-fYODTHhI/NG+B5GnzvuL3kiFrK/UnkUezWFTgEPBTY5V+kpyfAn95Vn9sJeeCX6omrCOdxnqCL3CvH+6sXtIbw== color-convert@^1.9.0, color-convert@^1.9.1: version "1.9.3" From 083e18e45b88f51e07837d21e2dd664efd0112cb Mon Sep 17 00:00:00 2001 From: Shlee Date: Thu, 2 Mar 2023 10:41:32 +0000 Subject: [PATCH 4/5] [Dependashlee] Bump fuzzysort from 1.9.0 to 2.0.4 (JS) (#23822) --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6493662444..fa9b650076 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "express": "^4.18.2", "file-loader": "^6.2.0", "font-awesome": "^4.7.0", - "fuzzysort": "^1.9.0", + "fuzzysort": "^2.0.4", "glob": "^8.1.0", "history": "^4.10.1", "http-link-header": "^1.1.0", diff --git a/yarn.lock b/yarn.lock index d614f7ce73..04a247c49b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5263,10 +5263,10 @@ functions-have-names@^1.2.2: resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834" integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ== -fuzzysort@^1.9.0: - version "1.9.0" - resolved "https://registry.yarnpkg.com/fuzzysort/-/fuzzysort-1.9.0.tgz#d36d27949eae22340bb6f7ba30ea6751b92a181c" - integrity sha512-MOxCT0qLTwLqmEwc7UtU045RKef7mc8Qz8eR4r2bLNEq9dy/c3ZKMEFp6IEst69otkQdFZ4FfgH2dmZD+ddX1g== +fuzzysort@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/fuzzysort/-/fuzzysort-2.0.4.tgz#a21d1ce8947eaf2797dc3b7c28c36db9d1165f84" + integrity sha512-Api1mJL+Ad7W7vnDZnWq5pGaXJjyencT+iKGia2PlHUcSsSzWwIQ3S1isiMpwpavjYtGd2FzhUIhnnhOULZgDw== gauge@^5.0.0: version "5.0.0" From 59f42c262b4faab3df7ec5fe2742f7707d58c285 Mon Sep 17 00:00:00 2001 From: Shlee Date: Thu, 2 Mar 2023 10:45:14 +0000 Subject: [PATCH 5/5] [Dependashlee] Bump @github/webauthn-json from 0.5.7 to 2.1.1 (js) (#23819) --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index fa9b650076..1ab297d041 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@babel/preset-react": "^7.18.6", "@babel/runtime": "^7.21.0", "@gamestdio/websocket": "^0.3.2", - "@github/webauthn-json": "^0.5.7", + "@github/webauthn-json": "^2.1.1", "@rails/ujs": "^6.1.7", "abortcontroller-polyfill": "^1.7.5", "array-includes": "^3.1.6", diff --git a/yarn.lock b/yarn.lock index 04a247c49b..a856cf91dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1245,10 +1245,10 @@ resolved "https://registry.yarnpkg.com/@gamestdio/websocket/-/websocket-0.3.2.tgz#321ba0976ee30fd14e51dbf8faa85ce7b325f76a" integrity sha512-J3n5SKim+ZoLbe44hRGI/VYAwSMCeIJuBy+FfP6EZaujEpNchPRFcIsVQLWAwpU1bP2Ji63rC+rEUOd1vjUB6Q== -"@github/webauthn-json@^0.5.7": - version "0.5.7" - resolved "https://registry.yarnpkg.com/@github/webauthn-json/-/webauthn-json-0.5.7.tgz#143bc67f6e0f75f8d188e565741507bb08c31214" - integrity sha512-SUYsttDxFSvWvvJssJpwzjmRCqYfdfqC9VCmAHQYfdKCVelyJteCHo9/lK1CB72mx/jrl6cFNY08aua4J2jIyg== +"@github/webauthn-json@^2.1.1": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@github/webauthn-json/-/webauthn-json-2.1.1.tgz#648e63fc28050917d2882cc2b27817a88cb420fc" + integrity sha512-XrftRn4z75SnaJOmZQbt7Mk+IIjqVHw+glDGOxuHwXkZBZh/MBoRS7MHjSZMDaLhT4RjN2VqiEU7EOYleuJWSQ== "@humanwhocodes/config-array@^0.11.8": version "0.11.8"