diff --git a/plugins/discourse-narrative-bot/jobs/onceoff/remap_old_bot_images.rb b/plugins/discourse-narrative-bot/jobs/onceoff/remap_old_bot_images.rb new file mode 100644 index 00000000000..d23f1c8d054 --- /dev/null +++ b/plugins/discourse-narrative-bot/jobs/onceoff/remap_old_bot_images.rb @@ -0,0 +1,36 @@ +module Jobs + module DiscourseNarrativeBot + class RemapOldBotImages < ::Jobs::Onceoff + def execute_onceoff(args) + paths = [ + "/images/font-awesome-link.png", + "/images/unicorn.png", + "/images/font-awesome-ellipsis.png", + "/images/font-awesome-bookmark.png", + "/images/font-awesome-smile.png", + "/images/font-awesome-flag.png", + "/images/font-awesome-search.png", + "/images/capybara-eating.gif", + "/images/font-awesome-pencil.png", + "/images/font-awesome-trash.png", + "/images/font-awesome-rotate-left.png", + "/images/font-awesome-gear.png", + ] + + Post.raw_match("/images/").where(user_id: -2).find_each do |post| + if (matches = post.raw.scan(/(? below and **bookmark this private message**. If you do, there may be a :gift: in your future!' + ) + end + + before do + post + end + + it 'should remap the links correctly' do + expected_raw = 'If you’d like to learn more, select below and **bookmark this private message**. If you do, there may be a :gift: in your future!' + + 2.times do + described_class.new.execute_onceoff({}) + expect(post.reload.raw).to eq(expected_raw) + end + end + + context 'subfolder' do + let(:post) do + Fabricate(:post, + user_id: -2, + raw: 'If you’d like to learn more, select below and **bookmark this private message**. If you do, there may be a :gift: in your future!' + ) + end + + it 'should remap the links correctly' do + described_class.new.execute_onceoff({}) + + expect(post.reload.raw).to eq( + 'If you’d like to learn more, select below and **bookmark this private message**. If you do, there may be a :gift: in your future!' + ) + end + end + end +end