require 'spec_helper' describe "Attaching a message" do describe ".send_message_mult_attach" do let(:entity1) { FactoryGirl.create(:user) } let(:entity2) { FactoryGirl.create(:user) } let(:attachments) { [{ :file => File.open('spec/testfile.txt') }, { :file => File.open('spec/1.mp4') }] } let!(:receipt_from_sent_message) { entity1.send_message_mult_attach(entity2, "Body", "Subject", true, attachments) } let!(:message) { receipt_from_sent_message.message } it "attaches a file" do expect(message.message_attachments.first.file.file.filename).to eq "testfile.txt" end it "stores the content type of a plain text file" do expect(message.message_attachments.first.file.content_type).to eq 'text/plain' end it "stores the content type of a video file" do expect(message.message_attachments.second.file.content_type).to eq 'application/mp4' end it "attaches two files" do expect(message.message_attachments.count).to eq 2 end it "returns the filename after the upload" do expect(message.message_attachments.first.file.file.filename).to eq 'testfile.txt' end context "without an attachment" do subject { entity1.send_message_mult_attach(entity2, "Body", "Subject", true) } it "sends a message successfully" do expect(subject.class).to eq Mailboxer::Receipt end it "has no message attachments" do expect(subject.message.message_attachments).to eq([]) end end end describe ".reply_to_sender_mult_attach" do let(:entity1) { FactoryGirl.create(:user) } let(:entity2) { FactoryGirl.create(:user) } let(:attachments) { [{ :file => File.open('spec/testfile.txt') }, { :file => File.open('spec/1.mp4') }] } let!(:receipt) { entity1.send_message_mult_attach(entity2, "Body", "Subject", true, attachments)} let!(:receipt_from_reply) { entity1.reply_to_sender_mult_attach(receipt, "Body", "Subject", true, attachments) } let!(:message) { receipt_from_reply.message } it "attaches a file" do expect(message.message_attachments.first.file.file.filename).to eq "testfile.txt" end it "stores the content type of a plain text file" do expect(message.message_attachments.first.file.content_type).to eq 'text/plain' end it "stores the content type of a video file" do expect(message.message_attachments.second.file.content_type).to eq 'application/mp4' end it "attaches two files" do expect(message.message_attachments.count).to eq 2 end it "returns the filename after the upload" do expect(message.message_attachments.first.file.file.filename).to eq 'testfile.txt' end context "without an attachment" do subject { entity1.reply_to_sender_mult_attach(receipt, "Body", "Subject", true) } it "has no message attachments" do receipt = subject expect(receipt.message.message_attachments).to eq([]) end end end end