Skip to content

A platform for community discussion. Free, open, simple.

correct specs

Samd7b1919ead2b
diff --git a/lib/upload_creator.rb b/lib/upload_creator.rb
index 3bb50448382..5dd94de3a49 100644
--- a/lib/upload_creator.rb
+++ b/lib/upload_creator.rb
@@ -82,7 +82,7 @@ class UploadCreator
# otherwise validation will fail and we can not save
# TODO decide if we only run the validation on the extension
if File.extname(@filename) != ".#{image_type}"
- fixed_original_filename = "#{@filename}.fixed.#{image_type}"
+ fixed_original_filename = "#{@filename}_fixed.#{image_type}"
end
end
diff --git a/spec/fixtures/images/not_an_image b/spec/fixtures/images/not_an_image
new file mode 100644
index 00000000000..acbe86c7c89
--- /dev/null
+++ b/spec/fixtures/images/not_an_image
@@ -0,0 +1 @@
+abcd
diff --git a/spec/lib/upload_creator_spec.rb b/spec/lib/upload_creator_spec.rb
index 9c23672eeea..7a85c0ffb5b 100644
--- a/spec/lib/upload_creator_spec.rb
+++ b/spec/lib/upload_creator_spec.rb
@@ -41,7 +41,7 @@ RSpec.describe UploadCreator do
expect(upload.extension).to eq('png')
expect(File.extname(upload.url)).to eq('.png')
- expect(upload.original_filename).to eq('png_as.bin.fixed.png')
+ expect(upload.original_filename).to eq('png_as.bin_fixed.png')
end
end
@@ -65,7 +65,7 @@ RSpec.describe UploadCreator do
expect(upload.extension).to eq('jpeg')
expect(File.extname(upload.url)).to eq('.jpeg')
- expect(upload.original_filename).to eq('logo.png.fixed.jpeg')
+ expect(upload.original_filename).to eq('logo.png_fixed.jpeg')
end
end
end
diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb
index 5145c7ae70b..1ee24f9b953 100644
--- a/spec/models/upload_spec.rb
+++ b/spec/models/upload_spec.rb
@@ -53,8 +53,7 @@ describe Upload do
it "should create an invalid upload when the filename is blank" do
SiteSetting.authorized_extensions = "*"
-
- created_upload = UploadCreator.new(image, nil).create_for(user_id)
+ created_upload = UploadCreator.new(attachment, nil).create_for(user_id)
expect(created_upload.valid?).to eq(false)
end
diff --git a/spec/requests/uploads_controller_spec.rb b/spec/requests/uploads_controller_spec.rb
index fac1a98d8d2..7ac95c9bbc4 100644
--- a/spec/requests/uploads_controller_spec.rb
+++ b/spec/requests/uploads_controller_spec.rb
@@ -206,13 +206,22 @@ describe UploadsController do
expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"logo.png\"")
end
- it "handles file without extension" do
+ it "handles image without extension" do
SiteSetting.authorized_extensions = "*"
upload = upload_file("image_no_extension")
get "/uploads/#{site}/#{upload.sha1}.json"
expect(response.status).to eq(200)
- expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"image_no_extension\"")
+ expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"image_no_extension_fixed.png\"")
+ end
+
+ it "handles file without extension" do
+ SiteSetting.authorized_extensions = "*"
+ upload = upload_file("not_an_image")
+
+ get "/uploads/#{site}/#{upload.sha1}.json"
+ expect(response.status).to eq(200)
+ expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"not_an_image\"")
end
context "prevent anons from downloading files" do