From d9a77798117e02299a830d7ab2441bcb63c5468e Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 18 Jul 2023 07:01:19 +0800 Subject: [PATCH] DEV: Fix flaky core backend spec (#22650) Why this change? The user id in a fixture file was hardcoded to 666. Once we've fabricated enough user objects until the sequence for `User#id` reaches 666, the specs in vanilla_body_parser_spec.rb will fail. What is the fix here? This commit increases the user id to a large integer which we will likely never hit in the next 10-20 years. --- spec/fixtures/json/vanilla-rich-posts.json | 2 +- spec/script/import_scripts/vanilla_body_parser_spec.rb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/fixtures/json/vanilla-rich-posts.json b/spec/fixtures/json/vanilla-rich-posts.json index e539e1d3728..850572348a1 100644 --- a/spec/fixtures/json/vanilla-rich-posts.json +++ b/spec/fixtures/json/vanilla-rich-posts.json @@ -3,7 +3,7 @@ "insert": "This is a message.\nAnd a second line.\n" }], "mention": [ - { "insert": { "mention": { "name": "Gandalf The Grey", "userID": 666 } } }, + { "insert": { "mention": { "name": "Gandalf The Grey", "userID": 999999999 } } }, { "insert": ", what do you think?\n" } diff --git a/spec/script/import_scripts/vanilla_body_parser_spec.rb b/spec/script/import_scripts/vanilla_body_parser_spec.rb index 50475c50290..19bfd49bdc5 100644 --- a/spec/script/import_scripts/vanilla_body_parser_spec.rb +++ b/spec/script/import_scripts/vanilla_body_parser_spec.rb @@ -96,6 +96,7 @@ this starts with spaces but IS NOT a quote" \ { "Format" => "Rich", "Body" => rich_bodies[:mention].to_json }, user_id, ).parse + expect(parsed).to eq "@Gandalf The Grey, what do you think?" end @@ -107,9 +108,10 @@ this starts with spaces but IS NOT a quote" \ name: "Gandalf The Grey", username: "gandalf_the_grey", ) + lookup.add_user(mentioned.id.to_s, mentioned) - body = rich_bodies[:mention].to_json.gsub("666", mentioned.id.to_s) + body = rich_bodies[:mention].to_json.gsub("999999999", mentioned.id.to_s) parsed = VanillaBodyParser.new({ "Format" => "Rich", "Body" => body }, user_id).parse expect(parsed).to eq "@gandalf_the_grey, what do you think?" end @@ -120,6 +122,7 @@ this starts with spaces but IS NOT a quote" \ { "Format" => "Rich", "Body" => rich_bodies[:links].to_json }, user_id, ).parse + expect( parsed, ).to eq "We can link to the Discourse home page and it works."