gitlab-org--gitlab-foss/spec/lib/gitlab/git/patches/collection_spec.rb
Bob Van Landuyt 6fbdc5ed52 Apply patches when creating MR via email
This allows users to add patches as attachments to merge request
created via email.

When an email to create a merge request is sent, all the attachments
ending in `.patch` will be applied to the branch specified in the
subject of the email. If the branch did not exist, it will be created
from the HEAD of the repository.

When the patches could not be applied, the error message will be
replied to the user.

The patches can have a maximum combined size of 2MB for now.
2018-11-07 16:27:55 +01:00

28 lines
857 B
Ruby

# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Git::Patches::Collection do
let(:patches_folder) { Rails.root.join('spec/fixtures/patchfiles') }
let(:patch_content1) do
File.read(File.join(patches_folder, "0001-This-does-not-apply-to-the-feature-branch.patch"))
end
let(:patch_content2) do
File.read(File.join(patches_folder, "0001-A-commit-from-a-patch.patch"))
end
subject(:collection) { described_class.new([patch_content1, patch_content2]) }
describe '#size' do
it 'combines the size of the patches' do
expect(collection.size).to eq(549.bytes + 424.bytes)
end
end
describe '#valid_size?' do
it 'is not valid if the total size is bigger than 2MB' do
expect(collection).to receive(:size).and_return(2500.kilobytes)
expect(collection).not_to be_valid_size
end
end
end