From 890e3347034db20410f8b11a7bf2518cfdf527b9 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 21 Sep 2023 12:33:30 +0200 Subject: [PATCH] Add migration tests for negative settings (#27012) --- db/migrate/20230215074423_move_user_settings.rb | 2 +- lib/tasks/tests.rake | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/db/migrate/20230215074423_move_user_settings.rb b/db/migrate/20230215074423_move_user_settings.rb index 2fac886bd..27caac101 100644 --- a/db/migrate/20230215074423_move_user_settings.rb +++ b/db/migrate/20230215074423_move_user_settings.rb @@ -69,7 +69,7 @@ class MoveUserSettings < ActiveRecord::Migration[6.1] MAPPING.each do |legacy_key, new_key| value = previous_settings[legacy_key]&.value - next if value.blank? + next if value.nil? if value.is_a?(Hash) value.each do |nested_key, nested_value| diff --git a/lib/tasks/tests.rake b/lib/tasks/tests.rake index dbf140599..7f8e72dd8 100644 --- a/lib/tasks/tests.rake +++ b/lib/tasks/tests.rake @@ -59,6 +59,11 @@ namespace :tests do exit(1) end + unless User.find(1).settings['web.trends'] == false + puts 'User settings not kept as expected' + exit(1) + end + unless Account.find_remote('bob', 'ActivityPub.com').domain == 'activitypub.com' puts 'Account domains not properly normalized' exit(1) @@ -131,7 +136,8 @@ namespace :tests do INSERT INTO "settings" (id, thing_type, thing_id, var, value, created_at, updated_at) VALUES - (3, 'User', 1, 'notification_emails', E'--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nfollow: false\nreblog: true\nfavourite: true\nmention: false\nfollow_request: true\ndigest: true\nreport: true\npending_account: false\ntrending_tag: true\nappeal: true\n', now(), now()); + (3, 'User', 1, 'notification_emails', E'--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nfollow: false\nreblog: true\nfavourite: true\nmention: false\nfollow_request: true\ndigest: true\nreport: true\npending_account: false\ntrending_tag: true\nappeal: true\n', now(), now()), + (4, 'User', 1, 'trends', E'--- false\n', now(), now()); INSERT INTO "accounts" (id, username, domain, private_key, public_key, created_at, updated_at) @@ -146,7 +152,7 @@ namespace :tests do INSERT INTO "settings" (id, thing_type, thing_id, var, value, created_at, updated_at) VALUES - (4, 'User', 4, 'default_language', E'--- kmr\n', now(), now()); + (5, 'User', 4, 'default_language', E'--- kmr\n', now(), now()); SQL end