Skip to content

Commit

Permalink
Merge pull request #159 from bdunne/more_pictures_edge_cases
Browse files Browse the repository at this point in the history
Handle cases where a Picture with that id doesn't exist
(cherry picked from commit 40c5ced)

https://bugzilla.redhat.com/show_bug.cgi?id=1536046
  • Loading branch information
Fryguy authored and simaishi committed Jan 18, 2018
1 parent c3d2c7c commit 0e711b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def up

say_with_time("Moving picture content from BinaryBlobs to the pictures table") do
BinaryBlob.in_my_region.includes(:binary_blob_parts).where(:resource_type => "Picture").find_each do |blob|
Picture.update(blob.resource_id, :content => blob.data, :extension => blob.data_type, :md5 => blob.md5) if blob.resource_id
Picture.where(:id => blob.resource_id).update_all(:content => blob.data, :extension => blob.data_type, :md5 => blob.md5) if blob.resource_id
blob.destroy
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@
let(:picture_stub) { migration_stub :Picture }

migration_context :up do
it 'Destroys picture blobs without a picture' do
it 'Destroys picture blobs with an invalid picture id' do
picture = picture_stub.create!
blob = binary_blob_stub.create!(
:data_type => "png",
:md5 => "ce114e4501d2f4e2dcea3e17b546f339",
:part_size => 1.megabyte,
:resource_id => picture.id + 42,
:resource_type => "Picture",
:size => 14,
)
binary_blob_part_stub.create!(
:binary_blob_id => blob.id,
:data => "This is a test",
:md5 => "ce114e4501d2f4e2dcea3e17b546f339",
:size => 14,
)

migrate

expect(picture_stub.count).to eq(1)
expect(binary_blob_stub.count).to eq(0)
expect(binary_blob_part_stub.count).to eq(0)
end

it 'Destroys picture blobs with a nil picture id' do
blob = binary_blob_stub.create!(
:data_type => "png",
:md5 => "ce114e4501d2f4e2dcea3e17b546f339",
:part_size => 1.megabyte,
Expand Down

0 comments on commit 0e711b5

Please sign in to comment.