Sha256: 2709d0574dbb28a38584d4072ebb8d3c85ab74203cb19f613cdf8fb685b4ac0f
Contents?: true
Size: 1.65 KB
Versions: 8
Compression:
Stored size: 1.65 KB
Contents
describe Sufia::UploadsController do let(:user) { create(:user) } describe "#create" do let(:file) { fixture_file_upload('/world.png', 'image/png') } context "when signed in" do before do sign_in user end it "is successful" do post :create, params: { files: [file], format: 'json' } expect(response).to be_success expect(assigns(:upload)).to be_kind_of Sufia::UploadedFile expect(assigns(:upload)).to be_persisted expect(assigns(:upload).user).to eq user end end context "when not signed in" do it "is unauthorized" do post :create, params: { files: [file], format: 'json' } expect(response.status).to eq 401 end end end describe "#destroy" do let(:file) { File.open(fixture_path + '/world.png') } let(:uploaded_file) { Sufia::UploadedFile.create(file: file, user: user) } context "when signed in" do before do sign_in user end it "destroys the uploaded file" do delete :destroy, params: { id: uploaded_file } expect(response.status).to eq 204 expect(assigns[:upload]).to be_destroyed expect(File.exist?(uploaded_file.file.file.file)).to be false end it "doesn't destroy files that don't belong to me" do delete :destroy, params: { id: Sufia::UploadedFile.create(file: file) } expect(response.status).to eq 401 end end context "when not signed in" do it "is redirected to sign in" do delete :destroy, params: { id: uploaded_file } expect(response).to redirect_to main_app.new_user_session_path end end end end
Version data entries
8 entries across 8 versions & 1 rubygems