Skip to content

Instantly share code, notes, and snippets.

@elrayle
Created November 5, 2015 19:37
Show Gist options
  • Save elrayle/fc44e802b36dc2da98dc to your computer and use it in GitHub Desktop.
Save elrayle/fc44e802b36dc2da98dc to your computer and use it in GitHub Desktop.
context "when multiple files are uploaded together" do
let(:mock1) { GenericFile.new(id: 'test_1') }
# let(:mock2) { GenericFile.new(id: 'test_2') }
# let(:mock3) { GenericFile.new(id: 'test_3') }
let(:file1) { fixture_file_upload('/world.png', 'image/png') }
let(:file2) { fixture_file_upload('/image.jpg', 'image/jpg') }
let(:file3) { fixture_file_upload('/4-20.png', 'image/png') }
let(:batch1) { Batch.create }
let(:batch1_id) { batch1.id }
let(:batch2) { Batch.create }
let(:batch2_id) { batch2.id }
let(:batch3) { Batch.create }
let(:batch3_id) { batch3.id }
before do
# allow(GenericFile).to receive(:new).and_call_original
# allow(GenericFile).to receive(:new).and_return(mock3)
# allow(GenericFile).to receive(:new).with(id: "test_1").and_return(mock1)
# allow(GenericFile).to receive(:new).with(id: "test_2").and_return(mock2)
# allow(GenericFile).to receive(:new).with(id: "test_3").and_return(mock3)
# allow(GenericFile).to receive(:new).with(label: "world.png").and_return(mock1)
# allow(GenericFile).to receive(:new).with(label: "image.jpg").and_return(mock2)
# allow(GenericFile).to receive(:new).with(label: "4-20.png").and_return(mock3)
end
it "adds new files to collection" do
# xhr :post, :create, files: [file1,file2,file3], Filename: "The world", batch_id: batch_id, permission: { "group" => { "public" => "read" } }, terms_of_service: "1", collection: collection_id
xhr :post, :create, files: [file1], Filename: "world.png", batch_id: batch1_id, permission: { "group" => { "public" => "read" } }, terms_of_service: "1", collection: collection_id
xhr :post, :create, files: [file2], Filename: "image.jpg", batch_id: batch2_id, permission: { "group" => { "public" => "read" } }, terms_of_service: "1", collection: collection_id
xhr :post, :create, files: [file3], Filename: "4-20.png", batch_id: batch3_id, permission: { "group" => { "public" => "read" } }, terms_of_service: "1", collection: collection_id
expect(response).to be_success
updated_collection = Collection.find(collection_id)
# This is confirming that the file was added to the collection
expect(updated_collection.member_ids).to eq ['test_1','test_2','test_3']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment