basic lightbox support

This commit is contained in:
Sam Saffron 2013-02-19 17:57:14 +11:00
parent 14c0b96d55
commit d9531d94d5
15 changed files with 191 additions and 44 deletions

View file

@ -3,6 +3,11 @@ require 'spec_helper'
require 'cooked_post_processor'
describe CookedPostProcessor do
let :cpp do
post = Fabricate.build(:post_with_youtube)
post.id = 123
CookedPostProcessor.new(post)
end
context 'process_onebox' do
@ -39,10 +44,11 @@ EXPECTED
@topic = Fabricate(:topic)
@post = Fabricate.build(:post_with_image_url, topic: @topic, user: @topic.user)
@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
it "doesn't call image_dimensions because it knows the size" do
CookedPostProcessor.expects(:image_dimensions).never
@cpp.expects(:image_dimensions).never
@cpp.post_process_images
end
@ -55,7 +61,8 @@ EXPECTED
context 'with unsized images in the post' do
before do
CookedPostProcessor.expects(:image_dimensions).returns([123, 456])
FastImage.stubs(:size).returns([123, 456])
CookedPostProcessor.any_instance.expects(:image_dimensions).returns([123, 456])
@post = Fabricate(:post_with_images)
end
@ -72,10 +79,36 @@ EXPECTED
end
end
context 'link convertor' do
before do
SiteSetting.stubs(:crawl_images?).returns(true)
end
let :post_with_img do
Fabricate.build(:post, cooked: '<p><img src="http://hello.com/image.png"></p>')
end
let :cpp_for_post do
CookedPostProcessor.new(post_with_img)
end
it 'convert img tags to links if they are sized down' do
cpp_for_post.expects(:get_size).returns([2000,2000]).twice
cpp_for_post.post_process
cpp_for_post.html.should =~ /a href/
end
it 'does not convert img tags to links if they are small' do
cpp_for_post.expects(:get_size).returns([200,200]).twice
cpp_for_post.post_process
(cpp_for_post.html !~ /a href/).should be_true
end
end
context 'image_dimensions' do
it "returns unless called with a http or https url" do
CookedPostProcessor.image_dimensions('/tmp/image.jpg').should be_blank
cpp.image_dimensions('/tmp/image.jpg').should be_blank
end
context 'with valid url' do
@ -86,13 +119,13 @@ EXPECTED
it "doesn't call fastimage if image crawling is disabled" do
SiteSetting.expects(:crawl_images?).returns(false)
FastImage.expects(:size).never
CookedPostProcessor.image_dimensions(@url)
cpp.image_dimensions(@url)
end
it "calls fastimage if image crawling is enabled" do
SiteSetting.expects(:crawl_images?).returns(true)
FastImage.expects(:size).with(@url)
CookedPostProcessor.image_dimensions(@url)
cpp.image_dimensions(@url)
end
end
end