diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/email/attachment_uploader_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/gitlab/email/reply_parser_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/projects/upload_service_spec.rb | 48 |
3 files changed, 51 insertions, 25 deletions
diff --git a/spec/lib/gitlab/email/attachment_uploader_spec.rb b/spec/lib/gitlab/email/attachment_uploader_spec.rb new file mode 100644 index 00000000000..b54ee8aa72a --- /dev/null +++ b/spec/lib/gitlab/email/attachment_uploader_spec.rb @@ -0,0 +1,26 @@ +require "spec_helper" + +describe Gitlab::Email::AttachmentUploader do + def fixture_file(filename) + return '' if filename.blank? + file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) + File.read(file_path) + end + + describe "#execute" do + let(:project) { build(:project) } + let(:message_raw) { fixture_file("emails/attachment.eml") } + let(:message) { Mail::Message.new(message_raw) } + + it "creates a post with an attachment" do + links = described_class.new(message).execute(project) + link = links.first + + expect(link).not_to be_nil + expect(link[:is_image]).to be_truthy + expect(link[:alt]).to eq("bricks") + expect(link[:url]).to include("/#{project.path_with_namespace}") + expect(link[:url]).to include("bricks.png") + end + end +end diff --git a/spec/lib/gitlab/email/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb index 999515beb1c..32120d56cbc 100644 --- a/spec/lib/gitlab/email/reply_parser_spec.rb +++ b/spec/lib/gitlab/email/reply_parser_spec.rb @@ -8,7 +8,7 @@ describe Gitlab::Email::ReplyParser do File.read(file_path) end - describe 'self.parse_body' do + describe '#execute' do def test_parse_body(mail_string) described_class.new(Mail::Message.new(mail_string)).execute end diff --git a/spec/services/projects/upload_service_spec.rb b/spec/services/projects/upload_service_spec.rb index 7aa26857649..fa4ff6b01ad 100644 --- a/spec/services/projects/upload_service_spec.rb +++ b/spec/services/projects/upload_service_spec.rb @@ -13,13 +13,13 @@ describe Projects::UploadService do @link_to_file = upload_file(@project.repository, gif) end - it { expect(@link_to_file).to have_key('alt') } - it { expect(@link_to_file).to have_key('url') } - it { expect(@link_to_file).to have_key('is_image') } + it { expect(@link_to_file).to have_key(:alt) } + it { expect(@link_to_file).to have_key(:url) } + it { expect(@link_to_file).to have_key(:is_image) } it { expect(@link_to_file).to have_value('banana_sample') } - it { expect(@link_to_file['is_image']).to equal(true) } - it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") } - it { expect(@link_to_file['url']).to match('banana_sample.gif') } + it { expect(@link_to_file[:is_image]).to equal(true) } + it { expect(@link_to_file[:url]).to match("/#{@project.path_with_namespace}") } + it { expect(@link_to_file[:url]).to match('banana_sample.gif') } end context 'for valid png file' do @@ -29,13 +29,13 @@ describe Projects::UploadService do @link_to_file = upload_file(@project.repository, png) end - it { expect(@link_to_file).to have_key('alt') } - it { expect(@link_to_file).to have_key('url') } + it { expect(@link_to_file).to have_key(:alt) } + it { expect(@link_to_file).to have_key(:url) } it { expect(@link_to_file).to have_value('dk') } - it { expect(@link_to_file).to have_key('is_image') } - it { expect(@link_to_file['is_image']).to equal(true) } - it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") } - it { expect(@link_to_file['url']).to match('dk.png') } + it { expect(@link_to_file).to have_key(:is_image) } + it { expect(@link_to_file[:is_image]).to equal(true) } + it { expect(@link_to_file[:url]).to match("/#{@project.path_with_namespace}") } + it { expect(@link_to_file[:url]).to match('dk.png') } end context 'for valid jpg file' do @@ -44,13 +44,13 @@ describe Projects::UploadService do @link_to_file = upload_file(@project.repository, jpg) end - it { expect(@link_to_file).to have_key('alt') } - it { expect(@link_to_file).to have_key('url') } - it { expect(@link_to_file).to have_key('is_image') } + it { expect(@link_to_file).to have_key(:alt) } + it { expect(@link_to_file).to have_key(:url) } + it { expect(@link_to_file).to have_key(:is_image) } it { expect(@link_to_file).to have_value('rails_sample') } - it { expect(@link_to_file['is_image']).to equal(true) } - it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") } - it { expect(@link_to_file['url']).to match('rails_sample.jpg') } + it { expect(@link_to_file[:is_image]).to equal(true) } + it { expect(@link_to_file[:url]).to match("/#{@project.path_with_namespace}") } + it { expect(@link_to_file[:url]).to match('rails_sample.jpg') } end context 'for txt file' do @@ -59,13 +59,13 @@ describe Projects::UploadService do @link_to_file = upload_file(@project.repository, txt) end - it { expect(@link_to_file).to have_key('alt') } - it { expect(@link_to_file).to have_key('url') } - it { expect(@link_to_file).to have_key('is_image') } + it { expect(@link_to_file).to have_key(:alt) } + it { expect(@link_to_file).to have_key(:url) } + it { expect(@link_to_file).to have_key(:is_image) } it { expect(@link_to_file).to have_value('doc_sample.txt') } - it { expect(@link_to_file['is_image']).to equal(false) } - it { expect(@link_to_file['url']).to match("/#{@project.path_with_namespace}") } - it { expect(@link_to_file['url']).to match('doc_sample.txt') } + it { expect(@link_to_file[:is_image]).to equal(false) } + it { expect(@link_to_file[:url]).to match("/#{@project.path_with_namespace}") } + it { expect(@link_to_file[:url]).to match('doc_sample.txt') } end context 'for too large a file' do |