about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mastodon/emoji_cli.rb2
-rw-r--r--lib/mastodon/maintenance_cli.rb2
-rw-r--r--lib/mastodon/statuses_cli.rb2
-rw-r--r--lib/tasks/tests.rake92
4 files changed, 84 insertions, 14 deletions
diff --git a/lib/mastodon/emoji_cli.rb b/lib/mastodon/emoji_cli.rb
index 5bee70ea5..a3e947909 100644
--- a/lib/mastodon/emoji_cli.rb
+++ b/lib/mastodon/emoji_cli.rb
@@ -41,7 +41,7 @@ module Mastodon
 
       Gem::Package::TarReader.new(Zlib::GzipReader.open(path)) do |tar|
         tar.each do |entry|
-          next unless entry.file? && entry.full_name.end_with?('.png')
+          next unless entry.file? && entry.full_name.end_with?('.png', '.gif')
 
           filename = File.basename(entry.full_name, '.*')
 
diff --git a/lib/mastodon/maintenance_cli.rb b/lib/mastodon/maintenance_cli.rb
index 00861df77..1e047d96c 100644
--- a/lib/mastodon/maintenance_cli.rb
+++ b/lib/mastodon/maintenance_cli.rb
@@ -510,7 +510,7 @@ module Mastodon
       accounts = accounts.sort_by(&:id).reverse
 
       @prompt.warn "Multiple local accounts were found for username '#{accounts.first.username}'."
-      @prompt.warn 'All those accounts are distinct accounts but only the most recently-created one is fully-functionnal.'
+      @prompt.warn 'All those accounts are distinct accounts but only the most recently-created one is fully-functional.'
 
       accounts.each_with_index do |account, idx|
         @prompt.say '%2d. %s: created at: %s; updated at: %s; last logged in at: %s; statuses: %5d; last status at: %s' % [idx, account.username, account.created_at, account.updated_at, account.user&.last_sign_in_at&.to_s || 'N/A', account.account_stat&.statuses_count || 0, account.account_stat&.last_status_at || 'N/A']
diff --git a/lib/mastodon/statuses_cli.rb b/lib/mastodon/statuses_cli.rb
index 91b08813b..d4c2e6cf2 100644
--- a/lib/mastodon/statuses_cli.rb
+++ b/lib/mastodon/statuses_cli.rb
@@ -156,7 +156,7 @@ module Mastodon
 
         ActiveRecord::Base.connection.add_index(:statuses, :conversation_id, name: :index_statuses_conversation_id, algorithm: :concurrently, if_not_exists: true)
 
-        say('Extract the deletion target from coversations... This might take a while...')
+        say('Extract the deletion target from conversations... This might take a while...')
 
         ActiveRecord::Base.connection.create_table('conversations_to_be_deleted', force: true)
 
diff --git a/lib/tasks/tests.rake b/lib/tasks/tests.rake
index 0f38b50e3..8082f32fb 100644
--- a/lib/tasks/tests.rake
+++ b/lib/tasks/tests.rake
@@ -2,6 +2,50 @@
 
 namespace :tests do
   namespace :migrations do
+    desc 'Check that database state is consistent with a successful migration from populated data'
+    task check_database: :environment do
+      unless Account.find_by(username: 'admin', domain: nil)&.hide_collections? == false
+        puts 'Unexpected value for Account#hide_collections? for user @admin'
+        exit(1)
+      end
+
+      unless Account.find_by(username: 'user', domain: nil)&.hide_collections? == true
+        puts 'Unexpected value for Account#hide_collections? for user @user'
+        exit(1)
+      end
+
+      unless Account.find_by(username: 'evil', domain: 'activitypub.com')&.suspended?
+        puts 'Unexpected value for Account#suspended? for user @evil@activitypub.com'
+        exit(1)
+      end
+
+      unless Status.find(6).account_id == Status.find(7).account_id
+        puts 'Users @remote@remote.com and @Remote@remote.com not properly merged'
+        exit(1)
+      end
+
+      if Account.where(domain: Rails.configuration.x.local_domain).exists?
+        puts 'Faux remote accounts not properly claned up'
+        exit(1)
+      end
+
+      unless AccountConversation.first&.last_status_id == 11
+        puts 'AccountConversation records not created as expected'
+        exit(1)
+      end
+    end
+
+    desc 'Populate the database with test data for 2.4.0'
+    task populate_v2_4: :environment do
+      ActiveRecord::Base.connection.execute(<<~SQL)
+        INSERT INTO "settings"
+          (id, thing_type, thing_id, var, value, created_at, updated_at)
+        VALUES
+          (1, 'User', 1, 'hide_network', E'--- false\n', now(), now()),
+          (2, 'User', 2, 'hide_network', E'--- true\n', now(), now());
+      SQL
+    end
+
     desc 'Populate the database with test data for 2.0.0'
     task populate_v2: :environment do
       admin_key   = OpenSSL::PKey::RSA.new(2048)
