mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: thumbnailing wasn't working with CDN enabled
This commit is contained in:
@@ -65,13 +65,13 @@ describe CookedPostProcessor do
|
||||
context "with locally uploaded images" do
|
||||
|
||||
let(:upload) { Fabricate(:upload) }
|
||||
let(:post) { Fabricate(:post_with_uploaded_images) }
|
||||
let(:post) { Fabricate(:post_with_uploaded_image) }
|
||||
let(:cpp) { CookedPostProcessor.new(post) }
|
||||
before { FastImage.stubs(:size) }
|
||||
before { FastImage.stubs(:size).returns([200, 400]) }
|
||||
|
||||
# all in one test to speed things up
|
||||
it "works" do
|
||||
Upload.expects(:get_from_url).returns(upload).twice
|
||||
Upload.expects(:get_from_url).returns(upload)
|
||||
cpp.post_process_images
|
||||
# ensures absolute urls on uploaded images
|
||||
cpp.html.should =~ /#{LocalStore.base_url}/
|
||||
@@ -148,7 +148,7 @@ describe CookedPostProcessor do
|
||||
context "topic image" do
|
||||
|
||||
let(:topic) { build(:topic, id: 1) }
|
||||
let(:post) { Fabricate(:post_with_uploaded_images, topic: topic) }
|
||||
let(:post) { Fabricate(:post_with_uploaded_image, topic: topic) }
|
||||
let(:cpp) { CookedPostProcessor.new(post) }
|
||||
|
||||
it "adds a topic image if there's one in the post" do
|
||||
|
||||
@@ -43,11 +43,8 @@ Fabricator(:post_with_images_in_quote_and_onebox, from: :post) do
|
||||
'
|
||||
end
|
||||
|
||||
Fabricator(:post_with_uploaded_images, from: :post) do
|
||||
cooked '
|
||||
<img src="/uploads/default/2/3456789012345678.png" width="1500" height="2000">
|
||||
<img src="/uploads/default/1/1234567890123456.jpg">
|
||||
'
|
||||
Fabricator(:post_with_uploaded_image, from: :post) do
|
||||
cooked '<img src="/uploads/default/2/3456789012345678.png" width="1500" height="2000">'
|
||||
end
|
||||
|
||||
Fabricator(:post_with_an_attachment, from: :post) do
|
||||
|
||||
@@ -153,11 +153,11 @@ describe Upload do
|
||||
it "identifies internal or relatives urls" do
|
||||
Discourse.expects(:base_url_no_prefix).returns("http://discuss.site.com")
|
||||
Upload.has_been_uploaded?("http://discuss.site.com/uploads/default/42/0123456789ABCDEF.jpg").should == true
|
||||
Upload.has_been_uploaded?("/uploads/42/0123456789ABCDEF.jpg").should == true
|
||||
Upload.has_been_uploaded?("/uploads/default/42/0123456789ABCDEF.jpg").should == true
|
||||
end
|
||||
|
||||
it "identifies internal urls when using a CDN" do
|
||||
ActionController::Base.expects(:asset_host).returns("http://my.cdn.com").twice
|
||||
Rails.configuration.action_controller.expects(:asset_host).returns("http://my.cdn.com").twice
|
||||
Upload.has_been_uploaded?("http://my.cdn.com/uploads/default/42/0123456789ABCDEF.jpg").should == true
|
||||
end
|
||||
|
||||
@@ -194,10 +194,20 @@ describe Upload do
|
||||
|
||||
context ".get_from_url" do
|
||||
|
||||
it "works when the file has been uploaded" do
|
||||
Upload.expects(:where).returns([]).once
|
||||
Upload.get_from_url("/uploads/default/1/10387531.jpg")
|
||||
end
|
||||
|
||||
it "works when using a cdn" do
|
||||
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
||||
Upload.expects(:where).with(url: "/uploads/default/1/02395732905.jpg").returns([]).once
|
||||
Upload.get_from_url("http://my.cdn.com/uploads/default/1/02395732905.jpg")
|
||||
end
|
||||
|
||||
it "works only when the file has been uploaded" do
|
||||
Upload.expects(:has_been_uploaded?).returns(false)
|
||||
Upload.expects(:where).never
|
||||
Upload.get_from_url("discourse.org")
|
||||
Upload.get_from_url("http://domain.com/my/file.txt")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user