* Enable Rails cops * Fix Rails/DynamicFindBy * Fix Rails/HttpStatus * Fix Rails/Blank * Fix Rails/RequestReferer * Fix Rails/ActiveRecordAliases * Fix Rails/FindBy * Fix Rails/Presence * Fix Rails/Delegate * Fix Rails/Validation * Fix Rails/PluralizationGrammar * Fix Rails/Present * Fix Rails/Output * Fix Rails/Blank * Fix Rails/FilePath * Fix Rails/InverseOf * Fix Rails/LexicallyScopedActionFilter * Add Rails/OutputSafety to TODO * Add Rails/HasManyOrHasOneDependent to TODO * Add Rails/SkipsModelValidations to TODO
55 lines
1.7 KiB
Ruby
55 lines
1.7 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "ImageUploads", type: :request do
|
|
describe "POST/image_uploads" do
|
|
let(:user) { create(:user) }
|
|
let(:headers) { { "Content-Type": "application/json", Accept: "application/json" } }
|
|
let(:image) do
|
|
Rack::Test::UploadedFile.new(
|
|
Rails.root.join("spec", "support", "fixtures", "images", "image1.jpeg"),
|
|
"image/jpeg",
|
|
)
|
|
end
|
|
let(:bad_image) do
|
|
Rack::Test::UploadedFile.new(
|
|
Rails.root.join("spec", "support", "fixtures", "images", "bad-image.jpg"),
|
|
"image/jpeg",
|
|
)
|
|
end
|
|
|
|
context "when not logged-in" do
|
|
it "responds with 401" do
|
|
post "/image_uploads", headers: headers
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
|
|
context "when logged-in" do
|
|
before do
|
|
sign_in user
|
|
end
|
|
|
|
it "returns json" do
|
|
post "/image_uploads", headers: headers
|
|
expect(response.content_type).to eq("application/json")
|
|
end
|
|
|
|
it "provides a link" do
|
|
# this test is a little flimsy
|
|
post "/image_uploads", headers: headers, params: { image: image }
|
|
expect(response.body).to match("\/i\/.+\.")
|
|
end
|
|
|
|
it "prevents image with resolutions larger than 4096x4096" do
|
|
post "/image_uploads", headers: headers, params: { image: bad_image }
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
end
|
|
|
|
it "returns a JSON error if something goes wrong" do
|
|
post "/image_uploads", headers: headers, params: { image: bad_image }
|
|
result = JSON.parse(response.body)
|
|
expect(result["error"]).not_to be_nil
|
|
end
|
|
end
|
|
end
|
|
end
|