FIX: rescale image during cooked_post_processor when only img height or width is specified

This commit is contained in:
kerryliu
2015-08-29 14:56:25 -07:00
parent aa45429989
commit c85835afc3
2 changed files with 45 additions and 1 deletions

View File

@ -182,6 +182,37 @@ describe CookedPostProcessor do
end
context ".get_size_from_attributes" do
let(:post) { build(:post) }
let(:cpp) { CookedPostProcessor.new(post) }
it "returns the size when width and height are specified" do
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 50, 'height' => 70}
expect(cpp.get_size_from_attributes(img)).to eq([50, 70])
end
it "returns the size when width and height are floats" do
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 50.2, 'height' => 70.1}
expect(cpp.get_size_from_attributes(img)).to eq([50, 70])
end
it "resizes when only width is specified" do
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 100}
SiteSetting.stubs(:crawl_images?).returns(true)
FastImage.expects(:size).returns([200, 400])
expect(cpp.get_size_from_attributes(img)).to eq([100, 200])
end
it "resizes when only height is specified" do
img = { 'src' => 'http://foo.bar/image3.png', 'height' => 100}
SiteSetting.stubs(:crawl_images?).returns(true)
FastImage.expects(:size).returns([100, 300])
expect(cpp.get_size_from_attributes(img)).to eq([33, 100])
end
end
context ".get_size_from_image_sizes" do
let(:post) { build(:post) }