2011-06-21 00:39:59 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Locomotive::Liquid::Filters::Resize do
|
|
|
|
before :each do
|
2011-08-25 21:28:56 +00:00
|
|
|
@site = FactoryGirl.create(:site)
|
|
|
|
@theme_asset = FactoryGirl.create(:theme_asset, :source => FixturedAsset.open('5k.png'), :site => @site)
|
2011-06-21 00:39:59 +00:00
|
|
|
@theme_asset_path = "/sites/#{@theme_asset.site_id}/theme/images/5k.png"
|
2011-08-25 21:28:56 +00:00
|
|
|
@asset = FactoryGirl.create(:asset, :source => FixturedAsset.open('5k.png'), :site => @site)
|
2011-06-21 00:39:59 +00:00
|
|
|
@asset_url = @asset.source.url
|
|
|
|
@asset_path = "/sites/#{@asset.site_id}/assets/#{@asset.id}/5k.png"
|
|
|
|
@context = Liquid::Context.new( { }, { 'asset_url' => @asset_url, 'theme_asset' => @theme_asset.to_liquid }, { :site => @site })
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resize' do
|
|
|
|
context 'when an asset url string is given' do
|
|
|
|
before :each do
|
|
|
|
@template = Liquid::Template.parse('{{ asset_url | resize: "40x30" }}')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return the location of the resized image' do
|
2011-06-28 13:38:13 +00:00
|
|
|
@template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/
|
2011-06-21 00:39:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should use the path in the public folder to generate a location' do
|
2011-11-27 08:02:20 +00:00
|
|
|
@template.render(@context).should == Locomotive::Dragonfly.resize_url(@asset_path, '40x30')
|
2011-06-21 00:39:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a theme asset is given' do
|
|
|
|
before :each do
|
|
|
|
@template = Liquid::Template.parse("{{ theme_asset | resize: '300x400' }}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return the location of the resized image' do
|
2011-06-28 13:38:13 +00:00
|
|
|
@template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/
|
2011-06-21 00:39:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should use the path of the theme asset to generate a location' do
|
2011-11-27 08:02:20 +00:00
|
|
|
@template.render(@context).should == Locomotive::Dragonfly.resize_url(@theme_asset_path, '300x400')
|
2011-06-21 00:39:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no resize string is given' do
|
|
|
|
before :each do
|
|
|
|
@template = Liquid::Template.parse('{{ asset | resize: }}')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a liquid error' do
|
|
|
|
@template.render(@context).should include 'Liquid error: wrong number of arguments'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-11-27 08:02:20 +00:00
|
|
|
end
|