mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
cleaned up CookedPostProcessor and improved specs
This commit is contained in:
@ -41,7 +41,6 @@ describe CookedPostProcessor do
|
||||
before do
|
||||
@topic = Fabricate(:topic)
|
||||
@post = Fabricate.build(:post_with_image_url, topic: @topic, user: @topic.user)
|
||||
ImageSorcery.any_instance.stubs(:convert).returns(false)
|
||||
@cpp = CookedPostProcessor.new(@post, image_sizes: {'http://www.forumwarz.com/images/header/logo.png' => {'width' => 111, 'height' => 222}})
|
||||
@cpp.expects(:get_size).returns([111,222])
|
||||
end
|
||||
@ -65,7 +64,6 @@ describe CookedPostProcessor do
|
||||
before do
|
||||
FastImage.stubs(:size).returns([123, 456])
|
||||
ImageSorcery.any_instance.stubs(:convert).returns(false)
|
||||
CookedPostProcessor.any_instance.expects(:image_dimensions).returns([123, 456])
|
||||
creator = PostCreator.new(user, raw: Fabricate.build(:post_with_images).raw, topic_id: topic.id)
|
||||
@post = creator.create
|
||||
end
|
||||
@ -89,7 +87,6 @@ describe CookedPostProcessor do
|
||||
let(:processor) { CookedPostProcessor.new(post) }
|
||||
|
||||
before do
|
||||
ImageSorcery.any_instance.stubs(:convert).returns(false)
|
||||
processor.post_process_images
|
||||
end
|
||||
|
||||
@ -151,4 +148,35 @@ describe CookedPostProcessor do
|
||||
end
|
||||
end
|
||||
|
||||
context 'get_image_uri' do
|
||||
|
||||
it "returns nil unless the scheme is either http or https" do
|
||||
cpp.get_image_uri("http://domain.com").should == URI.parse("http://domain.com")
|
||||
cpp.get_image_uri("https://domain.com").should == URI.parse("https://domain.com")
|
||||
cpp.get_image_uri("ftp://domain.com").should == nil
|
||||
cpp.get_image_uri("ftps://domain.com").should == nil
|
||||
cpp.get_image_uri("//domain.com").should == nil
|
||||
cpp.get_image_uri("/tmp/image.png").should == nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'has_been_uploaded?' do
|
||||
|
||||
it "identifies internal urls" do
|
||||
Discourse.expects(:base_url_no_prefix).returns("http://my.discourse.com")
|
||||
cpp.has_been_uploaded?("http://my.discourse.com").should == true
|
||||
end
|
||||
|
||||
it "identifies internal urls when using a CDN" do
|
||||
ActionController::Base.expects(:asset_host).returns("http://my.cdn.com").twice
|
||||
cpp.has_been_uploaded?("http://my.cdn.com").should == true
|
||||
end
|
||||
|
||||
it "identifies external urls" do
|
||||
cpp.has_been_uploaded?("http://domain.com").should == false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user