2020-05-25 01:38:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Jobs::MigrateGroupFlairImages do
|
|
|
|
let(:image_url) { "https://omg.aws.somestack/test.png" }
|
2020-05-25 15:13:50 -04:00
|
|
|
let(:group) { Fabricate(:group) }
|
2020-05-25 01:38:47 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_request(:get, image_url).to_return(
|
|
|
|
status: 200, body: file_from_fixtures("smallest.png").read
|
|
|
|
)
|
2020-05-25 03:41:00 -04:00
|
|
|
@orig_logger = Rails.logger
|
|
|
|
Rails.logger = @fake_logger = FakeLogger.new
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Rails.logger = @orig_logger
|
2020-05-25 01:38:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should migrate to the new group `flair_upload_id` column correctly' do
|
2020-05-25 15:13:50 -04:00
|
|
|
DB.exec(<<~SQL, flair_url: image_url)
|
|
|
|
UPDATE groups SET flair_url = :flair_url WHERE id = #{group.id}
|
|
|
|
SQL
|
2020-05-25 01:38:47 -04:00
|
|
|
|
|
|
|
expect do
|
|
|
|
described_class.new.execute_onceoff({})
|
|
|
|
end.to change { Upload.count }.by(1)
|
|
|
|
|
|
|
|
group.reload
|
2020-06-04 22:13:15 -04:00
|
|
|
upload = Upload.last
|
|
|
|
expect(group.flair_upload).to eq(upload)
|
2020-12-07 06:35:41 -05:00
|
|
|
expect(group.flair_url).to eq(upload.url)
|
2020-05-25 01:38:47 -04:00
|
|
|
expect(group[:flair_url]).to eq(nil)
|
|
|
|
end
|
2020-05-25 03:41:00 -04:00
|
|
|
|
|
|
|
it 'should skip groups with invalid flair URLs' do
|
2020-05-25 15:13:50 -04:00
|
|
|
DB.exec("UPDATE groups SET flair_url = 'abc' WHERE id = #{group.id}")
|
2020-05-25 03:41:00 -04:00
|
|
|
described_class.new.execute_onceoff({})
|
|
|
|
expect(Rails.logger.warnings.count).to eq(0)
|
|
|
|
end
|
2020-05-25 01:38:47 -04:00
|
|
|
end
|