radiant-clipped-extension-add-group 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +184 -0
- data/Rakefile +109 -0
- data/app/controllers/admin/assets_controller.rb +66 -0
- data/app/controllers/admin/page_attachments_controller.rb +18 -0
- data/app/helpers/admin/assets_helper.rb +16 -0
- data/app/helpers/admin/page_attachments_helper.rb +2 -0
- data/app/models/asset.rb +237 -0
- data/app/models/asset_type.rb +241 -0
- data/app/models/old_page_attachment.rb +26 -0
- data/app/models/page_attachment.rb +20 -0
- data/app/views/admin/assets/_asset.html.haml +12 -0
- data/app/views/admin/assets/_asset_table.html.haml +33 -0
- data/app/views/admin/assets/_errors.html.haml +3 -0
- data/app/views/admin/assets/_form.html.haml +25 -0
- data/app/views/admin/assets/_page_assets.html.haml +12 -0
- data/app/views/admin/assets/_search.html.haml +17 -0
- data/app/views/admin/assets/_search_results.html.haml +17 -0
- data/app/views/admin/assets/edit.html.haml +41 -0
- data/app/views/admin/assets/index.html.haml +19 -0
- data/app/views/admin/assets/new.html.haml +24 -0
- data/app/views/admin/assets/refresh.html.haml +14 -0
- data/app/views/admin/assets/remove.html.haml +16 -0
- data/app/views/admin/configuration/_clipped_edit.html.haml +8 -0
- data/app/views/admin/configuration/_clipped_show.html.haml +12 -0
- data/app/views/admin/page_attachments/_attachment.html.haml +25 -0
- data/app/views/admin/page_parts/_page_part.html.haml +21 -0
- data/app/views/admin/pages/_asset_popups.html.haml +42 -0
- data/app/views/admin/pages/_assets.html.haml +11 -0
- data/app/views/admin/removed/_assets_bucket.html.haml +8 -0
- data/app/views/admin/removed/_assets_container.html.haml +58 -0
- data/app/views/admin/removed/_bucket.html.haml +11 -0
- data/app/views/admin/removed/_bucket_asset.html.haml +9 -0
- data/app/views/admin/removed/_show_bucket_link.html.haml +4 -0
- data/app/views/admin/removed/_upload_to_page.html.haml +12 -0
- data/app/views/admin/removed/bucket/_iframe.html.haml +1 -0
- data/artwork/icons.png +0 -0
- data/clipped_extension.rb +52 -0
- data/config/initializers/interpolation.rb +6 -0
- data/config/initializers/processors.rb +43 -0
- data/config/initializers/radiant_config.rb +65 -0
- data/config/locales/de.yml +109 -0
- data/config/locales/en.yml +110 -0
- data/config/locales/nl.yml +107 -0
- data/config/locales/ru.yml +110 -0
- data/config/routes.rb +8 -0
- data/cucumber.yml +1 -0
- data/db/migrate/001_create_assets.rb +12 -0
- data/db/migrate/002_create_paperclip_attributes.rb +13 -0
- data/db/migrate/003_create_user_observer.rb +13 -0
- data/db/migrate/004_create_page_attachments.rb +19 -0
- data/db/migrate/005_rename_users.rb +13 -0
- data/db/migrate/20110513205050_asset_uuid.rb +11 -0
- data/db/migrate/20110606111250_update_configuration.rb +34 -0
- data/db/migrate/20110609101438_dimensions.rb +13 -0
- data/db/migrate/20121024064452_add_group_to_assets.rb +9 -0
- data/features/support/env.rb +11 -0
- data/features/support/paths.rb +22 -0
- data/lib/asset_tags.rb +350 -0
- data/lib/clipped_admin_ui.rb +32 -0
- data/lib/cloud.rb +41 -0
- data/lib/generators/templates/clipped_config.rb +53 -0
- data/lib/page_asset_associations.rb +13 -0
- data/lib/paperclip/frame_grab.rb +73 -0
- data/lib/paperclip/geometry_transformation.rb +80 -0
- data/lib/radiant-clipped-extension.rb +8 -0
- data/lib/tasks/clipped_extension_tasks.rake +124 -0
- data/lib/tasks/paperclip_tasks.rake +79 -0
- data/public/flash/ZeroClipboard.swf +0 -0
- data/public/images/admin/assets/add.png +0 -0
- data/public/images/admin/assets/archive_icon.png +0 -0
- data/public/images/admin/assets/audio_icon.png +0 -0
- data/public/images/admin/assets/audio_thumbnail.png +0 -0
- data/public/images/admin/assets/c_icon.png +0 -0
- data/public/images/admin/assets/copy.png +0 -0
- data/public/images/admin/assets/css_icon.png +0 -0
- data/public/images/admin/assets/database_icon.png +0 -0
- data/public/images/admin/assets/delete.png +0 -0
- data/public/images/admin/assets/document_icon.png +0 -0
- data/public/images/admin/assets/document_thumbnail.png +0 -0
- data/public/images/admin/assets/flash_icon.png +0 -0
- data/public/images/admin/assets/flash_thumbnail.png +0 -0
- data/public/images/admin/assets/font_icon.png +0 -0
- data/public/images/admin/assets/gzip_icon.png +0 -0
- data/public/images/admin/assets/html_icon.png +0 -0
- data/public/images/admin/assets/image_icon.png +0 -0
- data/public/images/admin/assets/image_thumbnail.png +0 -0
- data/public/images/admin/assets/java_icon.png +0 -0
- data/public/images/admin/assets/page_edit.png +0 -0
- data/public/images/admin/assets/perl_icon.png +0 -0
- data/public/images/admin/assets/php_icon.png +0 -0
- data/public/images/admin/assets/presentation_icon.png +0 -0
- data/public/images/admin/assets/python_icon.png +0 -0
- data/public/images/admin/assets/reorder_assets.png +0 -0
- data/public/images/admin/assets/ruby_icon.png +0 -0
- data/public/images/admin/assets/script_icon.png +0 -0
- data/public/images/admin/assets/spreadsheet_icon.png +0 -0
- data/public/images/admin/assets/tar_icon.png +0 -0
- data/public/images/admin/assets/unknown_icon.png +0 -0
- data/public/images/admin/assets/unknown_thumbnail.png +0 -0
- data/public/images/admin/assets/video_icon.png +0 -0
- data/public/images/admin/assets/video_thumbnail.png +0 -0
- data/public/images/admin/assets/xml_icon.png +0 -0
- data/public/images/admin/assets/zip_icon.png +0 -0
- data/public/javascripts/admin/assets.js +297 -0
- data/public/stylesheets/sass/admin/assets.sass +224 -0
- data/radiant-clipped-extension.gemspec +29 -0
- data/spec/ci/before_script +23 -0
- data/spec/ci/script +2 -0
- data/spec/controllers/admin/assets_controller_spec.rb +50 -0
- data/spec/controllers/admin/page_attachments_controller_spec.rb +50 -0
- data/spec/datasets/assets_dataset.rb +36 -0
- data/spec/fixtures/5k.png +0 -0
- data/spec/fixtures/test.flv +0 -0
- data/spec/lib/asset_tags_spec.rb +107 -0
- data/spec/lib/frame_grab_spec.rb +17 -0
- data/spec/lib/geometry_transformation_spec.rb +63 -0
- data/spec/models/asset_spec.rb +72 -0
- data/spec/models/asset_type_spec.rb +70 -0
- data/spec/models/post_processing_spec.rb +62 -0
- data/spec/spec.opts +7 -0
- data/spec/spec_helper.rb +36 -0
- data/wireframes/edit-page-assets-2.bmml +453 -0
- data/wireframes/edit-page-assets-2.png +0 -0
- data/wireframes/edit-page-assets-3.bmml +454 -0
- data/wireframes/edit-page-assets-3.png +0 -0
- data/wireframes/edit-page-assets.bmml +433 -0
- data/wireframes/edit-page-assets.png +0 -0
- data/wireframes/edit-page.bmml +174 -0
- data/wireframes/edit-page.png +0 -0
- metadata +281 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "radiant-clipped-extension"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "radiant-clipped-extension-add-group"
|
7
|
+
s.version = RadiantClippedExtension::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = RadiantClippedExtension::AUTHORS
|
10
|
+
s.email = RadiantClippedExtension::EMAIL
|
11
|
+
s.homepage = RadiantClippedExtension::URL
|
12
|
+
s.summary = RadiantClippedExtension::SUMMARY
|
13
|
+
s.description = RadiantClippedExtension::DESCRIPTION
|
14
|
+
|
15
|
+
s.add_dependency "acts_as_list", "0.1.4"
|
16
|
+
s.add_dependency "paperclip", "~> 2.7.0"
|
17
|
+
s.add_dependency "uuidtools", "~> 2.1.2"
|
18
|
+
s.add_dependency "cocaine", "~> 0.3.2"
|
19
|
+
|
20
|
+
ignores = if File.exist?('.gitignore')
|
21
|
+
File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
|
22
|
+
else
|
23
|
+
[]
|
24
|
+
end
|
25
|
+
s.files = Dir['**/*'] - ignores
|
26
|
+
s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
|
27
|
+
# s.executables = Dir['bin/*'] - ignores
|
28
|
+
s.require_paths = ["lib"]
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
cd ~
|
2
|
+
git clone git://github.com/radiant/radiant.git
|
3
|
+
cd ~/radiant
|
4
|
+
if [[ $RADIANT_VERSION != "master" ]]
|
5
|
+
then
|
6
|
+
git checkout -b $RADIANT_VERSION $RADIANT_VERSION
|
7
|
+
fi
|
8
|
+
cp -r ~/builds/*/radiant-clipped-extension vendor/extensions/clipped
|
9
|
+
gem install bundler --pre
|
10
|
+
echo 'gem "radiant-clipped-extension", :path => "vendor/extensions/clipped"' >> Gemfile
|
11
|
+
bundle install
|
12
|
+
|
13
|
+
case $DB in
|
14
|
+
"mysql" )
|
15
|
+
mysql -e 'create database radiant_test;'
|
16
|
+
cp spec/ci/database.mysql.yml config/database.yml;;
|
17
|
+
"postgres" )
|
18
|
+
psql -c 'create database radiant_test;' -U postgres
|
19
|
+
cp spec/ci/database.postgresql.yml config/database.yml;;
|
20
|
+
esac
|
21
|
+
|
22
|
+
bundle exec rake db:migrate
|
23
|
+
bundle exec rake db:migrate:extensions
|
data/spec/ci/script
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Admin::AssetsController do
|
4
|
+
dataset :users, :assets
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
ActionController::Routing::Routes.reload
|
8
|
+
login_as :designer
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be a ResourceController" do
|
12
|
+
controller.should be_kind_of(Admin::ResourceController)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should handle Assets" do
|
16
|
+
controller.class.model_class.should == Asset
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "index" do
|
20
|
+
describe "before filtration" do
|
21
|
+
before do
|
22
|
+
get :index
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should render the index view" do
|
26
|
+
response.should be_success
|
27
|
+
response.should render_template('index')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "on ajax filtration" do
|
32
|
+
before do
|
33
|
+
xml_http_request :get, :index, :filter => ['video']
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should render the table partial" do
|
37
|
+
response.body.should_not have_text('<head>')
|
38
|
+
response.content_type.should == 'text/javascript'
|
39
|
+
response.should_not render_template('index')
|
40
|
+
response.should render_template('admin/assets/_asset_table')
|
41
|
+
assigns(:assets).should include(assets(:video))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Admin::PageAttachmentsController do
|
4
|
+
dataset :users, :home_page, :assets
|
5
|
+
integrate_views
|
6
|
+
|
7
|
+
it "should be a ResourceController" do
|
8
|
+
controller.should be_kind_of(Admin::ResourceController)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should handle PageAttachments" do
|
12
|
+
controller.class.model_class.should == PageAttachment
|
13
|
+
controller.send(:model_symbol).should == :page_attachment
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "on call to new" do
|
17
|
+
before :each do
|
18
|
+
login_as :existing
|
19
|
+
@asset = assets(:video)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "with valid asset id" do
|
23
|
+
it "should return a nested form for asset-attachment" do
|
24
|
+
xhr :get, :new, :page_id => page_id(:home), :asset_id => @asset.id
|
25
|
+
response.should be_success
|
26
|
+
response.should render_template('admin/page_attachments/_attachment')
|
27
|
+
response.body.should =~ /attachment_#{@asset.uuid}/
|
28
|
+
response.body.should =~ /page_page_attachments_attributes_#{@asset.uuid}/
|
29
|
+
response.body.should =~ /<input class="attacher"/
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "without asset id" do
|
34
|
+
it "should respond blankly" do
|
35
|
+
get :new, :format => :js
|
36
|
+
response.should be_success
|
37
|
+
response.body.should be_blank
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "with invalid asset id" do
|
42
|
+
it "should respond blankly" do
|
43
|
+
get :new, :asset_id => 'foo', :format => :js
|
44
|
+
response.should be_success
|
45
|
+
response.body.should be_blank
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class AssetsDataset < Dataset::Base
|
2
|
+
uses :home_page
|
3
|
+
|
4
|
+
def load
|
5
|
+
create_page "pictured", :slug => 'pictured' do
|
6
|
+
create_asset "test1", :caption => "testing", :position => 1
|
7
|
+
create_asset "test2", :caption => "also testing", :position => 2
|
8
|
+
end
|
9
|
+
create_asset "video", :asset_content_type => 'video/mpeg', :asset_file_name => 'asset.mpg'
|
10
|
+
create_asset "audio", :asset_content_type => 'audio/mp3', :asset_file_name => 'asset.mp3'
|
11
|
+
create_asset "document", :asset_content_type => 'application/msword', :asset_file_name => 'asset.doc'
|
12
|
+
end
|
13
|
+
|
14
|
+
helpers do
|
15
|
+
def create_asset(name, attributes={})
|
16
|
+
pos = attributes.delete(:position)
|
17
|
+
create_record :asset, name.symbolize, {
|
18
|
+
:title => name,
|
19
|
+
:asset_file_name => 'asset.jpg',
|
20
|
+
:asset_content_type => 'image/jpeg',
|
21
|
+
:asset_file_size => '46248',
|
22
|
+
:original_height => 200,
|
23
|
+
:original_width => 400,
|
24
|
+
:uuid => UUIDTools::UUID.timestamp_create.to_s
|
25
|
+
}.merge(attributes)
|
26
|
+
if @current_page_id
|
27
|
+
create_record :page_attachment, "#{name}_attachment".symbolize, {
|
28
|
+
:page_id => @current_page_id,
|
29
|
+
:asset_id => asset_id(name.symbolize),
|
30
|
+
:position => pos
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe AssetTags do
|
4
|
+
dataset :assets
|
5
|
+
let(:page) { pages(:pictured) }
|
6
|
+
let(:asset) { assets(:test1) }
|
7
|
+
|
8
|
+
context "Asset tags" do
|
9
|
+
%w{width height caption asset_file_name asset_content_type asset_file_size id filename image flash url link extension page:title page:url}.each do |name|
|
10
|
+
it "should have the new singular 'asset:#{name}' tag and method" do
|
11
|
+
page.tags.include?("asset:#{name}").should be_true
|
12
|
+
page.respond_to?("tag:asset:#{name}".to_sym).should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have the old plural 'assets:#{name}' tag and method" do
|
16
|
+
page.tags.include?("assets:#{name}").should be_true
|
17
|
+
page.respond_to?("tag:assets:#{name}".to_sym).should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should deprecate the old plural 'assets:#{name}' tag" do
|
21
|
+
ActiveSupport::Deprecation.should_receive(:warn).at_least(:once)
|
22
|
+
page.should render("<r:assets:first><r:assets:#{name} /></r:assets:first>")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "rendering tag" do
|
28
|
+
before do
|
29
|
+
Radiant.config['assets.create_image_thumbnails?'] = true
|
30
|
+
Radiant.config['assets.thumbnails.image'] = 'normal:size=640x640>|small:size=320x320>'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "assets:each" do
|
34
|
+
page.should render('<r:assets:each><r:asset:id />,</r:assets:each>').as( "#{asset_id(:test1)},#{asset_id(:test2)}," )
|
35
|
+
end
|
36
|
+
|
37
|
+
it "assets:first" do
|
38
|
+
page.should render('<r:assets:first><r:asset:id /></r:assets:first>').as( asset.id.to_s )
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should retrieve an asset by name" do
|
42
|
+
page.should render('<r:asset:id name="video" />').as( "#{asset_id(:video)}" )
|
43
|
+
end
|
44
|
+
|
45
|
+
it "asset:name" do
|
46
|
+
page.should render(%{<r:asset:name id="#{asset_id(:test1)}" />}).as( asset.title )
|
47
|
+
end
|
48
|
+
|
49
|
+
it "asset:filename" do
|
50
|
+
page.should render(%{<r:asset:filename id="#{asset_id(:test1)}" />}).as( asset.asset_file_name )
|
51
|
+
end
|
52
|
+
|
53
|
+
it "asset:url" do
|
54
|
+
page.should render(%{<r:asset:url id="#{asset_id(:test1)}" />}).as( asset.thumbnail )
|
55
|
+
page.should render(%{<r:asset:url size="icon" id="#{asset_id(:test1)}" />}).as( asset.thumbnail('icon') )
|
56
|
+
end
|
57
|
+
|
58
|
+
it "asset:link" do
|
59
|
+
page.should render(%{<r:asset:link id="#{asset_id(:test1)}" />}).as( %{<a href="#{asset.thumbnail}">#{asset.title}</a>} )
|
60
|
+
page.should render(%{<r:asset:link size="icon" id="#{asset_id(:test1)}" />}).as( %{<a href="#{asset.thumbnail('icon')}">#{asset.title}</a>} )
|
61
|
+
end
|
62
|
+
|
63
|
+
it "asset:image" do
|
64
|
+
page.should render(%{<r:asset:image id="#{asset_id(:test1)}" />}).as( %{<img src="#{asset.thumbnail}" alt="#{asset.title}" />} )
|
65
|
+
page.should render(%{<r:asset:image size="icon" id="#{asset_id(:test1)}" />}).as( %{<img src="#{asset.thumbnail('icon')}" alt="#{asset.title}" />} )
|
66
|
+
end
|
67
|
+
|
68
|
+
it "asset:caption" do
|
69
|
+
page.should render(%{<r:asset:caption id="#{asset_id(:test1)}" />}).as( asset.caption )
|
70
|
+
end
|
71
|
+
|
72
|
+
it "asset:top_padding" do
|
73
|
+
page.should render(%{<r:asset:top_padding id="#{asset_id(:test1)}" container="500" />}).as( "229" )
|
74
|
+
end
|
75
|
+
|
76
|
+
it "asset:top_padding for a specified style" do
|
77
|
+
page.should render(%{<r:asset:top_padding id="#{asset_id(:test1)}" container="500" size="thumbnail" />}).as( "200" )
|
78
|
+
end
|
79
|
+
|
80
|
+
it "asset:width" do
|
81
|
+
page.should render(%{<r:asset:width id="#{asset_id(:test1)}" />}).as( "400" )
|
82
|
+
page.should render(%{<r:asset:width id="#{asset_id(:test1)}" size="icon" />}).as( "42" )
|
83
|
+
end
|
84
|
+
|
85
|
+
it "asset:height" do
|
86
|
+
page.should render(%{<r:asset:height id="#{asset_id(:test1)}" container="500" />}).as( "200" )
|
87
|
+
page.should render(%{<r:asset:height id="#{asset_id(:test1)}" size="icon" />}).as( "42" )
|
88
|
+
end
|
89
|
+
|
90
|
+
it "asset:orientation" do
|
91
|
+
page.should render(%{<r:asset:orientation id="#{asset_id(:test1)}" />}).as( "horizontal" )
|
92
|
+
page.should render(%{<r:asset:orientation id="#{asset_id(:test1)}" size="icon" />}).as( "square" )
|
93
|
+
end
|
94
|
+
|
95
|
+
it "asset:aspect" do
|
96
|
+
page.should render(%{<r:asset:aspect id="#{asset_id(:test1)}" />}).as( 2.to_f.to_s )
|
97
|
+
page.should render(%{<r:asset:aspect id="#{asset_id(:test1)}" size="icon" />}).as( 1.to_f.to_s )
|
98
|
+
end
|
99
|
+
|
100
|
+
it "asset:if_image" do
|
101
|
+
page.should render(%{<r:asset:if_image name="test1">foo</r:asset:if_image>}).as( "foo" )
|
102
|
+
page.should render(%{<r:asset:if_image name="video">foo</r:asset:if_image>}).as( "" )
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Paperclip::FrameGrab do
|
4
|
+
dataset :assets
|
5
|
+
let(:file) { File.new(File.join( File.dirname(__FILE__), "..", "fixtures", "test.flv")) }
|
6
|
+
let(:asset) { assets(:video) }
|
7
|
+
|
8
|
+
if Radiant.config['assets.create_video_thumbnails?']
|
9
|
+
context "processing video attachment" do
|
10
|
+
it "should create png icon and thumbnail"
|
11
|
+
it "should create jpeg file at configured size"
|
12
|
+
it "should squish if configured size is specific"
|
13
|
+
it "should preserve aspect ratio if configured size is >"
|
14
|
+
it "should resize then crop if configured size is #"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Paperclip::Geometry do
|
4
|
+
let(:original) { Paperclip::Geometry.new(1200,600) }
|
5
|
+
let(:small) { Paperclip::Geometry.new(100, 50) }
|
6
|
+
let(:scaled) {Paperclip::Geometry.new(300, 150) }
|
7
|
+
let(:incomplete) { Paperclip::Geometry.parse("300x") }
|
8
|
+
let(:simple) { Paperclip::Geometry.parse("300x200") }
|
9
|
+
let(:cropper) { Paperclip::Geometry.parse("300x200#") }
|
10
|
+
let(:if_bigger) { Paperclip::Geometry.parse("300x200>") }
|
11
|
+
let(:if_smaller) { Paperclip::Geometry.parse("300x200<") }
|
12
|
+
let(:percentage) { Paperclip::Geometry.parse("25%") }
|
13
|
+
let(:area) { Paperclip::Geometry.parse("180000@") }
|
14
|
+
|
15
|
+
context "=~" do
|
16
|
+
it "should compare sizes" do
|
17
|
+
(original =~ small).should be_false
|
18
|
+
(original =~ Paperclip::Geometry.new(1200,600)).should be_true
|
19
|
+
end
|
20
|
+
it "should ignore modifiers" do
|
21
|
+
(simple =~ cropper).should be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context "==" do
|
25
|
+
it "should compare sizes and modifiers" do
|
26
|
+
(original == Paperclip::Geometry.new(1200,600)).should be_true
|
27
|
+
(simple == cropper).should be_false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "stripping modifier" do
|
32
|
+
it "should return the same geometry with no modifier" do
|
33
|
+
cropper.without_modifier.should == simple
|
34
|
+
if_bigger.without_modifier.should == simple
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "calculating thumbnail dimensions" do
|
39
|
+
it "should raise an exception if called on a partial geometry" do
|
40
|
+
lambda{incomplete * simple}.should raise_error(Paperclip::TransformationError)
|
41
|
+
end
|
42
|
+
it "should not raise an exception if called on a complete geometry" do
|
43
|
+
lambda{original * simple}.should_not raise_error
|
44
|
+
end
|
45
|
+
it "should calculate the result of applying another geometry" do
|
46
|
+
(original * simple).should == scaled
|
47
|
+
(original * cropper).should == cropper.without_modifier
|
48
|
+
(original * if_bigger).should == scaled
|
49
|
+
(original * if_smaller).should == original
|
50
|
+
(small * if_smaller).should == scaled
|
51
|
+
(small * cropper).should == cropper.without_modifier
|
52
|
+
(original * percentage).should == scaled
|
53
|
+
(original * area).should == scaled
|
54
|
+
end
|
55
|
+
it "should cope with a partial-geometry argument" do
|
56
|
+
(original * incomplete).should == scaled
|
57
|
+
end
|
58
|
+
it "should instantiate a non-geometry argument" do
|
59
|
+
(original * "300x200").should == scaled
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Asset do
|
4
|
+
|
5
|
+
def default_attributes
|
6
|
+
{
|
7
|
+
:asset_file_name => 'asset.jpg',
|
8
|
+
:asset_content_type => 'image/jpeg',
|
9
|
+
:asset_file_size => '46248'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
def new_asset(overrides={})
|
13
|
+
Asset.new default_attributes.merge(overrides)
|
14
|
+
end
|
15
|
+
def create_asset(overrides={})
|
16
|
+
Asset.create! default_attributes.merge(overrides)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should be valid when instantiated' do
|
20
|
+
new_asset.should be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should be valid when saved' do
|
24
|
+
create_asset.should be_valid
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#thumbnail' do
|
28
|
+
describe 'without argument' do
|
29
|
+
it 'should return paperclip asset url for image' do
|
30
|
+
image = new_asset :asset_content_type => 'image/jpeg'
|
31
|
+
image.stub! :asset => mock('asset', :url => '/y/z/e.jpg')
|
32
|
+
image.thumbnail.should == '/y/z/e.jpg'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return paperclip asset url for non-image' do
|
36
|
+
asset = new_asset :asset_content_type => 'application/pdf'
|
37
|
+
asset.stub! :asset => mock('asset', :url => '/y/z/e.pdf')
|
38
|
+
asset.thumbnail.should == '/y/z/e.pdf'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'with size=original' do
|
43
|
+
it 'should return paperclip asset url for image' do
|
44
|
+
image = new_asset :asset_content_type => 'image/jpeg'
|
45
|
+
image.stub! :asset => mock('asset', :url => '/y/z/e.jpg')
|
46
|
+
image.thumbnail('original').should == '/y/z/e.jpg'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return paperclip asset url for non-image' do
|
50
|
+
asset = new_asset :asset_content_type => 'application/pdf'
|
51
|
+
asset.stub! :asset => mock('asset', :url => '/y/z/e.pdf')
|
52
|
+
asset.thumbnail('original').should == '/y/z/e.pdf'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should return resized image for images when given size' do
|
57
|
+
image = new_asset :asset_content_type => 'image/jpeg'
|
58
|
+
image.stub! :asset => mock('asset')
|
59
|
+
image.stub! :has_style? => true
|
60
|
+
image.asset.stub!(:content_type).and_return('image/jpeg')
|
61
|
+
image.asset.stub!(:url).with(:thumbnail).and_return('/re/sized/image_thumbnail.jpg')
|
62
|
+
image.thumbnail('thumbnail').should == '/re/sized/image_thumbnail.jpg'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should return icon for non-image with a given size' do
|
66
|
+
document = new_asset :asset_content_type => 'application/msword', :asset_file_name => "document.doc"
|
67
|
+
document.thumbnail('icon').should == "/images/admin/assets/document_icon.png"
|
68
|
+
document.thumbnail('anything_but_icon').should == "/images/admin/assets/document_icon.png"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|