2010-11-08 17:42:14 +00:00
|
|
|
# coding: utf-8
|
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
describe ThemeAsset do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
describe 'attaching a file' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
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-07-23 20:09:54 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
describe 'file is a picture' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
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-07-23 20:09:54 +00:00
|
|
|
|
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-07-23 20:09:54 +00:00
|
|
|
|
2010-10-12 15:26:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'local path and folder' do
|
|
|
|
|
|
|
|
it 'should set the local path based on the content type' do
|
|
|
|
@asset.source = FixturedAsset.open('5k.png')
|
|
|
|
@asset.save
|
|
|
|
@asset.local_path.should == 'images/5k.png'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should set the local path based on the folder' do
|
|
|
|
@asset.folder = 'trash'
|
|
|
|
@asset.source = FixturedAsset.open('5k.png')
|
|
|
|
@asset.save
|
|
|
|
@asset.local_path.should == 'images/trash/5k.png'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should set sanitize the local path' do
|
|
|
|
@asset.folder = '/images/à la poubelle'
|
2010-05-11 21:38:52 +00:00
|
|
|
@asset.source = FixturedAsset.open('5k.png')
|
|
|
|
@asset.save
|
2010-10-12 15:26:05 +00:00
|
|
|
@asset.local_path.should == 'images/a_la_poubelle/5k.png'
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-02-04 09:39:23 +00:00
|
|
|
describe '#validation' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-02-04 09:39:23 +00:00
|
|
|
it 'does not accept text file' do
|
2010-05-11 21:38:52 +00:00
|
|
|
@asset.source = FixturedAsset.open('wrong.txt')
|
|
|
|
@asset.valid?.should be_false
|
|
|
|
@asset.errors[:source].should_not be_blank
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-02-04 09:39:23 +00:00
|
|
|
it 'is not valid if another file with the same path exists' do
|
|
|
|
@asset.source = FixturedAsset.open('5k.png')
|
|
|
|
@asset.save!
|
|
|
|
|
|
|
|
another_asset = Factory.build(:theme_asset, :site => @asset.site)
|
|
|
|
another_asset.source = FixturedAsset.open('5k.png')
|
|
|
|
another_asset.valid?.should be_false
|
|
|
|
another_asset.errors[:local_path].should_not be_blank
|
|
|
|
end
|
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
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-07-23 20:09:54 +00:00
|
|
|
|
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-07-23 20:09:54 +00:00
|
|
|
|
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-07-23 20:09:54 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
describe 'creating from plain text' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
before(:each) do
|
|
|
|
ThemeAsset.any_instance.stubs(:site_id).returns('test')
|
2010-10-12 15:26:05 +00:00
|
|
|
@asset = Factory.build(:theme_asset, {
|
|
|
|
:site => Factory.build(:site),
|
|
|
|
:plain_text_name => 'test',
|
|
|
|
:plain_text => 'Lorem ipsum',
|
|
|
|
:performing_plain_text => true
|
|
|
|
})
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
it 'should handle stylesheet' do
|
2011-06-27 15:27:07 +00:00
|
|
|
@asset.plain_text_type = 'stylesheet'
|
2010-05-11 21:38:52 +00:00
|
|
|
@asset.valid?.should be_true
|
|
|
|
@asset.stylesheet?.should be_true
|
|
|
|
@asset.source.should_not be_nil
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
it 'should handle javascript' do
|
2011-06-27 15:27:07 +00:00
|
|
|
@asset.plain_text_type = 'javascript'
|
2010-05-11 21:38:52 +00:00
|
|
|
@asset.valid?.should be_true
|
|
|
|
@asset.javascript?.should be_true
|
|
|
|
@asset.source.should_not be_nil
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-11 21:38:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|