engine/spec/models/theme_asset_spec.rb

108 lines
3.0 KiB
Ruby
Raw Normal View History

2010-05-11 21:38:52 +00:00
require 'spec_helper'
2010-05-11 21:38:52 +00:00
describe ThemeAsset do
2010-05-11 21:38:52 +00:00
describe 'attaching a file' do
2010-05-11 21:38:52 +00:00
before(:each) do
ThemeAsset.any_instance.stubs(:site_id).returns('test')
@asset = Factory.build(:theme_asset)
end
2010-05-11 21:38:52 +00:00
describe 'file is a picture' do
2010-05-11 21:38:52 +00:00
it 'should process picture' do
@asset.source = FixturedAsset.open('5k.png')
@asset.source.file.content_type.should_not be_nil
@asset.image?.should be_true
end
2010-05-11 21:38:52 +00:00
it 'should get width and height from the image' do
@asset.source = FixturedAsset.open('5k.png')
@asset.width.should == 32
@asset.height.should == 32
end
2010-05-11 21:38:52 +00:00
it 'should have a slug' do
@asset.source = FixturedAsset.open('5k.png')
@asset.save
@asset.slug.should == '5k'
end
2010-05-11 21:38:52 +00:00
end
2010-05-11 21:38:52 +00:00
describe 'file is not allowed' do
2010-05-11 21:38:52 +00:00
it 'should not be valid' do
@asset.source = FixturedAsset.open('wrong.txt')
@asset.valid?.should be_false
@asset.errors[:source].should_not be_blank
end
2010-05-11 21:38:52 +00:00
end
2010-05-11 21:38:52 +00:00
it 'should process stylesheet' do
@asset.source = FixturedAsset.open('main.css')
@asset.source.file.content_type.should_not be_nil
@asset.stylesheet?.should be_true
end
2010-05-11 21:38:52 +00:00
it 'should process javascript' do
@asset.source = FixturedAsset.open('application.js')
@asset.source.file.content_type.should_not be_nil
@asset.javascript?.should be_true
end
2010-05-11 21:38:52 +00:00
it 'should get size' do
@asset.source = FixturedAsset.open('main.css')
@asset.size.should == 25
end
2010-05-11 21:38:52 +00:00
end
2010-05-11 21:38:52 +00:00
describe 'creating from plain text' do
2010-05-11 21:38:52 +00:00
before(:each) do
ThemeAsset.any_instance.stubs(:site_id).returns('test')
@asset = Factory.build(:theme_asset, :site => Factory.build(:site))
2010-05-11 21:38:52 +00:00
@asset.performing_plain_text = true
@asset.slug = 'a file'
@asset.plain_text = "Lorem ipsum"
end
2010-05-11 21:38:52 +00:00
it 'should handle stylesheet' do
@asset.content_type = 'stylesheet'
@asset.valid?.should be_true
@asset.stylesheet?.should be_true
@asset.source.should_not be_nil
end
2010-05-11 21:38:52 +00:00
it 'should handle javascript' do
@asset.content_type = 'javascript'
@asset.valid?.should be_true
@asset.javascript?.should be_true
@asset.source.should_not be_nil
end
context 'shortcut urls' do
before(:each) do
@image = Factory.build(:theme_asset, :source => FixturedAsset.open('5k.png'))
@image.source.stubs(:url).returns('5k.png')
@asset.stubs(:stylesheet?).returns(true)
@asset.site.theme_assets.stubs(:where).returns([@image])
@asset.plain_text = 'body { background-image: url("/theme/images/5k.png"); } h1 { background-image: url("/images/5k.png"); }'
@asset.store_plain_text
end
it 'replaces shortcut url if present' do
@asset.plain_text.should == 'body { background-image: url("/theme/images/5k.png"); } h1 { background-image: url("/images/5k.png"); }'
@asset.source.read.should == 'body { background-image: url("5k.png"); } h1 { background-image: url("/images/5k.png"); }'
end
end
2010-05-11 21:38:52 +00:00
end
end