@@ -34,7 +78,7 @@ namespace :tests do
            'https://remote.com/@remote', 'https://remote.com/salmon/1'),
           (4, 'Remote', 'remote.com', NULL, #{remote_public_key}, now(), now(),
            'https://remote.com/@Remote', 'https://remote.com/salmon/1'),
-          (5, 'REMOTE', 'Remote.com', NULL, #{remote_public_key2}, now(), now(),
+          (5, 'REMOTE', 'Remote.com', NULL, #{remote_public_key2}, now() - interval '1 year', now() - interval '1 year',
            'https://remote.com/stale/@REMOTE', 'https://remote.com/stale/salmon/1');
 
         INSERT INTO "accounts"
@@ -49,6 +93,13 @@ namespace :tests do
           (7, 'user', #{local_domain}, #{user_private_key}, #{user_public_key}, now(), now()),
           (8, 'pt_user', NULL, #{user_private_key}, #{user_public_key}, now(), now());
 
+        INSERT INTO "accounts"
+          (id, username, domain, private_key, public_key, created_at, updated_at, protocol, inbox_url, outbox_url, followers_url, suspended)
+        VALUES
+          (9, 'evil', 'activitypub.com', NULL, #{remote_public_key_ap}, now(), now(),
+           1, 'https://activitypub.com/users/evil/inbox', 'https://activitypub.com/users/evil/outbox',
+           'https://activitypub.com/users/evil/followers', true);
+
         -- users
 
         INSERT INTO "users"
@@ -62,6 +113,9 @@ namespace :tests do
         VALUES
           (3, 7, 'ptuser@localhost', now(), now(), false, 'pt');
 
+        -- conversations
+        INSERT INTO "conversations" (id, created_at, updated_at) VALUES (1, now(), now());
+
         -- statuses
 
         INSERT INTO "statuses"
@@ -97,14 +151,22 @@ namespace :tests do
         VALUES
           (9, 1, 2, now(), now());
 
+        INSERT INTO "statuses"
+          (id, account_id, text, in_reply_to_id, conversation_id, visibility, created_at, updated_at)
+        VALUES
+          (10, 2, '@admin hey!', NULL, 1, 3, now(), now()),
+          (11, 1, '@user hey!', 10, 1, 3, now(), now());
+
         -- mentions (from previous statuses)
 
         INSERT INTO "mentions"
-          (status_id, account_id, created_at, updated_at)
+          (id, status_id, account_id, created_at, updated_at)
         VALUES
-          (2, 3, now(), now()),
-          (3, 4, now(), now()),
-          (4, 5, now(), now());
+          (1, 2, 3, now(), now()),
+          (2, 3, 4, now(), now()),
+          (3, 4, 5, now(), now()),
+          (4, 10, 1, now(), now()),
+          (5, 11, 2, now(), now());
 
         -- stream entries
 
@@ -121,7 +183,6 @@ namespace :tests do
           (8, 5, 'status', now(), now()),
           (9, 1, 'status', now(), now());
 
-
         -- custom emoji
 
         INSERT INTO "custom_emojis"
@@ -161,12 +222,12 @@ namespace :tests do
         -- follows
 
         INSERT INTO "follows"
-          (account_id, target_account_id, created_at, updated_at)
+          (id, account_id, target_account_id, created_at, updated_at)
         VALUES
-          (1, 5, now(), now()),
-          (6, 2, now(), now()),
-          (5, 2, now(), now()),
-          (6, 1, now(), now());
+          (1, 1, 5, now(), now()),
+          (2, 6, 2, now(), now()),
+          (3, 5, 2, now(), now()),
+          (4, 6, 1, now(), now());
 
         -- follow requests
 
@@ -175,6 +236,15 @@ namespace :tests do
         VALUES
           (2, 5, now(), now()),
           (5, 1, now(), now());
+
+        -- notifications
+
+        INSERT INTO "notifications"
+          (id, from_account_id, account_id, activity_type, activity_id, created_at, updated_at)
+        VALUES
+          (1, 6, 2, 'Follow', 2, now(), now()),
+          (2, 2, 1, 'Mention', 4, now(), now()),
+          (3, 1, 2, 'Mention', 5, now(), now());
       SQL
     end
   end