Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
40010c4d
Commit
40010c4d
authored
Mar 04, 2014
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert applicable hashes to 1.9 syntax
parent
1f3a7467
Show whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
900 additions
and
894 deletions
+900
-894
spec/paperclip/attachment_definitions_spec.rb
+3
-3
spec/paperclip/attachment_processing_spec.rb
+7
-7
spec/paperclip/attachment_spec.rb
+130
-127
spec/paperclip/geometry_detector_spec.rb
+2
-2
spec/paperclip/geometry_parser_spec.rb
+20
-20
spec/paperclip/geometry_spec.rb
+3
-3
spec/paperclip/integration_spec.rb
+66
-63
spec/paperclip/interpolations_spec.rb
+5
-5
spec/paperclip/io_adapters/attachment_adapter_spec.rb
+1
-1
spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb
+17
-17
spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb
+8
-8
spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb
+2
-2
spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb
+7
-7
spec/paperclip/paperclip_missing_attachment_styles_spec.rb
+18
-18
spec/paperclip/paperclip_spec.rb
+7
-7
spec/paperclip/schema_spec.rb
+4
-4
spec/paperclip/storage/filesystem_spec.rb
+2
-2
spec/paperclip/storage/fog_spec.rb
+65
-65
spec/paperclip/storage/s3_live_spec.rb
+35
-35
spec/paperclip/storage/s3_spec.rb
+261
-261
spec/paperclip/style_spec.rb
+54
-54
spec/paperclip/thumbnail_spec.rb
+24
-24
spec/paperclip/url_generator_spec.rb
+39
-39
spec/paperclip/validators/attachment_content_type_validator_spec.rb
+47
-47
spec/paperclip/validators/attachment_file_name_validator_spec.rb
+25
-25
spec/paperclip/validators/attachment_presence_validator_spec.rb
+3
-3
spec/paperclip/validators/attachment_size_validator_spec.rb
+28
-28
spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb
+1
-1
spec/paperclip/validators_spec.rb
+14
-14
spec/spec_helper.rb
+2
-2
No files found.
spec/paperclip/attachment_definitions_spec.rb
View file @
40010c4d
...
@@ -3,10 +3,10 @@ require 'spec_helper'
...
@@ -3,10 +3,10 @@ require 'spec_helper'
describe
"Attachment Definitions"
do
describe
"Attachment Definitions"
do
it
'returns all of the attachments on the class'
do
it
'returns all of the attachments on the class'
do
reset_class
"Dummy"
reset_class
"Dummy"
Dummy
.
has_attached_file
:avatar
,
{
:path
=>
"abc"
}
Dummy
.
has_attached_file
:avatar
,
{
path:
"abc"
}
Dummy
.
has_attached_file
:other_attachment
,
{
:url
=>
"123"
}
Dummy
.
has_attached_file
:other_attachment
,
{
url:
"123"
}
Dummy
.
do_not_validate_attachment_file_type
:avatar
Dummy
.
do_not_validate_attachment_file_type
:avatar
expected
=
{
:avatar
=>
{
:path
=>
"abc"
},
:other_attachment
=>
{
:url
=>
"123"
}}
expected
=
{
avatar:
{
path:
"abc"
},
other_attachment:
{
url:
"123"
}}
assert_equal
expected
,
Dummy
.
attachment_definitions
assert_equal
expected
,
Dummy
.
attachment_definitions
end
end
...
...
spec/paperclip/attachment_processing_spec.rb
View file @
40010c4d
...
@@ -9,7 +9,7 @@ describe 'Attachment Processing' do
...
@@ -9,7 +9,7 @@ describe 'Attachment Processing' do
it
'process attachments given a valid assignment'
do
it
'process attachments given a valid assignment'
do
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
"image/png"
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
"image/png"
instance
=
Dummy
.
new
instance
=
Dummy
.
new
attachment
=
instance
.
avatar
attachment
=
instance
.
avatar
attachment
.
expects
(
:post_process_styles
)
attachment
.
expects
(
:post_process_styles
)
...
@@ -19,7 +19,7 @@ describe 'Attachment Processing' do
...
@@ -19,7 +19,7 @@ describe 'Attachment Processing' do
it
'not process attachments given an invalid assignment with :not'
do
it
'not process attachments given an invalid assignment with :not'
do
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
Dummy
.
validates_attachment_content_type
:avatar
,
:not
=>
"image/png"
Dummy
.
validates_attachment_content_type
:avatar
,
not:
"image/png"
instance
=
Dummy
.
new
instance
=
Dummy
.
new
attachment
=
instance
.
avatar
attachment
=
instance
.
avatar
attachment
.
expects
(
:post_process_styles
).
never
attachment
.
expects
(
:post_process_styles
).
never
...
@@ -29,7 +29,7 @@ describe 'Attachment Processing' do
...
@@ -29,7 +29,7 @@ describe 'Attachment Processing' do
it
'not process attachments given an invalid assignment with :content_type'
do
it
'not process attachments given an invalid assignment with :content_type'
do
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
"image/tiff"
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
"image/tiff"
instance
=
Dummy
.
new
instance
=
Dummy
.
new
attachment
=
instance
.
avatar
attachment
=
instance
.
avatar
attachment
.
expects
(
:post_process_styles
).
never
attachment
.
expects
(
:post_process_styles
).
never
...
@@ -39,7 +39,7 @@ describe 'Attachment Processing' do
...
@@ -39,7 +39,7 @@ describe 'Attachment Processing' do
it
'when validation :if clause returns false, allow what would be an invalid assignment'
do
it
'when validation :if clause returns false, allow what would be an invalid assignment'
do
invalid_assignment
=
File
.
new
(
fixture_file
(
"5k.png"
))
invalid_assignment
=
File
.
new
(
fixture_file
(
"5k.png"
))
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
"image/tiff"
,
:if
=>
lambda
{
false
}
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
"image/tiff"
,
if:
lambda
{
false
}
instance
=
Dummy
.
new
instance
=
Dummy
.
new
attachment
=
instance
.
avatar
attachment
=
instance
.
avatar
attachment
.
expects
(
:post_process_styles
)
attachment
.
expects
(
:post_process_styles
)
...
@@ -51,7 +51,7 @@ describe 'Attachment Processing' do
...
@@ -51,7 +51,7 @@ describe 'Attachment Processing' do
context
'using validates_attachment'
do
context
'using validates_attachment'
do
it
'process attachments given a valid assignment'
do
it
'process attachments given a valid assignment'
do
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
Dummy
.
validates_attachment
:avatar
,
:content_type
=>
{
:content_type
=>
"image/png"
}
Dummy
.
validates_attachment
:avatar
,
content_type:
{
content_type:
"image/png"
}
instance
=
Dummy
.
new
instance
=
Dummy
.
new
attachment
=
instance
.
avatar
attachment
=
instance
.
avatar
attachment
.
expects
(
:post_process_styles
)
attachment
.
expects
(
:post_process_styles
)
...
@@ -61,7 +61,7 @@ describe 'Attachment Processing' do
...
@@ -61,7 +61,7 @@ describe 'Attachment Processing' do
it
'not process attachments given an invalid assignment with :not'
do
it
'not process attachments given an invalid assignment with :not'
do
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
Dummy
.
validates_attachment
:avatar
,
:content_type
=>
{
:not
=>
"image/png"
}
Dummy
.
validates_attachment
:avatar
,
content_type:
{
not:
"image/png"
}
instance
=
Dummy
.
new
instance
=
Dummy
.
new
attachment
=
instance
.
avatar
attachment
=
instance
.
avatar
attachment
.
expects
(
:post_process_styles
).
never
attachment
.
expects
(
:post_process_styles
).
never
...
@@ -71,7 +71,7 @@ describe 'Attachment Processing' do
...
@@ -71,7 +71,7 @@ describe 'Attachment Processing' do
it
'not process attachments given an invalid assignment with :content_type'
do
it
'not process attachments given an invalid assignment with :content_type'
do
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
Dummy
.
validates_attachment
:avatar
,
:content_type
=>
{
:content_type
=>
"image/tiff"
}
Dummy
.
validates_attachment
:avatar
,
content_type:
{
content_type:
"image/tiff"
}
instance
=
Dummy
.
new
instance
=
Dummy
.
new
attachment
=
instance
.
avatar
attachment
=
instance
.
avatar
attachment
.
expects
(
:post_process_styles
).
never
attachment
.
expects
(
:post_process_styles
).
never
...
...
spec/paperclip/attachment_spec.rb
View file @
40010c4d
...
@@ -20,7 +20,7 @@ describe Paperclip::Attachment do
...
@@ -20,7 +20,7 @@ describe Paperclip::Attachment do
it
"processes :original style first"
do
it
"processes :original style first"
do
file
=
File
.
new
(
fixture_file
(
"50x50.png"
),
'rb'
)
file
=
File
.
new
(
fixture_file
(
"50x50.png"
),
'rb'
)
rebuild_class
:styles
=>
{
:small
=>
'100x>'
,
:original
=>
'42x42#'
}
rebuild_class
styles:
{
small:
'100x>'
,
original:
'42x42#'
}
dummy
=
Dummy
.
new
dummy
=
Dummy
.
new
dummy
.
avatar
=
file
dummy
.
avatar
=
file
dummy
.
save
dummy
.
save
...
@@ -33,9 +33,12 @@ describe Paperclip::Attachment do
...
@@ -33,9 +33,12 @@ describe Paperclip::Attachment do
it
"not delete styles that don't get reprocessed"
do
it
"not delete styles that don't get reprocessed"
do
file
=
File
.
new
(
fixture_file
(
"50x50.png"
),
'rb'
)
file
=
File
.
new
(
fixture_file
(
"50x50.png"
),
'rb'
)
rebuild_class
:styles
=>
{
:small
=>
'100x>'
,
rebuild_class
styles:
{
:large
=>
'500x>'
,
small:
'100x>'
,
:original
=>
'42x42#'
}
large:
'500x>'
,
original:
'42x42#'
}
dummy
=
Dummy
.
new
dummy
=
Dummy
.
new
dummy
.
avatar
=
file
dummy
.
avatar
=
file
dummy
.
save
dummy
.
save
...
@@ -54,7 +57,7 @@ describe Paperclip::Attachment do
...
@@ -54,7 +57,7 @@ describe Paperclip::Attachment do
context
"having a not empty hash as a default option"
do
context
"having a not empty hash as a default option"
do
before
do
before
do
@old_default_options
=
Paperclip
::
Attachment
.
default_options
.
dup
@old_default_options
=
Paperclip
::
Attachment
.
default_options
.
dup
@new_default_options
=
{
:convert_options
=>
{
:all
=>
"-background white"
}
}
@new_default_options
=
{
convert_options:
{
all:
"-background white"
}
}
Paperclip
::
Attachment
.
default_options
.
merge!
(
@new_default_options
)
Paperclip
::
Attachment
.
default_options
.
merge!
(
@new_default_options
)
end
end
...
@@ -63,7 +66,7 @@ describe Paperclip::Attachment do
...
@@ -63,7 +66,7 @@ describe Paperclip::Attachment do
end
end
it
"deep merge when it is overridden"
do
it
"deep merge when it is overridden"
do
new_options
=
{
:convert_options
=>
{
:thumb
=>
"-thumbnailize"
}
}
new_options
=
{
convert_options:
{
thumb:
"-thumbnailize"
}
}
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
new_options
)
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
new_options
)
expect
(
Paperclip
::
Attachment
.
default_options
.
deep_merge
(
new_options
)).
to
eq
attachment
.
instance_variable_get
(
"@options"
)
expect
(
Paperclip
::
Attachment
.
default_options
.
deep_merge
(
new_options
)).
to
eq
attachment
.
instance_variable_get
(
"@options"
)
...
@@ -72,115 +75,115 @@ describe Paperclip::Attachment do
...
@@ -72,115 +75,115 @@ describe Paperclip::Attachment do
it
"handles a boolean second argument to #url"
do
it
"handles a boolean second argument to #url"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:url_generator
=>
mock_url_generator_builder
)
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
url_generator:
mock_url_generator_builder
)
attachment
.
url
(
:style_name
,
true
)
attachment
.
url
(
:style_name
,
true
)
expect
(
mock_url_generator_builder
.
has_generated_url_with_options?
(
:timestamp
=>
true
,
:escape
=>
true
)).
to
be_true
expect
(
mock_url_generator_builder
.
has_generated_url_with_options?
(
timestamp:
true
,
escape:
true
)).
to
be_true
attachment
.
url
(
:style_name
,
false
)
attachment
.
url
(
:style_name
,
false
)
expect
(
mock_url_generator_builder
.
has_generated_url_with_options?
(
:timestamp
=>
false
,
:escape
=>
true
)).
to
be_true
expect
(
mock_url_generator_builder
.
has_generated_url_with_options?
(
timestamp:
false
,
escape:
true
)).
to
be_true
end
end
it
"pass the style and options through to the URL generator on #url"
do
it
"pass the style and options through to the URL generator on #url"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:url_generator
=>
mock_url_generator_builder
)
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
url_generator:
mock_url_generator_builder
)
attachment
.
url
(
:style_name
,
:options
=>
:values
)
attachment
.
url
(
:style_name
,
options:
:values
)
expect
(
mock_url_generator_builder
.
has_generated_url_with_options?
(
:options
=>
:values
)).
to
be_true
expect
(
mock_url_generator_builder
.
has_generated_url_with_options?
(
options:
:values
)).
to
be_true
end
end
it
"pass default options through when #url is given one argument"
do
it
"pass default options through when #url is given one argument"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:instance
,
:url_generator
=>
mock_url_generator_builder
,
url_generator:
mock_url_generator_builder
,
:use_timestamp
=>
true
)
use_timestamp:
true
)
attachment
.
url
(
:style_name
)
attachment
.
url
(
:style_name
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
:escape
=>
true
,
:timestamp
=>
true
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
escape:
true
,
timestamp:
true
)
end
end
it
"pass default style and options through when #url is given no arguments"
do
it
"pass default style and options through when #url is given no arguments"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:instance
,
:default_style
=>
'default style'
,
default_style:
'default style'
,
:url_generator
=>
mock_url_generator_builder
,
url_generator:
mock_url_generator_builder
,
:use_timestamp
=>
true
)
use_timestamp:
true
)
attachment
.
url
attachment
.
url
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
:escape
=>
true
,
:timestamp
=>
true
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
escape:
true
,
timestamp:
true
)
assert
mock_url_generator_builder
.
has_generated_url_with_style_name?
(
'default style'
)
assert
mock_url_generator_builder
.
has_generated_url_with_style_name?
(
'default style'
)
end
end
it
"pass the option
:timestamp =>
true if :use_timestamp is true and :timestamp is not passed"
do
it
"pass the option
timestamp:
true if :use_timestamp is true and :timestamp is not passed"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:instance
,
:url_generator
=>
mock_url_generator_builder
,
url_generator:
mock_url_generator_builder
,
:use_timestamp
=>
true
)
use_timestamp:
true
)
attachment
.
url
(
:style_name
)
attachment
.
url
(
:style_name
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
:escape
=>
true
,
:timestamp
=>
true
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
escape:
true
,
timestamp:
true
)
end
end
it
"pass the option
:timestamp =>
false if :use_timestamp is false and :timestamp is not passed"
do
it
"pass the option
timestamp:
false if :use_timestamp is false and :timestamp is not passed"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:instance
,
:url_generator
=>
mock_url_generator_builder
,
url_generator:
mock_url_generator_builder
,
:use_timestamp
=>
false
)
use_timestamp:
false
)
attachment
.
url
(
:style_name
)
attachment
.
url
(
:style_name
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
:escape
=>
true
,
:timestamp
=>
false
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
escape:
true
,
timestamp:
false
)
end
end
it
"not change the :timestamp if :timestamp is passed"
do
it
"not change the :timestamp if :timestamp is passed"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:instance
,
:url_generator
=>
mock_url_generator_builder
,
url_generator:
mock_url_generator_builder
,
:use_timestamp
=>
false
)
use_timestamp:
false
)
attachment
.
url
(
:style_name
,
:timestamp
=>
true
)
attachment
.
url
(
:style_name
,
timestamp:
true
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
:escape
=>
true
,
:timestamp
=>
true
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
escape:
true
,
timestamp:
true
)
end
end
it
"render JSON as default style"
do
it
"render JSON as default style"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:instance
,
:default_style
=>
'default style'
,
default_style:
'default style'
,
:url_generator
=>
mock_url_generator_builder
)
url_generator:
mock_url_generator_builder
)
attachment
.
as_json
attachment
.
as_json
assert
mock_url_generator_builder
.
has_generated_url_with_style_name?
(
'default style'
)
assert
mock_url_generator_builder
.
has_generated_url_with_style_name?
(
'default style'
)
end
end
it
"pass the option
:escape =>
true if :escape_url is true and :escape is not passed"
do
it
"pass the option
escape:
true if :escape_url is true and :escape is not passed"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:instance
,
:url_generator
=>
mock_url_generator_builder
,
url_generator:
mock_url_generator_builder
,
:escape_url
=>
true
)
escape_url:
true
)
attachment
.
url
(
:style_name
)
attachment
.
url
(
:style_name
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
:escape
=>
true
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
escape:
true
)
end
end
it
"pass the option
:escape =>
false if :escape_url is false and :escape is not passed"
do
it
"pass the option
escape:
false if :escape_url is false and :escape is not passed"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:instance
,
:url_generator
=>
mock_url_generator_builder
,
url_generator:
mock_url_generator_builder
,
:escape_url
=>
false
)
escape_url:
false
)
attachment
.
url
(
:style_name
)
attachment
.
url
(
:style_name
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
:escape
=>
false
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
escape:
false
)
end
end
it
"return the path based on the url by default"
do
it
"return the path based on the url by default"
do
@attachment
=
attachment
:url
=>
"/:class/:id/:basename"
@attachment
=
attachment
url:
"/:class/:id/:basename"
@model
=
@attachment
.
instance
@model
=
@attachment
.
instance
@model
.
id
=
1234
@model
.
id
=
1234
@model
.
avatar_file_name
=
"fake.jpg"
@model
.
avatar_file_name
=
"fake.jpg"
...
@@ -214,7 +217,7 @@ describe Paperclip::Attachment do
...
@@ -214,7 +217,7 @@ describe Paperclip::Attachment do
expected_string
=
%({"dummy":#{expected_string}})
expected_string
=
%({"dummy":#{expected_string}})
end
end
# active_model pre-3.2 checks only by calling any? on it, thus it doesn't work if it is empty
# active_model pre-3.2 checks only by calling any? on it, thus it doesn't work if it is empty
assert_equal
expected_string
,
dummy
.
to_json
(
:only
=>
[
:dummy_key_for_old_active_model
],
:methods
=>
[
:avatar
])
assert_equal
expected_string
,
dummy
.
to_json
(
only:
[
:dummy_key_for_old_active_model
],
methods:
[
:avatar
])
end
end
context
"Attachment default_options"
do
context
"Attachment default_options"
do
...
@@ -222,9 +225,9 @@ describe Paperclip::Attachment do
...
@@ -222,9 +225,9 @@ describe Paperclip::Attachment do
rebuild_model
rebuild_model
@old_default_options
=
Paperclip
::
Attachment
.
default_options
.
dup
@old_default_options
=
Paperclip
::
Attachment
.
default_options
.
dup
@new_default_options
=
@old_default_options
.
merge
({
@new_default_options
=
@old_default_options
.
merge
({
:path
=>
"argle/bargle"
,
path:
"argle/bargle"
,
:url
=>
"fooferon"
,
url:
"fooferon"
,
:default_url
=>
"not here.png"
default_url:
"not here.png"
})
})
end
end
...
@@ -284,7 +287,7 @@ describe Paperclip::Attachment do
...
@@ -284,7 +287,7 @@ describe Paperclip::Attachment do
context
"An attachment with similarly named interpolations"
do
context
"An attachment with similarly named interpolations"
do
before
do
before
do
rebuild_model
:path
=>
":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
rebuild_model
path:
":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:id
).
returns
(
1024
)
@dummy
.
stubs
(
:id
).
returns
(
1024
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
...
@@ -309,7 +312,7 @@ describe Paperclip::Attachment do
...
@@ -309,7 +312,7 @@ describe Paperclip::Attachment do
context
"using default time zone"
do
context
"using default time zone"
do
before
do
before
do
rebuild_model
:path
=>
":timestamp"
,
:use_default_time_zone
=>
true
rebuild_model
path:
":timestamp"
,
use_default_time_zone:
true
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
end
end
...
@@ -321,7 +324,7 @@ describe Paperclip::Attachment do
...
@@ -321,7 +324,7 @@ describe Paperclip::Attachment do
context
"using per-thread time zone"
do
context
"using per-thread time zone"
do
before
do
before
do
rebuild_model
:path
=>
":timestamp"
,
:use_default_time_zone
=>
false
rebuild_model
path:
":timestamp"
,
use_default_time_zone:
false
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
end
end
...
@@ -338,7 +341,7 @@ describe Paperclip::Attachment do
...
@@ -338,7 +341,7 @@ describe Paperclip::Attachment do
end
end
it
"raise if no secret is provided"
do
it
"raise if no secret is provided"
do
rebuild_model
:path
=>
":hash"
rebuild_model
path:
":hash"
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
@attachment
.
assign
@file
@attachment
.
assign
@file
...
@@ -349,9 +352,9 @@ describe Paperclip::Attachment do
...
@@ -349,9 +352,9 @@ describe Paperclip::Attachment do
context
"when secret is set"
do
context
"when secret is set"
do
before
do
before
do
rebuild_model
:path
=>
":hash"
,
rebuild_model
path:
":hash"
,
:hash_secret
=>
"w00t"
,
hash_secret:
"w00t"
,
:hash_data
=>
":class/:attachment/:style/:filename"
hash_data:
":class/:attachment/:style/:filename"
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
@attachment
.
assign
@file
@attachment
.
assign
@file
end
end
...
@@ -374,7 +377,7 @@ describe Paperclip::Attachment do
...
@@ -374,7 +377,7 @@ describe Paperclip::Attachment do
before
do
before
do
@rails_env
=
"blah"
@rails_env
=
"blah"
@id
=
1024
@id
=
1024
rebuild_model
:path
=>
":rails_env/:id.png"
rebuild_model
path:
":rails_env/:id.png"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:id
).
returns
(
@id
)
@dummy
.
stubs
(
:id
).
returns
(
@id
)
@file
=
StringIO
.
new
(
"."
)
@file
=
StringIO
.
new
(
"."
)
...
@@ -389,9 +392,9 @@ describe Paperclip::Attachment do
...
@@ -389,9 +392,9 @@ describe Paperclip::Attachment do
context
"An attachment with a default style and an extension interpolation"
do
context
"An attachment with a default style and an extension interpolation"
do
before
do
before
do
rebuild_model
:path
=>
":basename.:extension"
,
rebuild_model
path:
":basename.:extension"
,
:styles
=>
{
:default
=>
[
"100x100"
,
:jpg
]
},
styles:
{
default:
[
"100x100"
,
:jpg
]
},
:default_style
=>
:default
default_style:
:default
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
@file
=
File
.
open
(
fixture_file
(
"5k.png"
))
@file
=
File
.
open
(
fixture_file
(
"5k.png"
))
@file
.
stubs
(
:original_filename
).
returns
(
"file.png"
)
@file
.
stubs
(
:original_filename
).
returns
(
"file.png"
)
...
@@ -404,13 +407,13 @@ describe Paperclip::Attachment do
...
@@ -404,13 +407,13 @@ describe Paperclip::Attachment do
context
"An attachment with :convert_options"
do
context
"An attachment with :convert_options"
do
before
do
before
do
rebuild_model
:styles
=>
{
rebuild_model
styles:
{
:thumb
=>
"100x100"
,
thumb:
"100x100"
,
:large
=>
"400x400"
large:
"400x400"
},
},
:convert_options
=>
{
convert_options:
{
:all
=>
"-do_stuff"
,
all:
"-do_stuff"
,
:thumb
=>
"-thumbnailize"
thumb:
"-thumbnailize"
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
@dummy
.
avatar
...
@@ -427,13 +430,13 @@ describe Paperclip::Attachment do
...
@@ -427,13 +430,13 @@ describe Paperclip::Attachment do
context
"An attachment with :source_file_options"
do
context
"An attachment with :source_file_options"
do
before
do
before
do
rebuild_model
:styles
=>
{
rebuild_model
styles:
{
:thumb
=>
"100x100"
,
thumb:
"100x100"
,
:large
=>
"400x400"
large:
"400x400"
},
},
:source_file_options
=>
{
source_file_options:
{
:all
=>
"-density 400"
,
all:
"-density 400"
,
:thumb
=>
"-depth 8"
thumb:
"-depth 8"
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
@dummy
.
avatar
...
@@ -450,11 +453,11 @@ describe Paperclip::Attachment do
...
@@ -450,11 +453,11 @@ describe Paperclip::Attachment do
context
"An attachment with :only_process"
do
context
"An attachment with :only_process"
do
before
do
before
do
rebuild_model
:styles
=>
{
rebuild_model
styles:
{
:thumb
=>
"100x100"
,
thumb:
"100x100"
,
:large
=>
"400x400"
large:
"400x400"
},
},
:only_process
=>
[
:thumb
]
only_process:
[
:thumb
]
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
end
end
...
@@ -468,11 +471,11 @@ describe Paperclip::Attachment do
...
@@ -468,11 +471,11 @@ describe Paperclip::Attachment do
context
"An attachment with :only_process that is a proc"
do
context
"An attachment with :only_process that is a proc"
do
before
do
before
do
rebuild_model
:styles
=>
{
rebuild_model
styles:
{
:thumb
=>
"100x100"
,
thumb:
"100x100"
,
:large
=>
"400x400"
large:
"400x400"
},
},
:only_process
=>
lambda
{
|
attachment
|
[
:thumb
]
}
only_process:
lambda
{
|
attachment
|
[
:thumb
]
}
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
...
@@ -487,13 +490,13 @@ describe Paperclip::Attachment do
...
@@ -487,13 +490,13 @@ describe Paperclip::Attachment do
context
"An attachment with :convert_options that is a proc"
do
context
"An attachment with :convert_options that is a proc"
do
before
do
before
do
rebuild_model
:styles
=>
{
rebuild_model
styles:
{
:thumb
=>
"100x100"
,
thumb:
"100x100"
,
:large
=>
"400x400"
large:
"400x400"
},
},
:convert_options
=>
{
convert_options:
{
:all
=>
lambda
{
|
i
|
i
.
all
},
all:
lambda
{
|
i
|
i
.
all
},
:thumb
=>
lambda
{
|
i
|
i
.
thumb
}
thumb:
lambda
{
|
i
|
i
.
thumb
}
}
}
Dummy
.
class_eval
do
Dummy
.
class_eval
do
def
all
;
"-all"
;
end
def
all
;
"-all"
;
end
...
@@ -514,12 +517,12 @@ describe Paperclip::Attachment do
...
@@ -514,12 +517,12 @@ describe Paperclip::Attachment do
context
"An attachment with :path that is a proc"
do
context
"An attachment with :path that is a proc"
do
before
do
before
do
rebuild_model
:path
=>
lambda
{
|
attachment
|
"path/
#{
attachment
.
instance
.
other
}
.:extension"
}
rebuild_model
path:
lambda
{
|
attachment
|
"path/
#{
attachment
.
instance
.
other
}
.:extension"
}
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@dummyA
=
Dummy
.
new
(
:other
=>
'a'
)
@dummyA
=
Dummy
.
new
(
other:
'a'
)
@dummyA
.
avatar
=
@file
@dummyA
.
avatar
=
@file
@dummyB
=
Dummy
.
new
(
:other
=>
'b'
)
@dummyB
=
Dummy
.
new
(
other:
'b'
)
@dummyB
.
avatar
=
@file
@dummyB
.
avatar
=
@file
end
end
...
@@ -533,7 +536,7 @@ describe Paperclip::Attachment do
...
@@ -533,7 +536,7 @@ describe Paperclip::Attachment do
context
"An attachment with :styles that is a proc"
do
context
"An attachment with :styles that is a proc"
do
before
do
before
do
rebuild_model
:styles
=>
lambda
{
|
attachment
|
{
:thumb
=>
"50x50#"
,
:large
=>
"400x400"
}
}
rebuild_model
styles:
lambda
{
|
attachment
|
{
thumb:
"50x50#"
,
large:
"400x400"
}
}
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
end
end
...
@@ -545,9 +548,9 @@ describe Paperclip::Attachment do
...
@@ -545,9 +548,9 @@ describe Paperclip::Attachment do
context
"An attachment with conditional :styles that is a proc"
do
context
"An attachment with conditional :styles that is a proc"
do
before
do
before
do
rebuild_model
:styles
=>
lambda
{
|
attachment
|
attachment
.
instance
.
other
==
'a'
?
{:
thumb
=>
"50x50#"
}
:
{
:large
=>
"400x400"
}
}
rebuild_model
styles:
lambda
{
|
attachment
|
attachment
.
instance
.
other
==
'a'
?
{
thumb:
"50x50#"
}
:
{
large:
"400x400"
}
}
@dummy
=
Dummy
.
new
(
:other
=>
'a'
)
@dummy
=
Dummy
.
new
(
other:
'a'
)
end
end
it
"have the correct styles for the assigned instance values"
do
it
"have the correct styles for the assigned instance values"
do
...
@@ -564,12 +567,12 @@ describe Paperclip::Attachment do
...
@@ -564,12 +567,12 @@ describe Paperclip::Attachment do
geometry_specs
=
[
geometry_specs
=
[
[
lambda
{
|
z
|
"50x50#"
},
:png
],
[
lambda
{
|
z
|
"50x50#"
},
:png
],
lambda
{
|
z
|
"50x50#"
},
lambda
{
|
z
|
"50x50#"
},
{
:geometry
=>
lambda
{
|
z
|
"50x50#"
}
}
{
geometry:
lambda
{
|
z
|
"50x50#"
}
}
]
]
geometry_specs
.
each
do
|
geometry_spec
|
geometry_specs
.
each
do
|
geometry_spec
|
context
"An attachment geometry like
#{
geometry_spec
}
"
do
context
"An attachment geometry like
#{
geometry_spec
}
"
do
before
do
before
do
rebuild_model
:styles
=>
{
:normal
=>
geometry_spec
}
rebuild_model
styles:
{
normal:
geometry_spec
}
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
end
end
...
@@ -588,9 +591,9 @@ describe Paperclip::Attachment do
...
@@ -588,9 +591,9 @@ describe Paperclip::Attachment do
context
"An attachment with both 'normal' and hash-style styles"
do
context
"An attachment with both 'normal' and hash-style styles"
do
before
do
before
do
rebuild_model
:styles
=>
{
rebuild_model
styles:
{
:normal
=>
[
"50x50#"
,
:png
],
normal:
[
"50x50#"
,
:png
],
:hash
=>
{
:geometry
=>
"50x50#"
,
:format
=>
:png
}
hash:
{
geometry:
"50x50#"
,
format:
:png
}
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@attachment
=
@dummy
.
avatar
@attachment
=
@dummy
.
avatar
...
@@ -609,7 +612,7 @@ describe Paperclip::Attachment do
...
@@ -609,7 +612,7 @@ describe Paperclip::Attachment do
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
Paperclip
::
Test
.
stubs
(
:make
).
returns
(
@file
)
Paperclip
::
Test
.
stubs
(
:make
).
returns
(
@file
)
rebuild_model
:styles
=>
{
:normal
=>
''
},
:processors
=>
lambda
{
|
a
|
[
:test
]
}
rebuild_model
styles:
{
normal:
''
},
processors:
lambda
{
|
a
|
[
:test
]
}
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
end
end
...
@@ -626,7 +629,7 @@ describe Paperclip::Attachment do
...
@@ -626,7 +629,7 @@ describe Paperclip::Attachment do
context
"An attachment with erroring processor"
do
context
"An attachment with erroring processor"
do
before
do
before
do
rebuild_model
:processor
=>
[
:thumbnail
],
:styles
=>
{
:small
=>
''
},
:whiny_thumbnails
=>
true
rebuild_model
processor:
[
:thumbnail
],
styles:
{
small:
''
},
whiny_thumbnails:
true
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
Paperclip
::
Thumbnail
.
expects
(
:make
).
raises
(
Paperclip
::
Error
,
"cannot be processed."
)
Paperclip
::
Thumbnail
.
expects
(
:make
).
raises
(
Paperclip
::
Error
,
"cannot be processed."
)
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
...
@@ -643,8 +646,8 @@ describe Paperclip::Attachment do
...
@@ -643,8 +646,8 @@ describe Paperclip::Attachment do
context
"An attachment with multiple processors"
do
context
"An attachment with multiple processors"
do
before
do
before
do
class
Paperclip
::
Test
<
Paperclip
::
Processor
;
end
class
Paperclip
::
Test
<
Paperclip
::
Processor
;
end
@style_params
=
{
:once
=>
{
:one
=>
1
,
:two
=>
2
}
}
@style_params
=
{
once:
{
one:
1
,
two:
2
}
}
rebuild_model
:processors
=>
[
:thumbnail
,
:test
],
:styles
=>
@style_params
rebuild_model
processors:
[
:thumbnail
,
:test
],
styles:
@style_params
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
@file
.
stubs
(
:close
)
@file
.
stubs
(
:close
)
...
@@ -665,10 +668,10 @@ describe Paperclip::Attachment do
...
@@ -665,10 +668,10 @@ describe Paperclip::Attachment do
it
"call #make with the right parameters passed as second argument"
do
it
"call #make with the right parameters passed as second argument"
do
expected_params
=
@style_params
[
:once
].
merge
({
expected_params
=
@style_params
[
:once
].
merge
({
:processors
=>
[
:thumbnail
,
:test
],
processors:
[
:thumbnail
,
:test
],
:whiny
=>
true
,
whiny:
true
,
:convert_options
=>
""
,
convert_options:
""
,
:source_file_options
=>
""
source_file_options:
""
})
})
Paperclip
::
Thumbnail
.
stubs
(
:make
).
returns
(
@file
)
Paperclip
::
Thumbnail
.
stubs
(
:make
).
returns
(
@file
)
...
@@ -688,23 +691,23 @@ describe Paperclip::Attachment do
...
@@ -688,23 +691,23 @@ describe Paperclip::Attachment do
end
end
it
"include the filesystem module when loading the filesystem storage"
do
it
"include the filesystem module when loading the filesystem storage"
do
rebuild_model
:storage
=>
:filesystem
rebuild_model
storage:
:filesystem
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
assert
@dummy
.
avatar
.
is_a?
(
Paperclip
::
Storage
::
Filesystem
)
assert
@dummy
.
avatar
.
is_a?
(
Paperclip
::
Storage
::
Filesystem
)
end
end
it
"include the filesystem module even if capitalization is wrong"
do
it
"include the filesystem module even if capitalization is wrong"
do
rebuild_model
:storage
=>
:FileSystem
rebuild_model
storage:
:FileSystem
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
assert
@dummy
.
avatar
.
is_a?
(
Paperclip
::
Storage
::
Filesystem
)
assert
@dummy
.
avatar
.
is_a?
(
Paperclip
::
Storage
::
Filesystem
)
rebuild_model
:storage
=>
:Filesystem
rebuild_model
storage:
:Filesystem
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
assert
@dummy
.
avatar
.
is_a?
(
Paperclip
::
Storage
::
Filesystem
)
assert
@dummy
.
avatar
.
is_a?
(
Paperclip
::
Storage
::
Filesystem
)
end
end
it
"convert underscored storage name to camelcase"
do
it
"convert underscored storage name to camelcase"
do
rebuild_model
:storage
=>
:not_here
rebuild_model
storage:
:not_here
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
exception
=
assert_raises
(
Paperclip
::
Errors
::
StorageMethodNotFound
,
/NotHere/
)
do
exception
=
assert_raises
(
Paperclip
::
Errors
::
StorageMethodNotFound
,
/NotHere/
)
do
@dummy
.
avatar
@dummy
.
avatar
...
@@ -712,7 +715,7 @@ describe Paperclip::Attachment do
...
@@ -712,7 +715,7 @@ describe Paperclip::Attachment do
end
end
it
"raise an error if you try to include a storage module that doesn't exist"
do
it
"raise an error if you try to include a storage module that doesn't exist"
do
rebuild_model
:storage
=>
:not_here
rebuild_model
storage:
:not_here
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
assert_raises
(
Paperclip
::
Errors
::
StorageMethodNotFound
)
do
assert_raises
(
Paperclip
::
Errors
::
StorageMethodNotFound
)
do
@dummy
.
avatar
@dummy
.
avatar
...
@@ -721,7 +724,7 @@ describe Paperclip::Attachment do
...
@@ -721,7 +724,7 @@ describe Paperclip::Attachment do
context
"An attachment with styles but no processors defined"
do
context
"An attachment with styles but no processors defined"
do
before
do
before
do
rebuild_model
:processors
=>
[],
:styles
=>
{
:something
=>
'1'
}
rebuild_model
processors:
[],
styles:
{
something:
'1'
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
end
end
...
@@ -732,7 +735,7 @@ describe Paperclip::Attachment do
...
@@ -732,7 +735,7 @@ describe Paperclip::Attachment do
context
"An attachment without styles and with no processors defined"
do
context
"An attachment without styles and with no processors defined"
do
before
do
before
do
rebuild_model
:processors
=>
[],
:styles
=>
{}
rebuild_model
processors:
[],
styles:
{}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
end
end
...
@@ -743,7 +746,7 @@ describe Paperclip::Attachment do
...
@@ -743,7 +746,7 @@ describe Paperclip::Attachment do
context
"Assigning an attachment with post_process hooks"
do
context
"Assigning an attachment with post_process hooks"
do
before
do
before
do
rebuild_class
:styles
=>
{
:something
=>
"100x100#"
}
rebuild_class
styles:
{
something:
"100x100#"
}
Dummy
.
class_eval
do
Dummy
.
class_eval
do
before_avatar_post_process
:do_before_avatar
before_avatar_post_process
:do_before_avatar
after_avatar_post_process
:do_after_avatar
after_avatar_post_process
:do_after_avatar
...
@@ -800,7 +803,7 @@ describe Paperclip::Attachment do
...
@@ -800,7 +803,7 @@ describe Paperclip::Attachment do
context
"Assigning an attachment"
do
context
"Assigning an attachment"
do
before
do
before
do
rebuild_model
:styles
=>
{
:something
=>
"100x100#"
}
rebuild_model
styles:
{
something:
"100x100#"
}
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
"rb"
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
"rb"
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -817,7 +820,7 @@ describe Paperclip::Attachment do
...
@@ -817,7 +820,7 @@ describe Paperclip::Attachment do
context
"Assigning an attachment"
do
context
"Assigning an attachment"
do
before
do
before
do
rebuild_model
:styles
=>
{
:something
=>
"100x100#"
}
rebuild_model
styles:
{
something:
"100x100#"
}
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
"rb"
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
"rb"
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -907,7 +910,7 @@ describe Paperclip::Attachment do
...
@@ -907,7 +910,7 @@ describe Paperclip::Attachment do
context
'as another regexp'
do
context
'as another regexp'
do
before
do
before
do
Paperclip
::
Attachment
.
default_options
.
merge!
:restricted_characters
=>
/o/
Paperclip
::
Attachment
.
default_options
.
merge!
restricted_characters:
/o/
@file
.
stubs
(
:original_filename
).
returns
(
"goood.png"
)
@file
.
stubs
(
:original_filename
).
returns
(
"goood.png"
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -921,7 +924,7 @@ describe Paperclip::Attachment do
...
@@ -921,7 +924,7 @@ describe Paperclip::Attachment do
context
'as nil'
do
context
'as nil'
do
before
do
before
do
Paperclip
::
Attachment
.
default_options
.
merge!
:restricted_characters
=>
nil
Paperclip
::
Attachment
.
default_options
.
merge!
restricted_characters:
nil
@file
.
stubs
(
:original_filename
).
returns
(
"goood.png"
)
@file
.
stubs
(
:original_filename
).
returns
(
"goood.png"
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -974,13 +977,13 @@ describe Paperclip::Attachment do
...
@@ -974,13 +977,13 @@ describe Paperclip::Attachment do
before
do
before
do
@old_defaults
=
Paperclip
::
Attachment
.
default_options
.
dup
@old_defaults
=
Paperclip
::
Attachment
.
default_options
.
dup
Paperclip
::
Attachment
.
default_options
.
merge!
({
Paperclip
::
Attachment
.
default_options
.
merge!
({
:path
=>
":rails_root/:attachment/:class/:style/:id/:basename.:extension"
path:
":rails_root/:attachment/:class/:style/:id/:basename.:extension"
})
})
FileUtils
.
rm_rf
(
"tmp"
)
FileUtils
.
rm_rf
(
"tmp"
)
rebuild_model
:styles
=>
{
:large
=>
[
"400x400"
,
:jpg
],
rebuild_model
styles:
{
large:
[
"400x400"
,
:jpg
],
:medium
=>
[
"100x100"
,
:jpg
],
medium:
[
"100x100"
,
:jpg
],
:small
=>
[
"32x32#"
,
:jpg
]},
small:
[
"32x32#"
,
:jpg
]},
:default_style
=>
:small
default_style:
:small
@instance
=
Dummy
.
new
@instance
=
Dummy
.
new
@instance
.
stubs
(
:id
).
returns
123
@instance
.
stubs
(
:id
).
returns
123
@file
=
File
.
new
(
fixture_file
(
"uppercase.PNG"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"uppercase.PNG"
),
'rb'
)
...
@@ -1012,7 +1015,7 @@ describe Paperclip::Attachment do
...
@@ -1012,7 +1015,7 @@ describe Paperclip::Attachment do
before
do
before
do
@old_defaults
=
Paperclip
::
Attachment
.
default_options
.
dup
@old_defaults
=
Paperclip
::
Attachment
.
default_options
.
dup
Paperclip
::
Attachment
.
default_options
.
merge!
({
Paperclip
::
Attachment
.
default_options
.
merge!
({
:path
=>
":rails_root/:attachment/:class/:style/:id/:basename.:extension"
path:
":rails_root/:attachment/:class/:style/:id/:basename.:extension"
})
})
FileUtils
.
rm_rf
(
"tmp"
)
FileUtils
.
rm_rf
(
"tmp"
)
rebuild_model
rebuild_model
...
@@ -1085,10 +1088,10 @@ describe Paperclip::Attachment do
...
@@ -1085,10 +1088,10 @@ describe Paperclip::Attachment do
context
"when expecting three styles"
do
context
"when expecting three styles"
do
before
do
before
do
rebuild_class
:styles
=>
{
rebuild_class
styles:
{
:large
=>
[
"400x400"
,
:png
],
large:
[
"400x400"
,
:png
],
:medium
=>
[
"100x100"
,
:gif
],
medium:
[
"100x100"
,
:gif
],
:small
=>
[
"32x32#"
,
:jpg
]
small:
[
"32x32#"
,
:jpg
]
}
}
@instance
=
Dummy
.
new
@instance
=
Dummy
.
new
@instance
.
stubs
(
:id
).
returns
123
@instance
.
stubs
(
:id
).
returns
123
...
@@ -1215,7 +1218,7 @@ describe Paperclip::Attachment do
...
@@ -1215,7 +1218,7 @@ describe Paperclip::Attachment do
context
"when trying a nonexistant storage type"
do
context
"when trying a nonexistant storage type"
do
before
do
before
do
rebuild_model
:storage
=>
:not_here
rebuild_model
storage:
:not_here
end
end
it
"not be able to find the module"
do
it
"not be able to find the module"
do
...
@@ -1226,7 +1229,7 @@ describe Paperclip::Attachment do
...
@@ -1226,7 +1229,7 @@ describe Paperclip::Attachment do
context
"An attachment with only a avatar_file_name column"
do
context
"An attachment with only a avatar_file_name column"
do
before
do
before
do
ActiveRecord
::
Base
.
connection
.
create_table
:dummies
,
:force
=>
true
do
|
table
|
ActiveRecord
::
Base
.
connection
.
create_table
:dummies
,
force:
true
do
|
table
|
table
.
column
:avatar_file_name
,
:string
table
.
column
:avatar_file_name
,
:string
end
end
rebuild_class
rebuild_class
...
@@ -1379,7 +1382,7 @@ describe Paperclip::Attachment do
...
@@ -1379,7 +1382,7 @@ describe Paperclip::Attachment do
context
"an attachment with delete_file option set to false"
do
context
"an attachment with delete_file option set to false"
do
before
do
before
do
rebuild_model
:preserve_files
=>
true
rebuild_model
preserve_files:
true
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
...
spec/paperclip/geometry_detector_spec.rb
View file @
40010c4d
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Paperclip
::
GeometryDetector
do
describe
Paperclip
::
GeometryDetector
do
it
'identify an image and extract its dimensions'
do
it
'identify an image and extract its dimensions'
do
Paperclip
::
GeometryParser
.
stubs
(
:new
).
with
(
"434x66,"
).
returns
(
stub
(
:make
=>
:correct
))
Paperclip
::
GeometryParser
.
stubs
(
:new
).
with
(
"434x66,"
).
returns
(
stub
(
make:
:correct
))
file
=
fixture_file
(
"5k.png"
)
file
=
fixture_file
(
"5k.png"
)
factory
=
Paperclip
::
GeometryDetector
.
new
(
file
)
factory
=
Paperclip
::
GeometryDetector
.
new
(
file
)
...
@@ -12,7 +12,7 @@ describe Paperclip::GeometryDetector do
...
@@ -12,7 +12,7 @@ describe Paperclip::GeometryDetector do
end
end
it
'identify an image and extract its dimensions and orientation'
do
it
'identify an image and extract its dimensions and orientation'
do
Paperclip
::
GeometryParser
.
stubs
(
:new
).
with
(
"300x200,6"
).
returns
(
stub
(
:make
=>
:correct
))
Paperclip
::
GeometryParser
.
stubs
(
:new
).
with
(
"300x200,6"
).
returns
(
stub
(
make:
:correct
))
file
=
fixture_file
(
"rotated.jpg"
)
file
=
fixture_file
(
"rotated.jpg"
)
factory
=
Paperclip
::
GeometryDetector
.
new
(
file
)
factory
=
Paperclip
::
GeometryDetector
.
new
(
file
)
...
...
spec/paperclip/geometry_parser_spec.rb
View file @
40010c4d
...
@@ -3,10 +3,10 @@ require 'spec_helper'
...
@@ -3,10 +3,10 @@ require 'spec_helper'
describe
Paperclip
::
GeometryParser
do
describe
Paperclip
::
GeometryParser
do
it
'identify an image and extract its dimensions with no orientation'
do
it
'identify an image and extract its dimensions with no orientation'
do
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
:height
=>
'73'
,
height:
'73'
,
:width
=>
'434'
,
width:
'434'
,
:modifier
=>
nil
,
modifier:
nil
,
:orientation
=>
nil
orientation:
nil
).
returns
(
:correct
)
).
returns
(
:correct
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"434x73"
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"434x73"
)
...
@@ -17,10 +17,10 @@ describe Paperclip::GeometryParser do
...
@@ -17,10 +17,10 @@ describe Paperclip::GeometryParser do
it
'identify an image and extract its dimensions with an empty orientation'
do
it
'identify an image and extract its dimensions with an empty orientation'
do
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
:height
=>
'73'
,
height:
'73'
,
:width
=>
'434'
,
width:
'434'
,
:modifier
=>
nil
,
modifier:
nil
,
:orientation
=>
''
orientation:
''
).
returns
(
:correct
)
).
returns
(
:correct
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"434x73,"
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"434x73,"
)
...
@@ -31,10 +31,10 @@ describe Paperclip::GeometryParser do
...
@@ -31,10 +31,10 @@ describe Paperclip::GeometryParser do
it
'identify an image and extract its dimensions and orientation'
do
it
'identify an image and extract its dimensions and orientation'
do
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
:height
=>
'200'
,
height:
'200'
,
:width
=>
'300'
,
width:
'300'
,
:modifier
=>
nil
,
modifier:
nil
,
:orientation
=>
'6'
orientation:
'6'
).
returns
(
:correct
)
).
returns
(
:correct
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"300x200,6"
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"300x200,6"
)
...
@@ -45,10 +45,10 @@ describe Paperclip::GeometryParser do
...
@@ -45,10 +45,10 @@ describe Paperclip::GeometryParser do
it
'identify an image and extract its dimensions and modifier'
do
it
'identify an image and extract its dimensions and modifier'
do
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
:height
=>
'64'
,
height:
'64'
,
:width
=>
'64'
,
width:
'64'
,
:modifier
=>
'#'
,
modifier:
'#'
,
:orientation
=>
nil
orientation:
nil
).
returns
(
:correct
)
).
returns
(
:correct
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"64x64#"
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"64x64#"
)
...
@@ -59,10 +59,10 @@ describe Paperclip::GeometryParser do
...
@@ -59,10 +59,10 @@ describe Paperclip::GeometryParser do
it
'identify an image and extract its dimensions, orientation, and modifier'
do
it
'identify an image and extract its dimensions, orientation, and modifier'
do
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
Paperclip
::
Geometry
.
stubs
(
:new
).
with
(
:height
=>
'50'
,
height:
'50'
,
:width
=>
'100'
,
width:
'100'
,
:modifier
=>
'>'
,
modifier:
'>'
,
:orientation
=>
'7'
orientation:
'7'
).
returns
(
:correct
)
).
returns
(
:correct
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"100x50,7>"
)
factory
=
Paperclip
::
GeometryParser
.
new
(
"100x50,7>"
)
...
...
spec/paperclip/geometry_spec.rb
View file @
40010c4d
...
@@ -50,7 +50,7 @@ describe Paperclip::Geometry do
...
@@ -50,7 +50,7 @@ describe Paperclip::Geometry do
end
end
it
"recognize an EXIF orientation and not rotate with auto_orient if not necessary"
do
it
"recognize an EXIF orientation and not rotate with auto_orient if not necessary"
do
geo
=
Paperclip
::
Geometry
.
new
(
:width
=>
1024
,
:height
=>
768
,
:orientation
=>
1
)
geo
=
Paperclip
::
Geometry
.
new
(
width:
1024
,
height:
768
,
orientation:
1
)
assert
geo
assert
geo
assert_equal
1024
,
geo
.
width
assert_equal
1024
,
geo
.
width
assert_equal
768
,
geo
.
height
assert_equal
768
,
geo
.
height
...
@@ -62,7 +62,7 @@ describe Paperclip::Geometry do
...
@@ -62,7 +62,7 @@ describe Paperclip::Geometry do
end
end
it
"recognize an EXIF orientation and rotate with auto_orient if necessary"
do
it
"recognize an EXIF orientation and rotate with auto_orient if necessary"
do
geo
=
Paperclip
::
Geometry
.
new
(
:width
=>
1024
,
:height
=>
768
,
:orientation
=>
6
)
geo
=
Paperclip
::
Geometry
.
new
(
width:
1024
,
height:
768
,
orientation:
6
)
assert
geo
assert
geo
assert_equal
1024
,
geo
.
width
assert_equal
1024
,
geo
.
width
assert_equal
768
,
geo
.
height
assert_equal
768
,
geo
.
height
...
@@ -161,7 +161,7 @@ describe Paperclip::Geometry do
...
@@ -161,7 +161,7 @@ describe Paperclip::Geometry do
end
end
it
"not generate from a file with no path"
do
it
"not generate from a file with no path"
do
file
=
mock
(
"file"
,
:path
=>
""
)
file
=
mock
(
"file"
,
path:
""
)
file
.
stubs
(
:respond_to?
).
with
(
:path
).
returns
(
true
)
file
.
stubs
(
:respond_to?
).
with
(
:path
).
returns
(
true
)
expect
{
@geo
=
Paperclip
::
Geometry
.
from_file
(
file
)
}.
to
raise_error
(
Paperclip
::
Errors
::
NotIdentifiedByImageMagickError
)
expect
{
@geo
=
Paperclip
::
Geometry
.
from_file
(
file
)
}.
to
raise_error
(
Paperclip
::
Errors
::
NotIdentifiedByImageMagickError
)
end
end
...
...
spec/paperclip/integration_spec.rb
View file @
40010c4d
...
@@ -8,11 +8,11 @@ describe 'Paperclip' do
...
@@ -8,11 +8,11 @@ describe 'Paperclip' do
rebuild_model
rebuild_model
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
300
.
times
do
|
i
|
300
.
times
do
|
i
|
Dummy
.
create!
:avatar
=>
@file
Dummy
.
create!
avatar:
@file
end
end
end
end
#
after { @file.close }
after
{
@file
.
close
}
it
"not exceed the open file limit"
do
it
"not exceed the open file limit"
do
assert_nothing_raised
do
assert_nothing_raised
do
...
@@ -23,14 +23,14 @@ describe 'Paperclip' do
...
@@ -23,14 +23,14 @@ describe 'Paperclip' do
context
"An attachment"
do
context
"An attachment"
do
before
do
before
do
rebuild_model
:styles
=>
{
:thumb
=>
"50x50#"
}
rebuild_model
styles:
{
thumb:
"50x50#"
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
assert
@dummy
.
save
assert
@dummy
.
save
end
end
#
after { @file.close }
after
{
@file
.
close
}
it
"create its thumbnails properly"
do
it
"create its thumbnails properly"
do
assert_match
(
/\b50x50\b/
,
`identify "
#{
@dummy
.
avatar
.
path
(
:thumb
)
}
"`
)
assert_match
(
/\b50x50\b/
,
`identify "
#{
@dummy
.
avatar
.
path
(
:thumb
)
}
"`
)
...
@@ -53,13 +53,13 @@ describe 'Paperclip' do
...
@@ -53,13 +53,13 @@ describe 'Paperclip' do
end
end
end
end
#
after { File.chmod(0644, @dummy.avatar.path) }
after
{
File
.
chmod
(
0644
,
@dummy
.
avatar
.
path
)
}
end
end
context
"redefining its attachment styles"
do
context
"redefining its attachment styles"
do
before
do
before
do
Dummy
.
class_eval
do
Dummy
.
class_eval
do
has_attached_file
:avatar
,
:styles
=>
{
:thumb
=>
"150x25#"
,
:dynamic
=>
lambda
{
|
a
|
'50x50#'
}
}
has_attached_file
:avatar
,
styles:
{
thumb:
"150x25#"
,
dynamic:
lambda
{
|
a
|
'50x50#'
}
}
end
end
@d2
=
Dummy
.
find
(
@dummy
.
id
)
@d2
=
Dummy
.
find
(
@dummy
.
id
)
@original_timestamp
=
@d2
.
avatar_updated_at
@original_timestamp
=
@d2
.
avatar_updated_at
...
@@ -82,13 +82,13 @@ describe 'Paperclip' do
...
@@ -82,13 +82,13 @@ describe 'Paperclip' do
before
do
before
do
@thumb_path
=
"tmp/public/system/dummies/avatars/000/000/001/thumb/5k.png"
@thumb_path
=
"tmp/public/system/dummies/avatars/000/000/001/thumb/5k.png"
File
.
delete
(
@thumb_path
)
if
File
.
exists?
(
@thumb_path
)
File
.
delete
(
@thumb_path
)
if
File
.
exists?
(
@thumb_path
)
rebuild_model
:styles
=>
{
:thumb
=>
"50x50#"
}
rebuild_model
styles:
{
thumb:
"50x50#"
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
end
end
#
after { @file.close }
after
{
@file
.
close
}
it
"not create the thumbnails upon saving when post-processing is disabled"
do
it
"not create the thumbnails upon saving when post-processing is disabled"
do
@dummy
.
avatar
.
post_processing
=
false
@dummy
.
avatar
.
post_processing
=
false
...
@@ -111,7 +111,7 @@ describe 'Paperclip' do
...
@@ -111,7 +111,7 @@ describe 'Paperclip' do
@thumb_large_path
=
"tmp/public/system/dummies/avatars/000/000/001/thumb_large/5k.png"
@thumb_large_path
=
"tmp/public/system/dummies/avatars/000/000/001/thumb_large/5k.png"
File
.
delete
(
@thumb_small_path
)
if
File
.
exists?
(
@thumb_small_path
)
File
.
delete
(
@thumb_small_path
)
if
File
.
exists?
(
@thumb_small_path
)
File
.
delete
(
@thumb_large_path
)
if
File
.
exists?
(
@thumb_large_path
)
File
.
delete
(
@thumb_large_path
)
if
File
.
exists?
(
@thumb_large_path
)
rebuild_model
:styles
=>
{
:thumb_small
=>
"50x50#"
,
:thumb_large
=>
"60x60#"
}
rebuild_model
styles:
{
thumb_small:
"50x50#"
,
thumb_large:
"60x60#"
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
...
@@ -121,7 +121,7 @@ describe 'Paperclip' do
...
@@ -121,7 +121,7 @@ describe 'Paperclip' do
@dummy
.
avatar
.
post_processing
=
true
@dummy
.
avatar
.
post_processing
=
true
end
end
#
after { @file.close }
after
{
@file
.
close
}
it
"allow us to create all thumbnails in one go"
do
it
"allow us to create all thumbnails in one go"
do
assert_file_not_exists
(
@thumb_small_path
)
assert_file_not_exists
(
@thumb_small_path
)
...
@@ -148,7 +148,7 @@ describe 'Paperclip' do
...
@@ -148,7 +148,7 @@ describe 'Paperclip' do
context
"A model that modifies its original"
do
context
"A model that modifies its original"
do
before
do
before
do
rebuild_model
:styles
=>
{
:original
=>
"2x2#"
}
rebuild_model
styles:
{
original:
"2x2#"
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -158,20 +158,20 @@ describe 'Paperclip' do
...
@@ -158,20 +158,20 @@ describe 'Paperclip' do
assert_not_equal
File
.
size
(
@file
.
path
),
@dummy
.
avatar
.
size
assert_not_equal
File
.
size
(
@file
.
path
),
@dummy
.
avatar
.
size
end
end
#
after { @file.close }
after
{
@file
.
close
}
end
end
context
"A model with attachments scoped under an id"
do
context
"A model with attachments scoped under an id"
do
before
do
before
do
rebuild_model
:styles
=>
{
:large
=>
"100x100"
,
rebuild_model
styles:
{
large:
"100x100"
,
:medium
=>
"50x50"
},
medium:
"50x50"
},
:path
=>
":rails_root/tmp/:id/:attachments/:style.:extension"
path:
":rails_root/tmp/:id/:attachments/:style.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
end
end
#
after { @file.close }
after
{
@file
.
close
}
context
"when saved"
do
context
"when saved"
do
before
do
before
do
...
@@ -220,10 +220,10 @@ describe 'Paperclip' do
...
@@ -220,10 +220,10 @@ describe 'Paperclip' do
@umask
=
File
.
umask
(
umask
)
@umask
=
File
.
umask
(
umask
)
end
end
#
after do
after
do
#
File.umask @umask
File
.
umask
@umask
#
@file.close
@file
.
close
#
end
end
it
"respect the current umask"
do
it
"respect the current umask"
do
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -236,14 +236,14 @@ describe 'Paperclip' do
...
@@ -236,14 +236,14 @@ describe 'Paperclip' do
[
0666
,
0664
,
0640
].
each
do
|
perms
|
[
0666
,
0664
,
0640
].
each
do
|
perms
|
context
"when the perms are
#{
perms
}
"
do
context
"when the perms are
#{
perms
}
"
do
before
do
before
do
rebuild_model
:override_file_permissions
=>
perms
rebuild_model
override_file_permissions:
perms
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
end
end
#
after do
after
do
#
@file.close
@file
.
close
#
end
end
it
"respect the current perms"
do
it
"respect the current perms"
do
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -256,7 +256,7 @@ describe 'Paperclip' do
...
@@ -256,7 +256,7 @@ describe 'Paperclip' do
it
"skip chmod operation, when override_file_permissions is set to false (e.g. useful when using CIFS mounts)"
do
it
"skip chmod operation, when override_file_permissions is set to false (e.g. useful when using CIFS mounts)"
do
FileUtils
.
expects
(
:chmod
).
never
FileUtils
.
expects
(
:chmod
).
never
rebuild_model
:override_file_permissions
=>
false
rebuild_model
override_file_permissions:
false
dummy
=
Dummy
.
create!
dummy
=
Dummy
.
create!
dummy
.
avatar
=
@file
dummy
.
avatar
=
@file
dummy
.
save
dummy
.
save
...
@@ -264,12 +264,12 @@ describe 'Paperclip' do
...
@@ -264,12 +264,12 @@ describe 'Paperclip' do
context
"A model with a filesystem attachment"
do
context
"A model with a filesystem attachment"
do
before
do
before
do
rebuild_model
:styles
=>
{
:large
=>
"300x300>"
,
rebuild_model
styles:
{
large:
"300x300>"
,
:medium
=>
"100x100"
,
medium:
"100x100"
,
:thumb
=>
[
"32x32#"
,
:gif
]
},
thumb:
[
"32x32#"
,
:gif
]
},
:default_style
=>
:medium
,
default_style:
:medium
,
:url
=>
"/:attachment/:class/:style/:id/:basename.:extension"
,
url:
"/:attachment/:class/:style/:id/:basename.:extension"
,
:path
=>
":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
path:
":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@bad_file
=
File
.
new
(
fixture_file
(
"bad.png"
),
'rb'
)
@bad_file
=
File
.
new
(
fixture_file
(
"bad.png"
),
'rb'
)
...
@@ -279,7 +279,7 @@ describe 'Paperclip' do
...
@@ -279,7 +279,7 @@ describe 'Paperclip' do
assert
@dummy
.
save
assert
@dummy
.
save
end
end
#
after { [@file, @bad_file].each(&:close) }
after
{
[
@file
,
@bad_file
].
each
(
&
:close
)
}
it
"write and delete its files"
do
it
"write and delete its files"
do
[[
"434x66"
,
:original
],
[[
"434x66"
,
:original
],
...
@@ -374,7 +374,7 @@ describe 'Paperclip' do
...
@@ -374,7 +374,7 @@ describe 'Paperclip' do
@dummy2
.
save
@dummy2
.
save
end
end
#
after { @file2.close }
after
{
@file2
.
close
}
it
"work when assigned a file"
do
it
"work when assigned a file"
do
assert_not_equal
`identify -format "%wx%h" "
#{
@dummy
.
avatar
.
path
(
:original
)
}
"`
,
assert_not_equal
`identify -format "%wx%h" "
#{
@dummy
.
avatar
.
path
(
:original
)
}
"`
,
...
@@ -393,7 +393,7 @@ describe 'Paperclip' do
...
@@ -393,7 +393,7 @@ describe 'Paperclip' do
context
"A model with an attachments association and a Paperclip attachment"
do
context
"A model with an attachments association and a Paperclip attachment"
do
before
do
before
do
Dummy
.
class_eval
do
Dummy
.
class_eval
do
has_many
:attachments
,
:class_name
=>
'Dummy'
has_many
:attachments
,
class_name:
'Dummy'
end
end
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
...
@@ -401,7 +401,7 @@ describe 'Paperclip' do
...
@@ -401,7 +401,7 @@ describe 'Paperclip' do
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
end
end
#
after { @file.close }
after
{
@file
.
close
}
it
"should not error when saving"
do
it
"should not error when saving"
do
@dummy
.
save!
@dummy
.
save!
...
@@ -410,20 +410,20 @@ describe 'Paperclip' do
...
@@ -410,20 +410,20 @@ describe 'Paperclip' do
context
"A model with an attachment with hash in file name"
do
context
"A model with an attachment with hash in file name"
do
before
do
before
do
@settings
=
{
:styles
=>
{
:thumb
=>
"50x50#"
},
@settings
=
{
styles:
{
thumb:
"50x50#"
},
:path
=>
":rails_root/public/system/:attachment/:id_partition/:style/:hash.:extension"
,
path:
":rails_root/public/system/:attachment/:id_partition/:style/:hash.:extension"
,
:url
=>
"/system/:attachment/:id_partition/:style/:hash.:extension"
,
url:
"/system/:attachment/:id_partition/:style/:hash.:extension"
,
:hash_secret
=>
"somesecret"
}
hash_secret:
"somesecret"
}
rebuild_model
@settings
rebuild_model
@settings
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@dummy
=
Dummy
.
create!
:avatar
=>
@file
@dummy
=
Dummy
.
create!
avatar:
@file
end
end
#
after do
after
do
#
@file.close
@file
.
close
#
end
end
it
"be accessible"
do
it
"be accessible"
do
assert_file_exists
(
@dummy
.
avatar
.
path
(
:original
))
assert_file_exists
(
@dummy
.
avatar
.
path
(
:original
))
...
@@ -434,7 +434,7 @@ describe 'Paperclip' do
...
@@ -434,7 +434,7 @@ describe 'Paperclip' do
before
do
before
do
@dummy
.
avatar
.
options
[
:styles
][
:mini
]
=
"25x25#"
@dummy
.
avatar
.
options
[
:styles
][
:mini
]
=
"25x25#"
@dummy
.
avatar
.
instance_variable_set
:@normalized_styles
,
nil
@dummy
.
avatar
.
instance_variable_set
:@normalized_styles
,
nil
Time
.
stubs
(
:now
=>
Time
.
now
+
10
)
Time
.
stubs
(
now:
Time
.
now
+
10
)
@dummy
.
avatar
.
reprocess!
@dummy
.
avatar
.
reprocess!
@dummy
.
reload
@dummy
.
reload
end
end
...
@@ -470,21 +470,24 @@ describe 'Paperclip' do
...
@@ -470,21 +470,24 @@ describe 'Paperclip' do
context
"A model with an S3 attachment"
do
context
"A model with an S3 attachment"
do
before
do
before
do
rebuild_model
:styles
=>
{
:large
=>
"300x300>"
,
rebuild_model
(
:medium
=>
"100x100"
,
styles:
{
:thumb
=>
[
"32x32#"
,
:gif
],
large:
"300x300>"
,
:custom
=>
{
medium:
"100x100"
,
:geometry
=>
"32x32#"
,
thumb:
[
"32x32#"
,
:gif
],
:s3_headers
=>
{
'Cache-Control'
=>
'max-age=31557600'
},
custom:
{
:s3_metadata
=>
{
'foo'
=>
'bar'
}
geometry:
"32x32#"
,
s3_headers:
{
'Cache-Control'
=>
'max-age=31557600'
},
s3_metadata:
{
'foo'
=>
'bar'
}
}
}
},
},
:storage
=>
:s3
,
storage: :s3
,
:s3_credentials
=>
File
.
new
(
fixture_file
(
's3.yml'
)),
s3_credentials:
File
.
new
(
fixture_file
(
's3.yml'
)),
:s3_options
=>
{
:logger
=>
Paperclip
.
logger
},
s3_options:
{
logger:
Paperclip
.
logger
},
:default_style
=>
:medium
,
default_style: :medium
,
:bucket
=>
ENV
[
'S3_BUCKET'
],
bucket:
ENV
[
'S3_BUCKET'
],
:path
=>
":class/:attachment/:id/:style/:basename.:extension"
path:
":class/:attachment/:id/:style/:basename.:extension"
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
...
@@ -497,11 +500,11 @@ describe 'Paperclip' do
...
@@ -497,11 +500,11 @@ describe 'Paperclip' do
@files_on_s3
=
s3_files_for
(
@dummy
.
avatar
)
@files_on_s3
=
s3_files_for
(
@dummy
.
avatar
)
end
end
#
after do
after
do
#
@file.close
@file
.
close
#
@bad_file.close
@bad_file
.
close
#
@files_on_s3.values.each(&:close) if @files_on_s3
@files_on_s3
.
values
.
each
(
&
:close
)
if
@files_on_s3
#
end
end
context
'assigning itself to a new model'
do
context
'assigning itself to a new model'
do
before
do
before
do
...
@@ -634,7 +637,7 @@ describe 'Paperclip' do
...
@@ -634,7 +637,7 @@ describe 'Paperclip' do
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
end
end
#
after { @file.close }
after
{
@file
.
close
}
it
"succeed when original attachment is a file"
do
it
"succeed when original attachment is a file"
do
original
=
Dummy
.
new
original
=
Dummy
.
new
...
...
spec/paperclip/interpolations_spec.rb
View file @
40010c4d
...
@@ -46,7 +46,7 @@ describe Paperclip::Interpolations do
...
@@ -46,7 +46,7 @@ describe Paperclip::Interpolations do
it
"return the extension of the file as the format if defined in the style"
do
it
"return the extension of the file as the format if defined in the style"
do
attachment
=
mock
attachment
=
mock
attachment
.
expects
(
:original_filename
).
never
attachment
.
expects
(
:original_filename
).
never
attachment
.
expects
(
:styles
).
twice
.
returns
({
:style
=>
{
:format
=>
"png"
}})
attachment
.
expects
(
:styles
).
twice
.
returns
({
style:
{
format:
"png"
}})
[
:style
,
'style'
].
each
do
|
style
|
[
:style
,
'style'
].
each
do
|
style
|
assert_equal
"png"
,
Paperclip
::
Interpolations
.
extension
(
attachment
,
style
)
assert_equal
"png"
,
Paperclip
::
Interpolations
.
extension
(
attachment
,
style
)
...
@@ -83,7 +83,7 @@ describe Paperclip::Interpolations do
...
@@ -83,7 +83,7 @@ describe Paperclip::Interpolations do
it
"return the format if defined in the style, ignoring the content type"
do
it
"return the format if defined in the style, ignoring the content type"
do
attachment
=
mock
attachment
=
mock
attachment
.
expects
(
:content_type
).
returns
(
'image/jpeg'
)
attachment
.
expects
(
:content_type
).
returns
(
'image/jpeg'
)
attachment
.
expects
(
:styles
).
returns
({
:style
=>
{
:format
=>
"png"
}})
attachment
.
expects
(
:styles
).
returns
({
style:
{
format:
"png"
}})
interpolations
=
Paperclip
::
Interpolations
interpolations
=
Paperclip
::
Interpolations
interpolations
.
expects
(
:extension
).
returns
(
'random'
)
interpolations
.
expects
(
:extension
).
returns
(
'random'
)
assert_equal
"png"
,
interpolations
.
content_type_extension
(
attachment
,
:style
)
assert_equal
"png"
,
interpolations
.
content_type_extension
(
attachment
,
:style
)
...
@@ -91,7 +91,7 @@ describe Paperclip::Interpolations do
...
@@ -91,7 +91,7 @@ describe Paperclip::Interpolations do
it
"be able to handle numeric style names"
do
it
"be able to handle numeric style names"
do
attachment
=
mock
(
attachment
=
mock
(
:styles
=>
{
:"4"
=>
{
:format
=>
:expected_extension
}}
styles:
{
:"4"
=>
{
format:
:expected_extension
}}
)
)
assert_equal
:expected_extension
,
Paperclip
::
Interpolations
.
extension
(
attachment
,
4
)
assert_equal
:expected_extension
,
Paperclip
::
Interpolations
.
extension
(
attachment
,
4
)
end
end
...
@@ -156,7 +156,7 @@ describe Paperclip::Interpolations do
...
@@ -156,7 +156,7 @@ describe Paperclip::Interpolations do
it
"reinterpolate :url"
do
it
"reinterpolate :url"
do
attachment
=
mock
attachment
=
mock
attachment
.
expects
(
:url
).
with
(
:style
,
:timestamp
=>
false
,
:escape
=>
false
).
returns
(
"1234"
)
attachment
.
expects
(
:url
).
with
(
:style
,
timestamp:
false
,
escape:
false
).
returns
(
"1234"
)
assert_equal
"1234"
,
Paperclip
::
Interpolations
.
url
(
attachment
,
:style
)
assert_equal
"1234"
,
Paperclip
::
Interpolations
.
url
(
attachment
,
:style
)
end
end
...
@@ -179,7 +179,7 @@ describe Paperclip::Interpolations do
...
@@ -179,7 +179,7 @@ describe Paperclip::Interpolations do
it
"return the filename as basename.extension when format supplied"
do
it
"return the filename as basename.extension when format supplied"
do
attachment
=
mock
attachment
=
mock
attachment
.
expects
(
:styles
).
returns
({
:style
=>
{
:format
=>
:png
}})
attachment
.
expects
(
:styles
).
returns
({
style:
{
format:
:png
}})
attachment
.
expects
(
:original_filename
).
returns
(
"one.jpg"
).
times
(
2
)
attachment
.
expects
(
:original_filename
).
returns
(
"one.jpg"
).
times
(
2
)
assert_equal
"one.png"
,
Paperclip
::
Interpolations
.
filename
(
attachment
,
:style
)
assert_equal
"one.png"
,
Paperclip
::
Interpolations
.
filename
(
attachment
,
:style
)
end
end
...
...
spec/paperclip/io_adapters/attachment_adapter_spec.rb
View file @
40010c4d
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Paperclip
::
AttachmentAdapter
do
describe
Paperclip
::
AttachmentAdapter
do
before
do
before
do
rebuild_model
:path
=>
"tmp/:class/:attachment/:style/:filename"
,
:styles
=>
{
:thumb
=>
'50x50'
}
rebuild_model
path:
"tmp/:class/:attachment/:style/:filename"
,
styles:
{
thumb:
'50x50'
}
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
end
end
...
...
spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb
View file @
40010c4d
...
@@ -11,11 +11,11 @@ describe Paperclip::UploadedFileAdapter do
...
@@ -11,11 +11,11 @@ describe Paperclip::UploadedFileAdapter do
tempfile
.
binmode
tempfile
.
binmode
@file
=
UploadedFile
.
new
(
@file
=
UploadedFile
.
new
(
:original_filename
=>
"5k.png"
,
original_filename:
"5k.png"
,
:content_type
=>
"image/x-png-by-browser
\r
"
,
content_type:
"image/x-png-by-browser
\r
"
,
:head
=>
""
,
head:
""
,
:tempfile
=>
tempfile
,
tempfile:
tempfile
,
:path
=>
tempfile
.
path
path:
tempfile
.
path
)
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
...
@@ -58,10 +58,10 @@ describe Paperclip::UploadedFileAdapter do
...
@@ -58,10 +58,10 @@ describe Paperclip::UploadedFileAdapter do
class
UploadedFile
<
OpenStruct
;
end
class
UploadedFile
<
OpenStruct
;
end
@file
=
UploadedFile
.
new
(
@file
=
UploadedFile
.
new
(
:original_filename
=>
"image:restricted.gif"
,
original_filename:
"image:restricted.gif"
,
:content_type
=>
"image/x-png-by-browser"
,
content_type:
"image/x-png-by-browser"
,
:head
=>
""
,
head:
""
,
:path
=>
fixture_file
(
"5k.png"
)
path:
fixture_file
(
"5k.png"
)
)
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
...
@@ -81,10 +81,10 @@ describe Paperclip::UploadedFileAdapter do
...
@@ -81,10 +81,10 @@ describe Paperclip::UploadedFileAdapter do
class
UploadedFile
<
OpenStruct
;
end
class
UploadedFile
<
OpenStruct
;
end
@file
=
UploadedFile
.
new
(
@file
=
UploadedFile
.
new
(
:original_filename
=>
"5k.png"
,
original_filename:
"5k.png"
,
:content_type
=>
"image/x-png-by-browser"
,
content_type:
"image/x-png-by-browser"
,
:head
=>
""
,
head:
""
,
:path
=>
fixture_file
(
"5k.png"
)
path:
fixture_file
(
"5k.png"
)
)
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
...
@@ -129,10 +129,10 @@ describe Paperclip::UploadedFileAdapter do
...
@@ -129,10 +129,10 @@ describe Paperclip::UploadedFileAdapter do
class
UploadedFile
<
OpenStruct
;
end
class
UploadedFile
<
OpenStruct
;
end
@file
=
UploadedFile
.
new
(
@file
=
UploadedFile
.
new
(
:original_filename
=>
"5k.png"
,
original_filename:
"5k.png"
,
:content_type
=>
"image/x-png-by-browser"
,
content_type:
"image/x-png-by-browser"
,
:head
=>
""
,
head:
""
,
:path
=>
fixture_file
(
"5k.png"
)
path:
fixture_file
(
"5k.png"
)
)
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
...
...
spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb
View file @
40010c4d
...
@@ -25,7 +25,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
...
@@ -25,7 +25,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context
"given a class with a validation that doesn't match"
do
context
"given a class with a validation that doesn't match"
do
before
do
before
do
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{audio/.*}
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
%r{audio/.*}
end
end
should_reject_dummy_class
should_reject_dummy_class
...
@@ -33,7 +33,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
...
@@ -33,7 +33,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context
"given a class with a matching validation"
do
context
"given a class with a matching validation"
do
before
do
before
do
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{image/.*}
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
%r{image/.*}
end
end
should_accept_dummy_class
should_accept_dummy_class
...
@@ -42,7 +42,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
...
@@ -42,7 +42,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context
"given a class with other validations but matching types"
do
context
"given a class with other validations but matching types"
do
before
do
before
do
Dummy
.
validates_presence_of
:title
Dummy
.
validates_presence_of
:title
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{image/.*}
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
%r{image/.*}
end
end
should_accept_dummy_class
should_accept_dummy_class
...
@@ -50,7 +50,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
...
@@ -50,7 +50,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context
"given a class that matches and a matcher that only specifies 'allowing'"
do
context
"given a class that matches and a matcher that only specifies 'allowing'"
do
before
do
before
do
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{image/.*}
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
%r{image/.*}
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
allowing
(
%w(image/png image/jpeg)
)
allowing
(
%w(image/png image/jpeg)
)
end
end
...
@@ -60,7 +60,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
...
@@ -60,7 +60,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context
"given a class that does not match and a matcher that only specifies 'allowing'"
do
context
"given a class that does not match and a matcher that only specifies 'allowing'"
do
before
do
before
do
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{audio/.*}
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
%r{audio/.*}
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
allowing
(
%w(image/png image/jpeg)
)
allowing
(
%w(image/png image/jpeg)
)
end
end
...
@@ -70,7 +70,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
...
@@ -70,7 +70,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context
"given a class that matches and a matcher that only specifies 'rejecting'"
do
context
"given a class that matches and a matcher that only specifies 'rejecting'"
do
before
do
before
do
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{image/.*}
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
%r{image/.*}
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
rejecting
(
%w(audio/mp3 application/octet-stream)
)
rejecting
(
%w(audio/mp3 application/octet-stream)
)
end
end
...
@@ -80,7 +80,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
...
@@ -80,7 +80,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context
"given a class that does not match and a matcher that only specifies 'rejecting'"
do
context
"given a class that does not match and a matcher that only specifies 'rejecting'"
do
before
do
before
do
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{audio/.*}
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
%r{audio/.*}
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
rejecting
(
%w(audio/mp3 application/octet-stream)
)
rejecting
(
%w(audio/mp3 application/octet-stream)
)
end
end
...
@@ -91,7 +91,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
...
@@ -91,7 +91,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context
"using an :if to control the validation"
do
context
"using an :if to control the validation"
do
before
do
before
do
Dummy
.
class_eval
do
Dummy
.
class_eval
do
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{image/*}
,
:if
=>
:go
validates_attachment_content_type
:avatar
,
content_type:
%r{image/*}
,
if:
:go
attr_accessor
:go
attr_accessor
:go
end
end
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
@matcher
=
self
.
class
.
validate_attachment_content_type
(
:avatar
).
...
...
spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb
View file @
40010c4d
...
@@ -36,7 +36,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher do
...
@@ -36,7 +36,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher do
Dummy
.
class_eval
do
Dummy
.
class_eval
do
validates_attachment_presence
:avatar
validates_attachment_presence
:avatar
validates_attachment_content_type
:avatar
,
:content_type
=>
'image/gif'
validates_attachment_content_type
:avatar
,
content_type:
'image/gif'
end
end
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -52,7 +52,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher do
...
@@ -52,7 +52,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher do
context
"using an :if to control the validation"
do
context
"using an :if to control the validation"
do
before
do
before
do
Dummy
.
class_eval
do
Dummy
.
class_eval
do
validates_attachment_presence
:avatar
,
:if
=>
:go
validates_attachment_presence
:avatar
,
if:
:go
attr_accessor
:go
attr_accessor
:go
end
end
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
...
spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb
View file @
40010c4d
...
@@ -25,17 +25,17 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
...
@@ -25,17 +25,17 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
end
end
context
"given a class with a validation that's too high"
do
context
"given a class with a validation that's too high"
do
before
{
Dummy
.
validates_attachment_size
:avatar
,
:in
=>
256
..
2048
}
before
{
Dummy
.
validates_attachment_size
:avatar
,
in:
256
..
2048
}
should_reject_dummy_class
should_reject_dummy_class
end
end
context
"given a class with a validation that's too low"
do
context
"given a class with a validation that's too low"
do
before
{
Dummy
.
validates_attachment_size
:avatar
,
:in
=>
0
..
1024
}
before
{
Dummy
.
validates_attachment_size
:avatar
,
in:
0
..
1024
}
should_reject_dummy_class
should_reject_dummy_class
end
end
context
"given a class with a validation that matches"
do
context
"given a class with a validation that matches"
do
before
{
Dummy
.
validates_attachment_size
:avatar
,
:in
=>
256
..
1024
}
before
{
Dummy
.
validates_attachment_size
:avatar
,
in:
256
..
1024
}
should_accept_dummy_class
should_accept_dummy_class
end
end
end
end
...
@@ -46,12 +46,12 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
...
@@ -46,12 +46,12 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
end
end
context
"given a class with an upper limit"
do
context
"given a class with an upper limit"
do
before
{
Dummy
.
validates_attachment_size
:avatar
,
:less_than
=>
1
}
before
{
Dummy
.
validates_attachment_size
:avatar
,
less_than:
1
}
should_accept_dummy_class
should_accept_dummy_class
end
end
context
"given a class with a lower limit"
do
context
"given a class with a lower limit"
do
before
{
Dummy
.
validates_attachment_size
:avatar
,
:greater_than
=>
1
}
before
{
Dummy
.
validates_attachment_size
:avatar
,
greater_than:
1
}
should_accept_dummy_class
should_accept_dummy_class
end
end
end
end
...
@@ -59,7 +59,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
...
@@ -59,7 +59,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
context
"using an :if to control the validation"
do
context
"using an :if to control the validation"
do
before
do
before
do
Dummy
.
class_eval
do
Dummy
.
class_eval
do
validates_attachment_size
:avatar
,
:greater_than
=>
1024
,
:if
=>
:go
validates_attachment_size
:avatar
,
greater_than:
1024
,
if:
:go
attr_accessor
:go
attr_accessor
:go
end
end
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -79,7 +79,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
...
@@ -79,7 +79,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
context
"post processing"
do
context
"post processing"
do
before
do
before
do
Dummy
.
validates_attachment_size
:avatar
,
:greater_than
=>
1024
Dummy
.
validates_attachment_size
:avatar
,
greater_than:
1024
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@matcher
=
self
.
class
.
validate_attachment_size
(
:avatar
).
greater_than
(
1024
)
@matcher
=
self
.
class
.
validate_attachment_size
(
:avatar
).
greater_than
(
1024
)
...
...
spec/paperclip/paperclip_missing_attachment_styles_spec.rb
View file @
40010c4d
...
@@ -19,41 +19,41 @@ describe 'Missing Attachment Styles' do
...
@@ -19,41 +19,41 @@ describe 'Missing Attachment Styles' do
it
"be able to get current attachment styles"
do
it
"be able to get current attachment styles"
do
assert_equal
Hash
.
new
,
Paperclip
.
send
(
:current_attachments_styles
)
assert_equal
Hash
.
new
,
Paperclip
.
send
(
:current_attachments_styles
)
rebuild_model
:styles
=>
{
:croppable
=>
'600x600>'
,
:big
=>
'1000x1000>'
}
rebuild_model
styles:
{
croppable:
'600x600>'
,
big:
'1000x1000>'
}
expected_hash
=
{
:Dummy
=>
{
:avatar
=>
[
:big
,
:croppable
]}}
expected_hash
=
{
Dummy
:
{
avatar:
[
:big
,
:croppable
]}}
assert_equal
expected_hash
,
Paperclip
.
send
(
:current_attachments_styles
)
assert_equal
expected_hash
,
Paperclip
.
send
(
:current_attachments_styles
)
end
end
it
"be able to save current attachment styles for further comparison"
do
it
"be able to save current attachment styles for further comparison"
do
rebuild_model
:styles
=>
{
:croppable
=>
'600x600>'
,
:big
=>
'1000x1000>'
}
rebuild_model
styles:
{
croppable:
'600x600>'
,
big:
'1000x1000>'
}
Paperclip
.
save_current_attachments_styles!
Paperclip
.
save_current_attachments_styles!
expected_hash
=
{
:Dummy
=>
{
:avatar
=>
[
:big
,
:croppable
]}}
expected_hash
=
{
Dummy
:
{
avatar:
[
:big
,
:croppable
]}}
assert_equal
expected_hash
,
YAML
.
load_file
(
Paperclip
.
registered_attachments_styles_path
)
assert_equal
expected_hash
,
YAML
.
load_file
(
Paperclip
.
registered_attachments_styles_path
)
end
end
it
"be able to read registered attachment styles from file"
do
it
"be able to read registered attachment styles from file"
do
rebuild_model
:styles
=>
{
:croppable
=>
'600x600>'
,
:big
=>
'1000x1000>'
}
rebuild_model
styles:
{
croppable:
'600x600>'
,
big:
'1000x1000>'
}
Paperclip
.
save_current_attachments_styles!
Paperclip
.
save_current_attachments_styles!
expected_hash
=
{
:Dummy
=>
{
:avatar
=>
[
:big
,
:croppable
]}}
expected_hash
=
{
Dummy
:
{
avatar:
[
:big
,
:croppable
]}}
assert_equal
expected_hash
,
Paperclip
.
send
(
:get_registered_attachments_styles
)
assert_equal
expected_hash
,
Paperclip
.
send
(
:get_registered_attachments_styles
)
end
end
it
"be able to calculate differences between registered styles and current styles"
do
it
"be able to calculate differences between registered styles and current styles"
do
rebuild_model
:styles
=>
{
:croppable
=>
'600x600>'
,
:big
=>
'1000x1000>'
}
rebuild_model
styles:
{
croppable:
'600x600>'
,
big:
'1000x1000>'
}
Paperclip
.
save_current_attachments_styles!
Paperclip
.
save_current_attachments_styles!
rebuild_model
:styles
=>
{
:thumb
=>
'x100'
,
:export
=>
'x400>'
,
:croppable
=>
'600x600>'
,
:big
=>
'1000x1000>'
}
rebuild_model
styles:
{
thumb:
'x100'
,
export:
'x400>'
,
croppable:
'600x600>'
,
big:
'1000x1000>'
}
expected_hash
=
{
:Dummy
=>
{
:avatar
=>
[
:export
,
:thumb
]}
}
expected_hash
=
{
Dummy
:
{
avatar:
[
:export
,
:thumb
]}
}
assert_equal
expected_hash
,
Paperclip
.
missing_attachments_styles
assert_equal
expected_hash
,
Paperclip
.
missing_attachments_styles
ActiveRecord
::
Base
.
connection
.
create_table
:books
,
:force
=>
true
ActiveRecord
::
Base
.
connection
.
create_table
:books
,
force:
true
class
::
Book
<
ActiveRecord
::
Base
class
::
Book
<
ActiveRecord
::
Base
has_attached_file
:cover
,
:styles
=>
{
:small
=>
'x100'
,
:large
=>
'1000x1000>'
}
has_attached_file
:cover
,
styles:
{
small:
'x100'
,
large:
'1000x1000>'
}
has_attached_file
:sample
,
:styles
=>
{
:thumb
=>
'x100'
}
has_attached_file
:sample
,
styles:
{
thumb:
'x100'
}
end
end
expected_hash
=
{
expected_hash
=
{
:Dummy
=>
{
:avatar
=>
[
:export
,
:thumb
]},
Dummy
:
{
avatar:
[
:export
,
:thumb
]},
:Book
=>
{
:sample
=>
[
:thumb
],
:cover
=>
[
:large
,
:small
]}
Book
:
{
sample:
[
:thumb
],
cover:
[
:large
,
:small
]}
}
}
assert_equal
expected_hash
,
Paperclip
.
missing_attachments_styles
assert_equal
expected_hash
,
Paperclip
.
missing_attachments_styles
Paperclip
.
save_current_attachments_styles!
Paperclip
.
save_current_attachments_styles!
...
@@ -61,15 +61,15 @@ describe 'Missing Attachment Styles' do
...
@@ -61,15 +61,15 @@ describe 'Missing Attachment Styles' do
end
end
it
"be able to calculate differences when a new attachment is added to a model"
do
it
"be able to calculate differences when a new attachment is added to a model"
do
rebuild_model
:styles
=>
{
:croppable
=>
'600x600>'
,
:big
=>
'1000x1000>'
}
rebuild_model
styles:
{
croppable:
'600x600>'
,
big:
'1000x1000>'
}
Paperclip
.
save_current_attachments_styles!
Paperclip
.
save_current_attachments_styles!
class
::
Dummy
class
::
Dummy
has_attached_file
:photo
,
:styles
=>
{
:small
=>
'x100'
,
:large
=>
'1000x1000>'
}
has_attached_file
:photo
,
styles:
{
small:
'x100'
,
large:
'1000x1000>'
}
end
end
expected_hash
=
{
expected_hash
=
{
:Dummy
=>
{
:photo
=>
[
:large
,
:small
]}
Dummy
:
{
photo:
[
:large
,
:small
]}
}
}
assert_equal
expected_hash
,
Paperclip
.
missing_attachments_styles
assert_equal
expected_hash
,
Paperclip
.
missing_attachments_styles
Paperclip
.
save_current_attachments_styles!
Paperclip
.
save_current_attachments_styles!
...
@@ -78,7 +78,7 @@ describe 'Missing Attachment Styles' do
...
@@ -78,7 +78,7 @@ describe 'Missing Attachment Styles' do
# It's impossible to build styles hash without loading from database whole bunch of records
# It's impossible to build styles hash without loading from database whole bunch of records
it
"skip lambda-styles"
do
it
"skip lambda-styles"
do
rebuild_model
:styles
=>
lambda
{
|
attachment
|
attachment
.
instance
.
other
==
'a'
?
{:
thumb
=>
"50x50#"
}
:
{
:large
=>
"400x400"
}
}
rebuild_model
styles:
lambda
{
|
attachment
|
attachment
.
instance
.
other
==
'a'
?
{
thumb:
"50x50#"
}
:
{
large:
"400x400"
}
}
assert_equal
Hash
.
new
,
Paperclip
.
send
(
:current_attachments_styles
)
assert_equal
Hash
.
new
,
Paperclip
.
send
(
:current_attachments_styles
)
end
end
end
end
spec/paperclip/paperclip_spec.rb
View file @
40010c4d
...
@@ -61,7 +61,7 @@ describe Paperclip do
...
@@ -61,7 +61,7 @@ describe Paperclip do
context
"Calling Paperclip.run with a logger"
do
context
"Calling Paperclip.run with a logger"
do
it
"pass the defined logger if :log_command is set"
do
it
"pass the defined logger if :log_command is set"
do
Paperclip
.
options
[
:log_command
]
=
true
Paperclip
.
options
[
:log_command
]
=
true
Cocaine
::
CommandLine
.
expects
(
:new
).
with
(
"convert"
,
"stuff"
,
:logger
=>
Paperclip
.
logger
).
returns
(
stub
(
:run
))
Cocaine
::
CommandLine
.
expects
(
:new
).
with
(
"convert"
,
"stuff"
,
logger:
Paperclip
.
logger
).
returns
(
stub
(
:run
))
Paperclip
.
run
(
"convert"
,
"stuff"
)
Paperclip
.
run
(
"convert"
,
"stuff"
)
end
end
end
end
...
@@ -69,9 +69,9 @@ describe Paperclip do
...
@@ -69,9 +69,9 @@ describe Paperclip do
context
"Paperclip.each_instance_with_attachment"
do
context
"Paperclip.each_instance_with_attachment"
do
before
do
before
do
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
d1
=
Dummy
.
create
(
:avatar
=>
@file
)
d1
=
Dummy
.
create
(
avatar:
@file
)
d2
=
Dummy
.
create
d2
=
Dummy
.
create
d3
=
Dummy
.
create
(
:avatar
=>
@file
)
d3
=
Dummy
.
create
(
avatar:
@file
)
@expected
=
[
d1
,
d3
]
@expected
=
[
d1
,
d3
]
end
end
...
@@ -109,7 +109,7 @@ describe Paperclip do
...
@@ -109,7 +109,7 @@ describe Paperclip do
context
"An ActiveRecord model with an 'avatar' attachment"
do
context
"An ActiveRecord model with an 'avatar' attachment"
do
before
do
before
do
rebuild_model
:path
=>
"tmp/:class/omg/:style.:extension"
rebuild_model
path:
"tmp/:class/omg/:style.:extension"
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
end
end
...
@@ -133,8 +133,8 @@ describe Paperclip do
...
@@ -133,8 +133,8 @@ describe Paperclip do
end
end
it
"not assign the avatar on mass-set"
do
it
"not assign the avatar on mass-set"
do
@dummy
.
attributes
=
{
:other
=>
"I'm set!"
,
@dummy
.
attributes
=
{
other:
"I'm set!"
,
:avatar
=>
@file
}
avatar:
@file
}
assert_equal
"I'm set!"
,
@dummy
.
other
assert_equal
"I'm set!"
,
@dummy
.
other
assert
!
@dummy
.
avatar?
assert
!
@dummy
.
avatar?
...
@@ -157,7 +157,7 @@ describe Paperclip do
...
@@ -157,7 +157,7 @@ describe Paperclip do
it
"be able to use the attachment from the subclass"
do
it
"be able to use the attachment from the subclass"
do
assert_nothing_raised
do
assert_nothing_raised
do
@subdummy
=
SubDummy
.
create
(
:avatar
=>
@file
)
@subdummy
=
SubDummy
.
create
(
avatar:
@file
)
end
end
end
end
...
...
spec/paperclip/schema_spec.rb
View file @
40010c4d
...
@@ -19,7 +19,7 @@ describe Paperclip::Schema do
...
@@ -19,7 +19,7 @@ describe Paperclip::Schema do
ActiveSupport
::
Deprecation
.
silenced
=
false
ActiveSupport
::
Deprecation
.
silenced
=
false
end
end
it
"create attachment columns"
do
it
"create attachment columns"
do
Dummy
.
connection
.
create_table
:dummies
,
:force
=>
true
do
|
t
|
Dummy
.
connection
.
create_table
:dummies
,
force:
true
do
|
t
|
ActiveSupport
::
Deprecation
.
silence
do
ActiveSupport
::
Deprecation
.
silence
do
t
.
has_attached_file
:avatar
t
.
has_attached_file
:avatar
end
end
...
@@ -35,7 +35,7 @@ describe Paperclip::Schema do
...
@@ -35,7 +35,7 @@ describe Paperclip::Schema do
end
end
it
"display deprecation warning"
do
it
"display deprecation warning"
do
Dummy
.
connection
.
create_table
:dummies
,
:force
=>
true
do
|
t
|
Dummy
.
connection
.
create_table
:dummies
,
force:
true
do
|
t
|
assert_deprecated
do
assert_deprecated
do
t
.
has_attached_file
:avatar
t
.
has_attached_file
:avatar
end
end
...
@@ -45,7 +45,7 @@ describe Paperclip::Schema do
...
@@ -45,7 +45,7 @@ describe Paperclip::Schema do
context
"using #attachment"
do
context
"using #attachment"
do
before
do
before
do
Dummy
.
connection
.
create_table
:dummies
,
:force
=>
true
do
|
t
|
Dummy
.
connection
.
create_table
:dummies
,
force:
true
do
|
t
|
t
.
attachment
:avatar
t
.
attachment
:avatar
end
end
rebuild_class
rebuild_class
...
@@ -64,7 +64,7 @@ describe Paperclip::Schema do
...
@@ -64,7 +64,7 @@ describe Paperclip::Schema do
context
"within schema statement"
do
context
"within schema statement"
do
before
do
before
do
Dummy
.
connection
.
create_table
:dummies
,
:force
=>
true
Dummy
.
connection
.
create_table
:dummies
,
force:
true
end
end
context
"migrating up"
do
context
"migrating up"
do
...
...
spec/paperclip/storage/filesystem_spec.rb
View file @
40010c4d
...
@@ -4,7 +4,7 @@ describe Paperclip::Storage::Filesystem do
...
@@ -4,7 +4,7 @@ describe Paperclip::Storage::Filesystem do
context
"Filesystem"
do
context
"Filesystem"
do
context
"normal file"
do
context
"normal file"
do
before
do
before
do
rebuild_model
:styles
=>
{
:thumbnail
=>
"25x25#"
}
rebuild_model
styles:
{
thumbnail:
"25x25#"
}
@dummy
=
Dummy
.
create!
@dummy
=
Dummy
.
create!
@file
=
File
.
open
(
fixture_file
(
'5k.png'
))
@file
=
File
.
open
(
fixture_file
(
'5k.png'
))
...
@@ -53,7 +53,7 @@ describe Paperclip::Storage::Filesystem do
...
@@ -53,7 +53,7 @@ describe Paperclip::Storage::Filesystem do
context
"with file that has space in file name"
do
context
"with file that has space in file name"
do
before
do
before
do
rebuild_model
:styles
=>
{
:thumbnail
=>
"25x25#"
}
rebuild_model
styles:
{
thumbnail:
"25x25#"
}
@dummy
=
Dummy
.
create!
@dummy
=
Dummy
.
create!
@file
=
File
.
open
(
fixture_file
(
'spaced file.png'
))
@file
=
File
.
open
(
fixture_file
(
'spaced file.png'
))
...
...
spec/paperclip/storage/fog_spec.rb
View file @
40010c4d
...
@@ -7,11 +7,11 @@ describe Paperclip::Storage::Fog do
...
@@ -7,11 +7,11 @@ describe Paperclip::Storage::Fog do
context
"with credentials provided in a path string"
do
context
"with credentials provided in a path string"
do
before
do
before
do
rebuild_model
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
rebuild_model
styles:
{
medium:
"300x300>"
,
thumb:
"100x100>"
},
:storage
=>
:fog
,
storage:
:fog
,
:url
=>
'/:attachment/:filename'
,
url:
'/:attachment/:filename'
,
:fog_directory
=>
"paperclip"
,
fog_directory:
"paperclip"
,
:fog_credentials
=>
fixture_file
(
'fog.yml'
)
fog_credentials:
fixture_file
(
'fog.yml'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -26,11 +26,11 @@ describe Paperclip::Storage::Fog do
...
@@ -26,11 +26,11 @@ describe Paperclip::Storage::Fog do
context
"with credentials provided in a File object"
do
context
"with credentials provided in a File object"
do
before
do
before
do
rebuild_model
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
rebuild_model
styles:
{
medium:
"300x300>"
,
thumb:
"100x100>"
},
:storage
=>
:fog
,
storage:
:fog
,
:url
=>
'/:attachment/:filename'
,
url:
'/:attachment/:filename'
,
:fog_directory
=>
"paperclip"
,
fog_directory:
"paperclip"
,
:fog_credentials
=>
File
.
open
(
fixture_file
(
'fog.yml'
))
fog_credentials:
File
.
open
(
fixture_file
(
'fog.yml'
))
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -45,14 +45,14 @@ describe Paperclip::Storage::Fog do
...
@@ -45,14 +45,14 @@ describe Paperclip::Storage::Fog do
context
"with default values for path and url"
do
context
"with default values for path and url"
do
before
do
before
do
rebuild_model
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
rebuild_model
styles:
{
medium:
"300x300>"
,
thumb:
"100x100>"
},
:storage
=>
:fog
,
storage:
:fog
,
:url
=>
'/:attachment/:filename'
,
url:
'/:attachment/:filename'
,
:fog_directory
=>
"paperclip"
,
fog_directory:
"paperclip"
,
:fog_credentials
=>
{
fog_credentials:
{
:provider
=>
'AWS'
,
provider:
'AWS'
,
:aws_access_key_id
=>
'AWS_ID'
,
aws_access_key_id:
'AWS_ID'
,
:aws_secret_access_key
=>
'AWS_SECRET'
aws_secret_access_key:
'AWS_SECRET'
}
}
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -69,13 +69,13 @@ describe Paperclip::Storage::Fog do
...
@@ -69,13 +69,13 @@ describe Paperclip::Storage::Fog do
context
"with no path or url given and using defaults"
do
context
"with no path or url given and using defaults"
do
before
do
before
do
rebuild_model
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
rebuild_model
styles:
{
medium:
"300x300>"
,
thumb:
"100x100>"
},
:storage
=>
:fog
,
storage:
:fog
,
:fog_directory
=>
"paperclip"
,
fog_directory:
"paperclip"
,
:fog_credentials
=>
{
fog_credentials:
{
:provider
=>
'AWS'
,
provider:
'AWS'
,
:aws_access_key_id
=>
'AWS_ID'
,
aws_access_key_id:
'AWS_ID'
,
:aws_secret_access_key
=>
'AWS_SECRET'
aws_secret_access_key:
'AWS_SECRET'
}
}
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -92,9 +92,9 @@ describe Paperclip::Storage::Fog do
...
@@ -92,9 +92,9 @@ describe Paperclip::Storage::Fog do
context
"with file params provided as lambda"
do
context
"with file params provided as lambda"
do
before
do
before
do
fog_file
=
lambda
{
|
a
|
{
:custom_header
=>
a
.
instance
.
custom_method
}}
fog_file
=
lambda
{
|
a
|
{
custom_header:
a
.
instance
.
custom_method
}}
klass
=
rebuild_model
:storage
=>
:fog
,
klass
=
rebuild_model
storage:
:fog
,
:fog_file
=>
fog_file
fog_file:
fog_file
klass
.
class_eval
do
klass
.
class_eval
do
def
custom_method
def
custom_method
...
@@ -107,7 +107,7 @@ describe Paperclip::Storage::Fog do
...
@@ -107,7 +107,7 @@ describe Paperclip::Storage::Fog do
end
end
it
"be able to evaluate correct values for file headers"
do
it
"be able to evaluate correct values for file headers"
do
assert_equal
@dummy
.
avatar
.
send
(
:fog_file
),
{
:custom_header
=>
'foobar'
}
assert_equal
@dummy
.
avatar
.
send
(
:fog_file
),
{
custom_header:
'foobar'
}
end
end
end
end
...
@@ -115,23 +115,23 @@ describe Paperclip::Storage::Fog do
...
@@ -115,23 +115,23 @@ describe Paperclip::Storage::Fog do
@fog_directory
=
'papercliptests'
@fog_directory
=
'papercliptests'
@credentials
=
{
@credentials
=
{
:provider
=>
'AWS'
,
provider:
'AWS'
,
:aws_access_key_id
=>
'ID'
,
aws_access_key_id:
'ID'
,
:aws_secret_access_key
=>
'SECRET'
aws_secret_access_key:
'SECRET'
}
}
@connection
=
Fog
::
Storage
.
new
(
@credentials
)
@connection
=
Fog
::
Storage
.
new
(
@credentials
)
@connection
.
directories
.
create
(
@connection
.
directories
.
create
(
:key
=>
@fog_directory
key:
@fog_directory
)
)
@options
=
{
@options
=
{
:fog_directory
=>
@fog_directory
,
fog_directory:
@fog_directory
,
:fog_credentials
=>
@credentials
,
fog_credentials:
@credentials
,
:fog_host
=>
nil
,
fog_host:
nil
,
:fog_file
=>
{
:cache_control
=>
1234
},
fog_file:
{
cache_control:
1234
},
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:storage
=>
:fog
storage:
:fog
}
}
rebuild_model
(
@options
)
rebuild_model
(
@options
)
...
@@ -150,7 +150,7 @@ describe Paperclip::Storage::Fog do
...
@@ -150,7 +150,7 @@ describe Paperclip::Storage::Fog do
after
do
after
do
@file
.
close
@file
.
close
directory
=
@connection
.
directories
.
new
(
:key
=>
@fog_directory
)
directory
=
@connection
.
directories
.
new
(
key:
@fog_directory
)
directory
.
files
.
each
{
|
file
|
file
.
destroy
}
directory
.
files
.
each
{
|
file
|
file
.
destroy
}
directory
.
destroy
directory
.
destroy
end
end
...
@@ -207,7 +207,7 @@ describe Paperclip::Storage::Fog do
...
@@ -207,7 +207,7 @@ describe Paperclip::Storage::Fog do
context
"without a fog_host"
do
context
"without a fog_host"
do
before
do
before
do
rebuild_model
(
@options
.
merge
(
:fog_host
=>
nil
))
rebuild_model
(
@options
.
merge
(
fog_host:
nil
))
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
'.'
)
@dummy
.
avatar
=
StringIO
.
new
(
'.'
)
@dummy
.
save
@dummy
.
save
...
@@ -220,7 +220,7 @@ describe Paperclip::Storage::Fog do
...
@@ -220,7 +220,7 @@ describe Paperclip::Storage::Fog do
context
"with a fog_host"
do
context
"with a fog_host"
do
before
do
before
do
rebuild_model
(
@options
.
merge
(
:fog_host
=>
'http://example.com'
))
rebuild_model
(
@options
.
merge
(
fog_host:
'http://example.com'
))
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
".
\n
"
)
@dummy
.
avatar
=
StringIO
.
new
(
".
\n
"
)
@dummy
.
save
@dummy
.
save
...
@@ -234,11 +234,11 @@ describe Paperclip::Storage::Fog do
...
@@ -234,11 +234,11 @@ describe Paperclip::Storage::Fog do
context
"with a fog_host that includes a wildcard placeholder"
do
context
"with a fog_host that includes a wildcard placeholder"
do
before
do
before
do
rebuild_model
(
rebuild_model
(
:fog_directory
=>
@fog_directory
,
fog_directory:
@fog_directory
,
:fog_credentials
=>
@credentials
,
fog_credentials:
@credentials
,
:fog_host
=>
'http://img%d.example.com'
,
fog_host:
'http://img%d.example.com'
,
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:storage
=>
:fog
storage:
:fog
)
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
".
\n
"
)
@dummy
.
avatar
=
StringIO
.
new
(
".
\n
"
)
...
@@ -252,7 +252,7 @@ describe Paperclip::Storage::Fog do
...
@@ -252,7 +252,7 @@ describe Paperclip::Storage::Fog do
context
"with fog_public set to false"
do
context
"with fog_public set to false"
do
before
do
before
do
rebuild_model
(
@options
.
merge
(
:fog_public
=>
false
))
rebuild_model
(
@options
.
merge
(
fog_public:
false
))
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
'.'
)
@dummy
.
avatar
=
StringIO
.
new
(
'.'
)
@dummy
.
save
@dummy
.
save
...
@@ -266,7 +266,7 @@ describe Paperclip::Storage::Fog do
...
@@ -266,7 +266,7 @@ describe Paperclip::Storage::Fog do
context
"with styles set and fog_public set to false"
do
context
"with styles set and fog_public set to false"
do
before
do
before
do
rebuild_model
(
@options
.
merge
(
:fog_public
=>
false
,
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
}))
rebuild_model
(
@options
.
merge
(
fog_public:
false
,
styles:
{
medium:
"300x300>"
,
thumb:
"100x100>"
}))
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -281,7 +281,7 @@ describe Paperclip::Storage::Fog do
...
@@ -281,7 +281,7 @@ describe Paperclip::Storage::Fog do
context
"with styles set and fog_public set per-style"
do
context
"with styles set and fog_public set per-style"
do
before
do
before
do
rebuild_model
(
@options
.
merge
(
:fog_public
=>
{
:medium
=>
false
,
:thumb
=>
true
},
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
}))
rebuild_model
(
@options
.
merge
(
fog_public:
{
medium:
false
,
thumb:
true
},
styles:
{
medium:
"300x300>"
,
thumb:
"100x100>"
}))
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -339,7 +339,7 @@ describe Paperclip::Storage::Fog do
...
@@ -339,7 +339,7 @@ describe Paperclip::Storage::Fog do
context
"with an invalid bucket name for a subdomain"
do
context
"with an invalid bucket name for a subdomain"
do
before
do
before
do
rebuild_model
(
@options
.
merge
(
:fog_directory
=>
"this_is_invalid"
))
rebuild_model
(
@options
.
merge
(
fog_directory:
"this_is_invalid"
))
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
@dummy
.
save
@dummy
.
save
...
@@ -365,7 +365,7 @@ describe Paperclip::Storage::Fog do
...
@@ -365,7 +365,7 @@ describe Paperclip::Storage::Fog do
context
"with a proc for a bucket name evaluating a model method"
do
context
"with a proc for a bucket name evaluating a model method"
do
before
do
before
do
@dynamic_fog_directory
=
'dynamicpaperclip'
@dynamic_fog_directory
=
'dynamicpaperclip'
rebuild_model
(
@options
.
merge
(
:fog_directory
=>
lambda
{
|
attachment
|
attachment
.
instance
.
bucket_name
}))
rebuild_model
(
@options
.
merge
(
fog_directory:
lambda
{
|
attachment
|
attachment
.
instance
.
bucket_name
}))
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:bucket_name
).
returns
(
@dynamic_fog_directory
)
@dummy
.
stubs
(
:bucket_name
).
returns
(
@dynamic_fog_directory
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -380,7 +380,7 @@ describe Paperclip::Storage::Fog do
...
@@ -380,7 +380,7 @@ describe Paperclip::Storage::Fog do
context
"with a proc for the fog_host evaluating a model method"
do
context
"with a proc for the fog_host evaluating a model method"
do
before
do
before
do
rebuild_model
(
@options
.
merge
(
:fog_host
=>
lambda
{
|
attachment
|
attachment
.
instance
.
fog_host
}))
rebuild_model
(
@options
.
merge
(
fog_host:
lambda
{
|
attachment
|
attachment
.
instance
.
fog_host
}))
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:fog_host
).
returns
(
'http://dynamicfoghost.com'
)
@dummy
.
stubs
(
:fog_host
).
returns
(
'http://dynamicfoghost.com'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -395,7 +395,7 @@ describe Paperclip::Storage::Fog do
...
@@ -395,7 +395,7 @@ describe Paperclip::Storage::Fog do
context
"with a custom fog_host"
do
context
"with a custom fog_host"
do
before
do
before
do
rebuild_model
(
@options
.
merge
(
:fog_host
=>
"http://dynamicfoghost.com"
))
rebuild_model
(
@options
.
merge
(
fog_host:
"http://dynamicfoghost.com"
))
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
@dummy
.
save
@dummy
.
save
...
@@ -411,7 +411,7 @@ describe Paperclip::Storage::Fog do
...
@@ -411,7 +411,7 @@ describe Paperclip::Storage::Fog do
context
"with an invalid bucket name for a subdomain"
do
context
"with an invalid bucket name for a subdomain"
do
before
do
before
do
rebuild_model
(
@options
.
merge
({
:fog_directory
=>
"this_is_invalid"
,
:fog_host
=>
"http://dynamicfoghost.com"
}))
rebuild_model
(
@options
.
merge
({
fog_directory:
"this_is_invalid"
,
fog_host:
"http://dynamicfoghost.com"
}))
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
@dummy
.
save
@dummy
.
save
...
@@ -427,11 +427,11 @@ describe Paperclip::Storage::Fog do
...
@@ -427,11 +427,11 @@ describe Paperclip::Storage::Fog do
context
"with a proc for the fog_credentials evaluating a model method"
do
context
"with a proc for the fog_credentials evaluating a model method"
do
before
do
before
do
@dynamic_fog_credentials
=
{
@dynamic_fog_credentials
=
{
:provider
=>
'AWS'
,
provider:
'AWS'
,
:aws_access_key_id
=>
'DYNAMIC_ID'
,
aws_access_key_id:
'DYNAMIC_ID'
,
:aws_secret_access_key
=>
'DYNAMIC_SECRET'
aws_secret_access_key:
'DYNAMIC_SECRET'
}
}
rebuild_model
(
@options
.
merge
(
:fog_credentials
=>
lambda
{
|
attachment
|
attachment
.
instance
.
fog_credentials
}))
rebuild_model
(
@options
.
merge
(
fog_credentials:
lambda
{
|
attachment
|
attachment
.
instance
.
fog_credentials
}))
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:fog_credentials
).
returns
(
@dynamic_fog_credentials
)
@dummy
.
stubs
(
:fog_credentials
).
returns
(
@dynamic_fog_credentials
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
...
@@ -449,12 +449,12 @@ describe Paperclip::Storage::Fog do
...
@@ -449,12 +449,12 @@ describe Paperclip::Storage::Fog do
context
"when using local storage"
do
context
"when using local storage"
do
before
do
before
do
Fog
.
unmock!
Fog
.
unmock!
rebuild_model
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
rebuild_model
styles:
{
medium:
"300x300>"
,
thumb:
"100x100>"
},
:storage
=>
:fog
,
storage:
:fog
,
:url
=>
'/:attachment/:filename'
,
url:
'/:attachment/:filename'
,
:fog_directory
=>
"paperclip"
,
fog_directory:
"paperclip"
,
:fog_credentials
=>
{
:provider
=>
:local
,
:local_root
=>
"."
},
fog_credentials:
{
provider: :local
,
local_root:
"."
},
:fog_host
=>
'localhost'
fog_host:
'localhost'
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
...
spec/paperclip/storage/s3_live_spec.rb
View file @
40010c4d
...
@@ -4,13 +4,13 @@ unless ENV["S3_BUCKET"].blank?
...
@@ -4,13 +4,13 @@ unless ENV["S3_BUCKET"].blank?
describe
Paperclip
::
Storage
::
S3
,
'Live S3'
do
describe
Paperclip
::
Storage
::
S3
,
'Live S3'
do
context
"when assigning an S3 attachment directly to another model"
do
context
"when assigning an S3 attachment directly to another model"
do
before
do
before
do
rebuild_model
:styles
=>
{
:thumb
=>
"100x100"
,
:square
=>
"32x32#"
},
rebuild_model
styles:
{
thumb:
"100x100"
,
square:
"32x32#"
},
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
ENV
[
"S3_BUCKET"
],
bucket:
ENV
[
"S3_BUCKET"
],
:path
=>
":class/:attachment/:id/:style.:extension"
,
path:
":class/:attachment/:id/:style.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
:aws_access_key_id
=>
ENV
[
'AWS_ACCESS_KEY_ID'
],
aws_access_key_id:
ENV
[
'AWS_ACCESS_KEY_ID'
],
:aws_secre_access_key
=>
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
aws_secre_access_key:
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
}
}
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
...
@@ -41,13 +41,13 @@ unless ENV["S3_BUCKET"].blank?
...
@@ -41,13 +41,13 @@ unless ENV["S3_BUCKET"].blank?
context
"Generating an expiring url on a nonexistant attachment"
do
context
"Generating an expiring url on a nonexistant attachment"
do
before
do
before
do
rebuild_model
:styles
=>
{
:thumb
=>
"100x100"
,
:square
=>
"32x32#"
},
rebuild_model
styles:
{
thumb:
"100x100"
,
square:
"32x32#"
},
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
ENV
[
"S3_BUCKET"
],
bucket:
ENV
[
"S3_BUCKET"
],
:path
=>
":class/:attachment/:id/:style.:extension"
,
path:
":class/:attachment/:id/:style.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
:aws_access_key_id
=>
ENV
[
'AWS_ACCESS_KEY_ID'
],
aws_access_key_id:
ENV
[
'AWS_ACCESS_KEY_ID'
],
:aws_secre_access_key
=>
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
aws_secre_access_key:
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -60,13 +60,13 @@ unless ENV["S3_BUCKET"].blank?
...
@@ -60,13 +60,13 @@ unless ENV["S3_BUCKET"].blank?
context
"Using S3 for real, an attachment with S3 storage"
do
context
"Using S3 for real, an attachment with S3 storage"
do
before
do
before
do
rebuild_model
:styles
=>
{
:thumb
=>
"100x100"
,
:square
=>
"32x32#"
},
rebuild_model
styles:
{
thumb:
"100x100"
,
square:
"32x32#"
},
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
ENV
[
"S3_BUCKET"
],
bucket:
ENV
[
"S3_BUCKET"
],
:path
=>
":class/:attachment/:id/:style.:extension"
,
path:
":class/:attachment/:id/:style.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
:aws_access_key_id
=>
ENV
[
'AWS_ACCESS_KEY_ID'
],
aws_access_key_id:
ENV
[
'AWS_ACCESS_KEY_ID'
],
:aws_secre_access_key
=>
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
aws_secre_access_key:
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
}
}
Dummy
.
delete_all
Dummy
.
delete_all
...
@@ -102,12 +102,12 @@ unless ENV["S3_BUCKET"].blank?
...
@@ -102,12 +102,12 @@ unless ENV["S3_BUCKET"].blank?
context
"An attachment that uses S3 for storage and has spaces in file name"
do
context
"An attachment that uses S3 for storage and has spaces in file name"
do
before
do
before
do
rebuild_model
:styles
=>
{
:thumb
=>
"100x100"
,
:square
=>
"32x32#"
},
rebuild_model
styles:
{
thumb:
"100x100"
,
square:
"32x32#"
},
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
ENV
[
"S3_BUCKET"
],
bucket:
ENV
[
"S3_BUCKET"
],
:s3_credentials
=>
{
s3_credentials:
{
:aws_access_key_id
=>
ENV
[
'AWS_ACCESS_KEY_ID'
],
aws_access_key_id:
ENV
[
'AWS_ACCESS_KEY_ID'
],
:aws_secre_access_key
=>
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
aws_secre_access_key:
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
}
}
Dummy
.
delete_all
Dummy
.
delete_all
...
@@ -142,15 +142,15 @@ unless ENV["S3_BUCKET"].blank?
...
@@ -142,15 +142,15 @@ unless ENV["S3_BUCKET"].blank?
context
"An attachment that uses S3 for storage and uses AES256 encryption"
do
context
"An attachment that uses S3 for storage and uses AES256 encryption"
do
before
do
before
do
rebuild_model
:styles
=>
{
:thumb
=>
"100x100"
,
:square
=>
"32x32#"
},
rebuild_model
styles:
{
thumb:
"100x100"
,
square:
"32x32#"
},
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
ENV
[
"S3_BUCKET"
],
bucket:
ENV
[
"S3_BUCKET"
],
:path
=>
":class/:attachment/:id/:style.:extension"
,
path:
":class/:attachment/:id/:style.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
:aws_access_key_id
=>
ENV
[
'AWS_ACCESS_KEY_ID'
],
aws_access_key_id:
ENV
[
'AWS_ACCESS_KEY_ID'
],
:aws_secre_access_key
=>
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
aws_secre_access_key:
ENV
[
'AWS_SECRET_ACCESS_KEY'
]
},
},
:s3_server_side_encryption
=>
:aes256
s3_server_side_encryption:
:aes256
Dummy
.
delete_all
Dummy
.
delete_all
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
...
spec/paperclip/storage/s3_spec.rb
View file @
40010c4d
...
@@ -8,11 +8,11 @@ describe Paperclip::Storage::S3 do
...
@@ -8,11 +8,11 @@ describe Paperclip::Storage::S3 do
context
"Parsing S3 credentials"
do
context
"Parsing S3 credentials"
do
before
do
before
do
@proxy_settings
=
{
:host
=>
"127.0.0.1"
,
:port
=>
8888
,
:user
=>
"foo"
,
:password
=>
"bar"
}
@proxy_settings
=
{
host:
"127.0.0.1"
,
port:
8888
,
user:
"foo"
,
password:
"bar"
}
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:http_proxy
=>
@proxy_settings
,
http_proxy:
@proxy_settings
,
:s3_credentials
=>
{
:not
=>
:important
}
s3_credentials:
{
not:
:important
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@avatar
=
@dummy
.
avatar
@avatar
=
@dummy
.
avatar
...
@@ -20,23 +20,23 @@ describe Paperclip::Storage::S3 do
...
@@ -20,23 +20,23 @@ describe Paperclip::Storage::S3 do
it
"get the correct credentials when RAILS_ENV is production"
do
it
"get the correct credentials when RAILS_ENV is production"
do
rails_env
(
"production"
)
do
rails_env
(
"production"
)
do
assert_equal
({
:key
=>
"12345"
},
assert_equal
({
key:
"12345"
},
@avatar
.
parse_credentials
(
'production'
=>
{
:key
=>
'12345'
},
@avatar
.
parse_credentials
(
'production'
=>
{
key:
'12345'
},
:development
=>
{
:key
=>
"54321"
}))
development:
{
key:
"54321"
}))
end
end
end
end
it
"get the correct credentials when RAILS_ENV is development"
do
it
"get the correct credentials when RAILS_ENV is development"
do
rails_env
(
"development"
)
do
rails_env
(
"development"
)
do
assert_equal
({
:key
=>
"54321"
},
assert_equal
({
key:
"54321"
},
@avatar
.
parse_credentials
(
'production'
=>
{
:key
=>
'12345'
},
@avatar
.
parse_credentials
(
'production'
=>
{
key:
'12345'
},
:development
=>
{
:key
=>
"54321"
}))
development:
{
key:
"54321"
}))
end
end
end
end
it
"return the argument if the key does not exist"
do
it
"return the argument if the key does not exist"
do
rails_env
(
"not really an env"
)
do
rails_env
(
"not really an env"
)
do
assert_equal
({
:test
=>
"12345"
},
@avatar
.
parse_credentials
(
:test
=>
"12345"
))
assert_equal
({
test:
"12345"
},
@avatar
.
parse_credentials
(
test:
"12345"
))
end
end
end
end
...
@@ -55,7 +55,7 @@ describe Paperclip::Storage::S3 do
...
@@ -55,7 +55,7 @@ describe Paperclip::Storage::S3 do
context
":bucket option via :s3_credentials"
do
context
":bucket option via :s3_credentials"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
:s3_credentials
=>
{
:bucket
=>
'testing'
}
rebuild_model
storage: :s3
,
s3_credentials:
{
bucket:
'testing'
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
end
end
...
@@ -68,7 +68,7 @@ describe Paperclip::Storage::S3 do
...
@@ -68,7 +68,7 @@ describe Paperclip::Storage::S3 do
context
":bucket option"
do
context
":bucket option"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
:bucket
=>
"testing"
,
:s3_credentials
=>
{}
rebuild_model
storage: :s3
,
bucket:
"testing"
,
s3_credentials:
{}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
end
end
...
@@ -81,9 +81,9 @@ describe Paperclip::Storage::S3 do
...
@@ -81,9 +81,9 @@ describe Paperclip::Storage::S3 do
context
"missing :bucket option"
do
context
"missing :bucket option"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:http_proxy
=>
@proxy_settings
,
http_proxy:
@proxy_settings
,
:s3_credentials
=>
{
:not
=>
:important
}
s3_credentials:
{
not:
:important
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
stringy_file
@dummy
.
avatar
=
stringy_file
...
@@ -98,11 +98,11 @@ describe Paperclip::Storage::S3 do
...
@@ -98,11 +98,11 @@ describe Paperclip::Storage::S3 do
context
""
do
context
""
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{},
s3_credentials:
{},
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:url
=>
":s3_path_url"
url:
":s3_path_url"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
stringy_file
@dummy
.
avatar
=
stringy_file
end
end
...
@@ -124,7 +124,7 @@ describe Paperclip::Storage::S3 do
...
@@ -124,7 +124,7 @@ describe Paperclip::Storage::S3 do
[
"http"
,
:http
,
""
].
each
do
|
protocol
|
[
"http"
,
:http
,
""
].
each
do
|
protocol
|
context
"as
#{
protocol
.
inspect
}
"
do
context
"as
#{
protocol
.
inspect
}
"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
:s3_protocol
=>
protocol
rebuild_model
storage: :s3
,
s3_protocol:
protocol
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
end
end
...
@@ -136,13 +136,13 @@ describe Paperclip::Storage::S3 do
...
@@ -136,13 +136,13 @@ describe Paperclip::Storage::S3 do
end
end
end
end
context
"
:s3_protocol =>
'https'"
do
context
"
s3_protocol:
'https'"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{},
s3_credentials:
{},
:s3_protocol
=>
'https'
,
s3_protocol:
'https'
,
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:basename.:extension"
path:
":attachment/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
stringy_file
@dummy
.
avatar
=
stringy_file
end
end
...
@@ -152,13 +152,13 @@ describe Paperclip::Storage::S3 do
...
@@ -152,13 +152,13 @@ describe Paperclip::Storage::S3 do
end
end
end
end
context
"
:s3_protocol =>
:https"
do
context
"
s3_protocol:
:https"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{},
s3_credentials:
{},
:s3_protocol
=>
:https
,
s3_protocol:
:https
,
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:basename.:extension"
path:
":attachment/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
stringy_file
@dummy
.
avatar
=
stringy_file
end
end
...
@@ -168,13 +168,13 @@ describe Paperclip::Storage::S3 do
...
@@ -168,13 +168,13 @@ describe Paperclip::Storage::S3 do
end
end
end
end
context
"
:s3_protocol =>
''"
do
context
"
s3_protocol:
''"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{},
s3_credentials:
{},
:s3_protocol
=>
''
,
s3_protocol:
''
,
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:basename.:extension"
path:
":attachment/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
stringy_file
@dummy
.
avatar
=
stringy_file
end
end
...
@@ -186,13 +186,13 @@ describe Paperclip::Storage::S3 do
...
@@ -186,13 +186,13 @@ describe Paperclip::Storage::S3 do
context
"An attachment that uses S3 for storage and has the style in the path"
do
context
"An attachment that uses S3 for storage and has the style in the path"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:styles
=>
{
styles:
{
:thumb
=>
"80x80>"
thumb:
"80x80>"
},
},
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
}
}
...
@@ -213,11 +213,11 @@ describe Paperclip::Storage::S3 do
...
@@ -213,11 +213,11 @@ describe Paperclip::Storage::S3 do
context
"s3_host_name"
do
context
"s3_host_name"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{},
s3_credentials:
{},
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:s3_host_name
=>
"s3-ap-northeast-1.amazonaws.com"
s3_host_name:
"s3-ap-northeast-1.amazonaws.com"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
stringy_file
@dummy
.
avatar
=
stringy_file
end
end
...
@@ -233,11 +233,11 @@ describe Paperclip::Storage::S3 do
...
@@ -233,11 +233,11 @@ describe Paperclip::Storage::S3 do
context
"dynamic s3_host_name"
do
context
"dynamic s3_host_name"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{},
s3_credentials:
{},
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:s3_host_name
=>
lambda
{
|
a
|
a
.
instance
.
value
}
s3_host_name:
lambda
{
|
a
|
a
.
instance
.
value
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
class
<<
@dummy
class
<<
@dummy
attr_accessor
:value
attr_accessor
:value
...
@@ -247,17 +247,17 @@ describe Paperclip::Storage::S3 do
...
@@ -247,17 +247,17 @@ describe Paperclip::Storage::S3 do
it
"use s3_host_name as a proc if available"
do
it
"use s3_host_name as a proc if available"
do
@dummy
.
value
=
"s3.something.com"
@dummy
.
value
=
"s3.something.com"
assert_equal
"http://s3.something.com/bucket/avatars/data.txt"
,
@dummy
.
avatar
.
url
(
:original
,
:timestamp
=>
false
)
assert_equal
"http://s3.something.com/bucket/avatars/data.txt"
,
@dummy
.
avatar
.
url
(
:original
,
timestamp:
false
)
end
end
end
end
context
"An attachment that uses S3 for storage and has styles that return different file types"
do
context
"An attachment that uses S3 for storage and has styles that return different file types"
do
before
do
before
do
rebuild_model
:styles
=>
{
:large
=>
[
'500x500#'
,
:jpg
]
},
rebuild_model
styles:
{
large:
[
'500x500#'
,
:jpg
]
},
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
}
}
...
@@ -287,11 +287,11 @@ describe Paperclip::Storage::S3 do
...
@@ -287,11 +287,11 @@ describe Paperclip::Storage::S3 do
context
"An attachment that uses S3 for storage and has a proc for styles"
do
context
"An attachment that uses S3 for storage and has a proc for styles"
do
before
do
before
do
rebuild_model
:styles
=>
lambda
{
|
attachment
|
attachment
.
instance
.
counter
;
{
:thumbnail
=>
{
:geometry
=>
"50x50#"
,
:s3_headers
=>
{
'Cache-Control'
=>
'max-age=31557600'
}}
}},
rebuild_model
styles:
lambda
{
|
attachment
|
attachment
.
instance
.
counter
;
{
thumbnail:
{
geometry:
"50x50#"
,
s3_headers:
{
'Cache-Control'
=>
'max-age=31557600'
}}
}},
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
}
}
...
@@ -312,8 +312,8 @@ describe Paperclip::Storage::S3 do
...
@@ -312,8 +312,8 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
:original
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
:original
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
:thumbnail
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
:thumbnail
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
'image/png'
,
:acl
=>
:public_read
)
object
.
expects
(
:write
).
with
(
anything
,
content_type:
'image/png'
,
acl:
:public_read
)
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
'image/png'
,
:acl
=>
:public_read
,
:cache_control
=>
'max-age=31557600'
)
object
.
expects
(
:write
).
with
(
anything
,
content_type:
'image/png'
,
acl: :public_read
,
cache_control:
'max-age=31557600'
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -326,10 +326,10 @@ describe Paperclip::Storage::S3 do
...
@@ -326,10 +326,10 @@ describe Paperclip::Storage::S3 do
context
"An attachment that uses S3 for storage and has spaces in file name"
do
context
"An attachment that uses S3 for storage and has spaces in file name"
do
before
do
before
do
rebuild_model
:styles
=>
{
:large
=>
[
'500x500#'
,
:jpg
]
},
rebuild_model
styles:
{
large:
[
'500x500#'
,
:jpg
]
},
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
}
}
...
@@ -351,10 +351,10 @@ describe Paperclip::Storage::S3 do
...
@@ -351,10 +351,10 @@ describe Paperclip::Storage::S3 do
context
"An attachment that uses S3 for storage and has a question mark in file name"
do
context
"An attachment that uses S3 for storage and has a question mark in file name"
do
before
do
before
do
rebuild_model
:styles
=>
{
:large
=>
[
'500x500#'
,
:jpg
]
},
rebuild_model
styles:
{
large:
[
'500x500#'
,
:jpg
]
},
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
}
}
...
@@ -382,11 +382,11 @@ describe Paperclip::Storage::S3 do
...
@@ -382,11 +382,11 @@ describe Paperclip::Storage::S3 do
context
""
do
context
""
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{},
s3_credentials:
{},
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:url
=>
":s3_domain_url"
url:
":s3_domain_url"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
stringy_file
@dummy
.
avatar
=
stringy_file
end
end
...
@@ -398,14 +398,14 @@ describe Paperclip::Storage::S3 do
...
@@ -398,14 +398,14 @@ describe Paperclip::Storage::S3 do
context
""
do
context
""
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{
s3_credentials:
{
:production
=>
{
:bucket
=>
"prod_bucket"
},
production:
{
bucket:
"prod_bucket"
},
:development
=>
{
:bucket
=>
"dev_bucket"
}
development:
{
bucket:
"dev_bucket"
}
},
},
:s3_host_alias
=>
"something.something.com"
,
s3_host_alias:
"something.something.com"
,
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:url
=>
":s3_alias_url"
url:
":s3_alias_url"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
stringy_file
@dummy
.
avatar
=
stringy_file
end
end
...
@@ -417,11 +417,11 @@ describe Paperclip::Storage::S3 do
...
@@ -417,11 +417,11 @@ describe Paperclip::Storage::S3 do
context
"generating a url with a proc as the host alias"
do
context
"generating a url with a proc as the host alias"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{
:bucket
=>
"prod_bucket"
},
s3_credentials:
{
bucket:
"prod_bucket"
},
:s3_host_alias
=>
Proc
.
new
{
|
atch
|
"cdn
#{
atch
.
instance
.
counter
%
4
}
.example.com"
},
s3_host_alias:
Proc
.
new
{
|
atch
|
"cdn
#{
atch
.
instance
.
counter
%
4
}
.example.com"
},
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:url
=>
":s3_alias_url"
url:
":s3_alias_url"
Dummy
.
class_eval
do
Dummy
.
class_eval
do
def
counter
def
counter
@counter
||=
0
@counter
||=
0
...
@@ -446,11 +446,11 @@ describe Paperclip::Storage::S3 do
...
@@ -446,11 +446,11 @@ describe Paperclip::Storage::S3 do
context
""
do
context
""
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{},
s3_credentials:
{},
:bucket
=>
"bucket"
,
bucket:
"bucket"
,
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:url
=>
":asset_host"
url:
":asset_host"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
stringy_file
@dummy
.
avatar
=
stringy_file
end
end
...
@@ -465,15 +465,15 @@ describe Paperclip::Storage::S3 do
...
@@ -465,15 +465,15 @@ describe Paperclip::Storage::S3 do
before
do
before
do
@build_model_with_options
=
lambda
{
|
options
|
@build_model_with_options
=
lambda
{
|
options
|
base_options
=
{
base_options
=
{
:storage
=>
:s3
,
storage:
:s3
,
:s3_credentials
=>
{
s3_credentials:
{
:production
=>
{
:bucket
=>
"prod_bucket"
},
production:
{
bucket:
"prod_bucket"
},
:development
=>
{
:bucket
=>
"dev_bucket"
}
development:
{
bucket:
"dev_bucket"
}
},
},
:s3_host_alias
=>
"something.something.com"
,
s3_host_alias:
"something.something.com"
,
:s3_permissions
=>
"private"
,
s3_permissions:
"private"
,
:path
=>
":attachment/:basename.:extension"
,
path:
":attachment/:basename.:extension"
,
:url
=>
":s3_alias_url"
url:
":s3_alias_url"
}
}
rebuild_model
base_options
.
merge
(
options
)
rebuild_model
base_options
.
merge
(
options
)
...
@@ -489,14 +489,14 @@ describe Paperclip::Storage::S3 do
...
@@ -489,14 +489,14 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:url_for
).
with
(
:read
,
:expires
=>
3600
,
:secure
=>
true
)
object
.
expects
(
:url_for
).
with
(
:read
,
expires:
3600
,
secure:
true
)
@dummy
.
avatar
.
expiring_url
@dummy
.
avatar
.
expiring_url
end
end
end
end
it
"allow overriding s3_url_options"
do
it
"allow overriding s3_url_options"
do
@build_model_with_options
[
:s3_url_options
=>
{
:response_content_disposition
=>
"inline"
}]
@build_model_with_options
[
s3_url_options:
{
response_content_disposition:
"inline"
}]
rails_env
(
"production"
)
do
rails_env
(
"production"
)
do
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -504,14 +504,14 @@ describe Paperclip::Storage::S3 do
...
@@ -504,14 +504,14 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:url_for
).
with
(
:read
,
:expires
=>
3600
,
:secure
=>
true
,
:response_content_disposition
=>
"inline"
)
object
.
expects
(
:url_for
).
with
(
:read
,
expires:
3600
,
secure:
true
,
response_content_disposition:
"inline"
)
@dummy
.
avatar
.
expiring_url
@dummy
.
avatar
.
expiring_url
end
end
end
end
it
"allow overriding s3_object options with a proc"
do
it
"allow overriding s3_object options with a proc"
do
@build_model_with_options
[
:s3_url_options
=>
lambda
{
|
attachment
|
{
:response_content_type
=>
attachment
.
avatar_content_type
}
}]
@build_model_with_options
[
s3_url_options:
lambda
{
|
attachment
|
{
response_content_type:
attachment
.
avatar_content_type
}
}]
rails_env
(
"production"
)
do
rails_env
(
"production"
)
do
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -526,7 +526,7 @@ describe Paperclip::Storage::S3 do
...
@@ -526,7 +526,7 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:url_for
).
with
(
:read
,
:expires
=>
3600
,
:secure
=>
true
,
:response_content_type
=>
"image/png"
)
object
.
expects
(
:url_for
).
with
(
:read
,
expires:
3600
,
secure:
true
,
response_content_type:
"image/png"
)
@dummy
.
avatar
.
expiring_url
@dummy
.
avatar
.
expiring_url
end
end
...
@@ -555,15 +555,15 @@ describe Paperclip::Storage::S3 do
...
@@ -555,15 +555,15 @@ describe Paperclip::Storage::S3 do
context
"Generating a url with an expiration for each style"
do
context
"Generating a url with an expiration for each style"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{
s3_credentials:
{
:production
=>
{
:bucket
=>
"prod_bucket"
},
production:
{
bucket:
"prod_bucket"
},
:development
=>
{
:bucket
=>
"dev_bucket"
}
development:
{
bucket:
"dev_bucket"
}
},
},
:s3_permissions
=>
:private
,
s3_permissions:
:private
,
:s3_host_alias
=>
"something.something.com"
,
s3_host_alias:
"something.something.com"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:url
=>
":s3_alias_url"
url:
":s3_alias_url"
rails_env
(
"production"
)
do
rails_env
(
"production"
)
do
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -574,24 +574,24 @@ describe Paperclip::Storage::S3 do
...
@@ -574,24 +574,24 @@ describe Paperclip::Storage::S3 do
it
"should generate a url for the thumb"
do
it
"should generate a url for the thumb"
do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
:thumb
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
:thumb
).
returns
(
object
)
object
.
expects
(
:url_for
).
with
(
:read
,
:expires
=>
1800
,
:secure
=>
true
)
object
.
expects
(
:url_for
).
with
(
:read
,
expires:
1800
,
secure:
true
)
@dummy
.
avatar
.
expiring_url
(
1800
,
:thumb
)
@dummy
.
avatar
.
expiring_url
(
1800
,
:thumb
)
end
end
it
"should generate a url for the default style"
do
it
"should generate a url for the default style"
do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
:original
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
:original
).
returns
(
object
)
object
.
expects
(
:url_for
).
with
(
:read
,
:expires
=>
1800
,
:secure
=>
true
)
object
.
expects
(
:url_for
).
with
(
:read
,
expires:
1800
,
secure:
true
)
@dummy
.
avatar
.
expiring_url
(
1800
)
@dummy
.
avatar
.
expiring_url
(
1800
)
end
end
end
end
context
"Parsing S3 credentials with a bucket in them"
do
context
"Parsing S3 credentials with a bucket in them"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
{
s3_credentials:
{
:production
=>
{
:bucket
=>
"prod_bucket"
},
production:
{
bucket:
"prod_bucket"
},
:development
=>
{
:bucket
=>
"dev_bucket"
}
development:
{
bucket:
"dev_bucket"
}
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
end
end
...
@@ -613,11 +613,11 @@ describe Paperclip::Storage::S3 do
...
@@ -613,11 +613,11 @@ describe Paperclip::Storage::S3 do
context
"Parsing S3 credentials with a s3_host_name in them"
do
context
"Parsing S3 credentials with a s3_host_name in them"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
'testing'
,
bucket:
'testing'
,
:s3_credentials
=>
{
s3_credentials:
{
:production
=>
{
:s3_host_name
=>
"s3-world-end.amazonaws.com"
},
production:
{
s3_host_name:
"s3-world-end.amazonaws.com"
},
:development
=>
{
:s3_host_name
=>
"s3-ap-northeast-1.amazonaws.com"
}
development:
{
s3_host_name:
"s3-ap-northeast-1.amazonaws.com"
}
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
end
end
...
@@ -646,12 +646,12 @@ describe Paperclip::Storage::S3 do
...
@@ -646,12 +646,12 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage"
do
context
"An attachment with S3 storage"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
:aws_access_key_id
=>
"12345"
,
aws_access_key_id:
"12345"
,
:aws_secret_access_key
=>
"54321"
aws_secret_access_key:
"54321"
}
}
end
end
...
@@ -700,8 +700,8 @@ describe Paperclip::Storage::S3 do
...
@@ -700,8 +700,8 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
)
acl:
:public_read
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -715,8 +715,8 @@ describe Paperclip::Storage::S3 do
...
@@ -715,8 +715,8 @@ describe Paperclip::Storage::S3 do
AWS
::
S3
::
BucketCollection
.
any_instance
.
expects
(
:create
).
with
(
"testing"
)
AWS
::
S3
::
BucketCollection
.
any_instance
.
expects
(
:create
).
with
(
"testing"
)
AWS
::
S3
::
S3Object
.
any_instance
.
stubs
(
:write
).
AWS
::
S3
::
S3Object
.
any_instance
.
stubs
(
:write
).
raises
(
AWS
::
S3
::
Errors
::
NoSuchBucket
.
new
(
stub
,
raises
(
AWS
::
S3
::
Errors
::
NoSuchBucket
.
new
(
stub
,
stub
(
:status
=>
404
,
stub
(
status:
404
,
:body
=>
"<foo/>"
))).
body:
"<foo/>"
))).
then
.
returns
(
nil
)
then
.
returns
(
nil
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -752,31 +752,31 @@ describe Paperclip::Storage::S3 do
...
@@ -752,31 +752,31 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and bucket defined as a Proc"
do
context
"An attachment with S3 storage and bucket defined as a Proc"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
lambda
{
|
attachment
|
"bucket_
#{
attachment
.
instance
.
other
}
"
},
bucket:
lambda
{
|
attachment
|
"bucket_
#{
attachment
.
instance
.
other
}
"
},
:s3_credentials
=>
{
:not
=>
:important
}
s3_credentials:
{
not:
:important
}
end
end
it
"get the right bucket name"
do
it
"get the right bucket name"
do
assert
"bucket_a"
,
Dummy
.
new
(
:other
=>
'a'
).
avatar
.
bucket_name
assert
"bucket_a"
,
Dummy
.
new
(
other:
'a'
).
avatar
.
bucket_name
assert
"bucket_a"
,
Dummy
.
new
(
:other
=>
'a'
).
avatar
.
s3_bucket
.
name
assert
"bucket_a"
,
Dummy
.
new
(
other:
'a'
).
avatar
.
s3_bucket
.
name
assert
"bucket_b"
,
Dummy
.
new
(
:other
=>
'b'
).
avatar
.
bucket_name
assert
"bucket_b"
,
Dummy
.
new
(
other:
'b'
).
avatar
.
bucket_name
assert
"bucket_b"
,
Dummy
.
new
(
:other
=>
'b'
).
avatar
.
s3_bucket
.
name
assert
"bucket_b"
,
Dummy
.
new
(
other:
'b'
).
avatar
.
s3_bucket
.
name
end
end
end
end
context
"An attachment with S3 storage and S3 credentials defined as a Proc"
do
context
"An attachment with S3 storage and S3 credentials defined as a Proc"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
{
:not
=>
:important
},
bucket:
{
not:
:important
},
:s3_credentials
=>
lambda
{
|
attachment
|
s3_credentials:
lambda
{
|
attachment
|
Hash
[
'access_key_id'
=>
"access
#{
attachment
.
instance
.
other
}
"
,
'secret_access_key'
=>
"secret
#{
attachment
.
instance
.
other
}
"
]
Hash
[
'access_key_id'
=>
"access
#{
attachment
.
instance
.
other
}
"
,
'secret_access_key'
=>
"secret
#{
attachment
.
instance
.
other
}
"
]
}
}
end
end
it
"get the right credentials"
do
it
"get the right credentials"
do
assert
"access1234"
,
Dummy
.
new
(
:other
=>
'1234'
).
avatar
.
s3_credentials
[
:access_key_id
]
assert
"access1234"
,
Dummy
.
new
(
other:
'1234'
).
avatar
.
s3_credentials
[
:access_key_id
]
assert
"secret1234"
,
Dummy
.
new
(
:other
=>
'1234'
).
avatar
.
s3_credentials
[
:secret_access_key
]
assert
"secret1234"
,
Dummy
.
new
(
other:
'1234'
).
avatar
.
s3_credentials
[
:secret_access_key
]
end
end
end
end
...
@@ -784,10 +784,10 @@ describe Paperclip::Storage::S3 do
...
@@ -784,10 +784,10 @@ describe Paperclip::Storage::S3 do
before
do
before
do
class
DummyCredentialProvider
;
end
class
DummyCredentialProvider
;
end
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:s3_credentials
=>
{
s3_credentials:
{
:credential_provider
=>
DummyCredentialProvider
.
new
credential_provider:
DummyCredentialProvider
.
new
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
end
end
...
@@ -799,7 +799,7 @@ describe Paperclip::Storage::S3 do
...
@@ -799,7 +799,7 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and S3 credentials in an unsupported manor"
do
context
"An attachment with S3 storage and S3 credentials in an unsupported manor"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
:bucket
=>
"testing"
,
:s3_credentials
=>
[
"unsupported"
]
rebuild_model
storage: :s3
,
bucket:
"testing"
,
s3_credentials:
[
"unsupported"
]
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
end
end
...
@@ -812,7 +812,7 @@ describe Paperclip::Storage::S3 do
...
@@ -812,7 +812,7 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and S3 credentials not supplied"
do
context
"An attachment with S3 storage and S3 credentials not supplied"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
:bucket
=>
"testing"
rebuild_model
storage: :s3
,
bucket:
"testing"
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
end
end
...
@@ -823,14 +823,14 @@ describe Paperclip::Storage::S3 do
...
@@ -823,14 +823,14 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and specific s3 headers set"
do
context
"An attachment with S3 storage and specific s3 headers set"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_headers
=>
{
'Cache-Control'
=>
'max-age=31557600'
}
s3_headers:
{
'Cache-Control'
=>
'max-age=31557600'
}
end
end
context
"when assigned"
do
context
"when assigned"
do
...
@@ -847,9 +847,9 @@ describe Paperclip::Storage::S3 do
...
@@ -847,9 +847,9 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
,
acl:
:public_read
,
:cache_control
=>
'max-age=31557600'
)
cache_control:
'max-age=31557600'
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -862,14 +862,14 @@ describe Paperclip::Storage::S3 do
...
@@ -862,14 +862,14 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and metadata set using header names"
do
context
"An attachment with S3 storage and metadata set using header names"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_headers
=>
{
'x-amz-meta-color'
=>
'red'
}
s3_headers:
{
'x-amz-meta-color'
=>
'red'
}
end
end
context
"when assigned"
do
context
"when assigned"
do
...
@@ -886,9 +886,9 @@ describe Paperclip::Storage::S3 do
...
@@ -886,9 +886,9 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
,
acl:
:public_read
,
:metadata
=>
{
"color"
=>
"red"
})
metadata:
{
"color"
=>
"red"
})
@dummy
.
save
@dummy
.
save
end
end
...
@@ -901,14 +901,14 @@ describe Paperclip::Storage::S3 do
...
@@ -901,14 +901,14 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and metadata set using the :s3_metadata option"
do
context
"An attachment with S3 storage and metadata set using the :s3_metadata option"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_metadata
=>
{
"color"
=>
"red"
}
s3_metadata:
{
"color"
=>
"red"
}
end
end
context
"when assigned"
do
context
"when assigned"
do
...
@@ -925,9 +925,9 @@ describe Paperclip::Storage::S3 do
...
@@ -925,9 +925,9 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
,
acl:
:public_read
,
:metadata
=>
{
"color"
=>
"red"
})
metadata:
{
"color"
=>
"red"
})
@dummy
.
save
@dummy
.
save
end
end
...
@@ -940,14 +940,14 @@ describe Paperclip::Storage::S3 do
...
@@ -940,14 +940,14 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and storage class set using the header name"
do
context
"An attachment with S3 storage and storage class set using the header name"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_headers
=>
{
"x-amz-storage-class"
=>
"reduced_redundancy"
}
s3_headers:
{
"x-amz-storage-class"
=>
"reduced_redundancy"
}
end
end
context
"when assigned"
do
context
"when assigned"
do
...
@@ -964,9 +964,9 @@ describe Paperclip::Storage::S3 do
...
@@ -964,9 +964,9 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
,
acl:
:public_read
,
:storage_class
=>
"reduced_redundancy"
)
storage_class:
"reduced_redundancy"
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -981,13 +981,13 @@ describe Paperclip::Storage::S3 do
...
@@ -981,13 +981,13 @@ describe Paperclip::Storage::S3 do
[
nil
,
false
,
''
].
each
do
|
tech
|
[
nil
,
false
,
''
].
each
do
|
tech
|
before
do
before
do
rebuild_model
(
rebuild_model
(
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
},
'secret_access_key'
=>
"54321"
},
:s3_server_side_encryption
=>
tech
)
s3_server_side_encryption:
tech
)
end
end
context
"when assigned"
do
context
"when assigned"
do
...
@@ -1004,8 +1004,8 @@ describe Paperclip::Storage::S3 do
...
@@ -1004,8 +1004,8 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
)
acl:
:public_read
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -1019,14 +1019,14 @@ describe Paperclip::Storage::S3 do
...
@@ -1019,14 +1019,14 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and using AES256 encryption"
do
context
"An attachment with S3 storage and using AES256 encryption"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_server_side_encryption
=>
:aes256
s3_server_side_encryption:
:aes256
end
end
context
"when assigned"
do
context
"when assigned"
do
...
@@ -1043,9 +1043,9 @@ describe Paperclip::Storage::S3 do
...
@@ -1043,9 +1043,9 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
,
acl:
:public_read
,
:server_side_encryption
=>
'AES256'
)
server_side_encryption:
'AES256'
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -1058,14 +1058,14 @@ describe Paperclip::Storage::S3 do
...
@@ -1058,14 +1058,14 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and storage class set using the :storage_class option"
do
context
"An attachment with S3 storage and storage class set using the :storage_class option"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_storage_class
=>
:reduced_redundancy
s3_storage_class:
:reduced_redundancy
end
end
context
"when assigned"
do
context
"when assigned"
do
...
@@ -1082,9 +1082,9 @@ describe Paperclip::Storage::S3 do
...
@@ -1082,9 +1082,9 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
,
acl:
:public_read
,
:storage_class
=>
:reduced_redundancy
)
storage_class:
:reduced_redundancy
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -1102,8 +1102,8 @@ describe Paperclip::Storage::S3 do
...
@@ -1102,8 +1102,8 @@ describe Paperclip::Storage::S3 do
ENV
[
'S3_SECRET'
]
=
'pathname_secret'
ENV
[
'S3_SECRET'
]
=
'pathname_secret'
rails_env
(
'test'
)
do
rails_env
(
'test'
)
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
Pathname
.
new
(
fixture_file
(
's3.yml'
))
s3_credentials:
Pathname
.
new
(
fixture_file
(
's3.yml'
))
Dummy
.
delete_all
Dummy
.
delete_all
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
...
@@ -1124,8 +1124,8 @@ describe Paperclip::Storage::S3 do
...
@@ -1124,8 +1124,8 @@ describe Paperclip::Storage::S3 do
ENV
[
'S3_SECRET'
]
=
'env_secret'
ENV
[
'S3_SECRET'
]
=
'env_secret'
rails_env
(
'test'
)
do
rails_env
(
'test'
)
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:s3_credentials
=>
File
.
new
(
fixture_file
(
's3.yml'
))
s3_credentials:
File
.
new
(
fixture_file
(
's3.yml'
))
Dummy
.
delete_all
Dummy
.
delete_all
...
@@ -1143,10 +1143,10 @@ describe Paperclip::Storage::S3 do
...
@@ -1143,10 +1143,10 @@ describe Paperclip::Storage::S3 do
context
"S3 Permissions"
do
context
"S3 Permissions"
do
context
"defaults to :public_read"
do
context
"defaults to :public_read"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
}
}
...
@@ -1166,8 +1166,8 @@ describe Paperclip::Storage::S3 do
...
@@ -1166,8 +1166,8 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
)
acl:
:public_read
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -1180,14 +1180,14 @@ describe Paperclip::Storage::S3 do
...
@@ -1180,14 +1180,14 @@ describe Paperclip::Storage::S3 do
context
"string permissions set"
do
context
"string permissions set"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_permissions
=>
:private
s3_permissions:
:private
end
end
context
"when assigned"
do
context
"when assigned"
do
...
@@ -1204,8 +1204,8 @@ describe Paperclip::Storage::S3 do
...
@@ -1204,8 +1204,8 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:private
)
acl:
:private
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -1218,19 +1218,19 @@ describe Paperclip::Storage::S3 do
...
@@ -1218,19 +1218,19 @@ describe Paperclip::Storage::S3 do
context
"hash permissions set"
do
context
"hash permissions set"
do
before
do
before
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:styles
=>
{
styles:
{
:thumb
=>
"80x80>"
thumb:
"80x80>"
},
},
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_permissions
=>
{
s3_permissions:
{
:original
=>
:private
,
original:
:private
,
:thumb
=>
:public_read
thumb:
:public_read
}
}
end
end
...
@@ -1249,8 +1249,8 @@ describe Paperclip::Storage::S3 do
...
@@ -1249,8 +1249,8 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
style
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
style
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
style
==
:thumb
?
:
public_read
:
:private
)
acl:
style
==
:thumb
?
:
public_read
:
:private
)
end
end
@dummy
.
save
@dummy
.
save
end
end
...
@@ -1265,17 +1265,17 @@ describe Paperclip::Storage::S3 do
...
@@ -1265,17 +1265,17 @@ describe Paperclip::Storage::S3 do
context
"proc permission set"
do
context
"proc permission set"
do
before
do
before
do
rebuild_model
(
rebuild_model
(
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:styles
=>
{
styles:
{
:thumb
=>
"80x80>"
thumb:
"80x80>"
},
},
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_permissions
=>
lambda
{
|
attachment
,
style
|
s3_permissions:
lambda
{
|
attachment
,
style
|
attachment
.
instance
.
private_attachment?
&&
style
.
to_sym
!=
:thumb
?
:
private
:
:public_read
attachment
.
instance
.
private_attachment?
&&
style
.
to_sym
!=
:thumb
?
:
private
:
:public_read
}
}
)
)
...
@@ -1309,17 +1309,17 @@ describe Paperclip::Storage::S3 do
...
@@ -1309,17 +1309,17 @@ describe Paperclip::Storage::S3 do
context
"An attachment with S3 storage and metadata set using a proc as headers"
do
context
"An attachment with S3 storage and metadata set using a proc as headers"
do
before
do
before
do
rebuild_model
(
rebuild_model
(
:storage
=>
:s3
,
storage:
:s3
,
:bucket
=>
"testing"
,
bucket:
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
path:
":attachment/:style/:basename.:extension"
,
:styles
=>
{
styles:
{
:thumb
=>
"80x80>"
thumb:
"80x80>"
},
},
:s3_credentials
=>
{
s3_credentials:
{
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_headers
=>
lambda
{
|
attachment
|
s3_headers:
lambda
{
|
attachment
|
{
'Content-Disposition'
=>
"attachment; filename=
\"
#{
attachment
.
name
}
\"
"
}
{
'Content-Disposition'
=>
"attachment; filename=
\"
#{
attachment
.
name
}
\"
"
}
}
}
)
)
...
@@ -1329,7 +1329,7 @@ describe Paperclip::Storage::S3 do
...
@@ -1329,7 +1329,7 @@ describe Paperclip::Storage::S3 do
before
do
before
do
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:name
=>
'Custom Avatar Name.png'
)
@dummy
.
stubs
(
name:
'Custom Avatar Name.png'
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
end
end
...
@@ -1341,9 +1341,9 @@ describe Paperclip::Storage::S3 do
...
@@ -1341,9 +1341,9 @@ describe Paperclip::Storage::S3 do
object
=
stub
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
style
).
returns
(
object
)
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
style
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
content_type:
"image/png"
,
:acl
=>
:public_read
,
acl:
:public_read
,
:content_disposition
=>
'attachment; filename="Custom Avatar Name.png"'
)
content_disposition:
'attachment; filename="Custom Avatar Name.png"'
)
end
end
@dummy
.
save
@dummy
.
save
end
end
...
...
spec/paperclip/style_spec.rb
View file @
40010c4d
...
@@ -4,9 +4,9 @@ require 'spec_helper'
...
@@ -4,9 +4,9 @@ require 'spec_helper'
describe
Paperclip
::
Style
do
describe
Paperclip
::
Style
do
context
"A style rule"
do
context
"A style rule"
do
before
do
before
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:styles
=>
{
:foo
=>
{
:geometry
=>
"100x100#"
,
:format
=>
:png
}
},
styles:
{
foo:
{
geometry:
"100x100#"
,
format:
:png
}
},
:whiny
=>
true
whiny:
true
@style
=
@attachment
.
styles
[
:foo
]
@style
=
@attachment
.
styles
[
:foo
]
end
end
...
@@ -38,15 +38,15 @@ describe Paperclip::Style do
...
@@ -38,15 +38,15 @@ describe Paperclip::Style do
context
"A style rule with properties supplied as procs"
do
context
"A style rule with properties supplied as procs"
do
before
do
before
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:whiny_thumbnails
=>
true
,
whiny_thumbnails:
true
,
:processors
=>
lambda
{
|
a
|
[
:test
]},
processors:
lambda
{
|
a
|
[
:test
]},
:styles
=>
{
styles:
{
:foo
=>
lambda
{
|
a
|
"300x300#"
},
foo:
lambda
{
|
a
|
"300x300#"
},
:bar
=>
{
bar:
{
:geometry
=>
lambda
{
|
a
|
"300x300#"
},
geometry:
lambda
{
|
a
|
"300x300#"
},
:convert_options
=>
lambda
{
|
a
|
"-do_stuff"
},
convert_options:
lambda
{
|
a
|
"-do_stuff"
},
:source_file_options
=>
lambda
{
|
a
|
"-do_extra_stuff"
}
source_file_options:
lambda
{
|
a
|
"-do_extra_stuff"
}
}
}
}
}
end
end
...
@@ -65,10 +65,10 @@ describe Paperclip::Style do
...
@@ -65,10 +65,10 @@ describe Paperclip::Style do
before
do
before
do
styles
=
{}
styles
=
{}
styles
[
:aslist
]
=
[
"100x100"
,
:png
]
styles
[
:aslist
]
=
[
"100x100"
,
:png
]
styles
[
:ashash
]
=
{
:geometry
=>
"100x100"
,
:format
=>
:png
}
styles
[
:ashash
]
=
{
geometry:
"100x100"
,
format:
:png
}
styles
[
:asstring
]
=
"100x100"
styles
[
:asstring
]
=
"100x100"
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:styles
=>
styles
styles:
styles
end
end
it
"have the right number of styles"
do
it
"have the right number of styles"
do
...
@@ -101,17 +101,17 @@ describe Paperclip::Style do
...
@@ -101,17 +101,17 @@ describe Paperclip::Style do
context
"An attachment with :convert_options"
do
context
"An attachment with :convert_options"
do
it
"not have called extra_options_for(:thumb/:large) on initialization"
do
it
"not have called extra_options_for(:thumb/:large) on initialization"
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:styles
=>
{
:thumb
=>
"100x100"
,
:large
=>
"400x400"
},
styles:
{
thumb:
"100x100"
,
large:
"400x400"
},
:convert_options
=>
{
:all
=>
"-do_stuff"
,
:thumb
=>
"-thumbnailize"
}
convert_options:
{
all:
"-do_stuff"
,
thumb:
"-thumbnailize"
}
@attachment
.
expects
(
:extra_options_for
).
never
@attachment
.
expects
(
:extra_options_for
).
never
@style
=
@attachment
.
styles
[
:thumb
]
@style
=
@attachment
.
styles
[
:thumb
]
end
end
it
"call extra_options_for(:thumb/:large) when convert options are requested"
do
it
"call extra_options_for(:thumb/:large) when convert options are requested"
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:styles
=>
{
:thumb
=>
"100x100"
,
:large
=>
"400x400"
},
styles:
{
thumb:
"100x100"
,
large:
"400x400"
},
:convert_options
=>
{
:all
=>
"-do_stuff"
,
:thumb
=>
"-thumbnailize"
}
convert_options:
{
all:
"-do_stuff"
,
thumb:
"-thumbnailize"
}
@style
=
@attachment
.
styles
[
:thumb
]
@style
=
@attachment
.
styles
[
:thumb
]
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
@file
.
stubs
(
:original_filename
).
returns
(
"file.jpg"
)
@file
.
stubs
(
:original_filename
).
returns
(
"file.jpg"
)
...
@@ -123,17 +123,17 @@ describe Paperclip::Style do
...
@@ -123,17 +123,17 @@ describe Paperclip::Style do
context
"An attachment with :source_file_options"
do
context
"An attachment with :source_file_options"
do
it
"not have called extra_source_file_options_for(:thumb/:large) on initialization"
do
it
"not have called extra_source_file_options_for(:thumb/:large) on initialization"
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:styles
=>
{
:thumb
=>
"100x100"
,
:large
=>
"400x400"
},
styles:
{
thumb:
"100x100"
,
large:
"400x400"
},
:source_file_options
=>
{
:all
=>
"-density 400"
,
:thumb
=>
"-depth 8"
}
source_file_options:
{
all:
"-density 400"
,
thumb:
"-depth 8"
}
@attachment
.
expects
(
:extra_source_file_options_for
).
never
@attachment
.
expects
(
:extra_source_file_options_for
).
never
@style
=
@attachment
.
styles
[
:thumb
]
@style
=
@attachment
.
styles
[
:thumb
]
end
end
it
"call extra_options_for(:thumb/:large) when convert options are requested"
do
it
"call extra_options_for(:thumb/:large) when convert options are requested"
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:styles
=>
{
:thumb
=>
"100x100"
,
:large
=>
"400x400"
},
styles:
{
thumb:
"100x100"
,
large:
"400x400"
},
:source_file_options
=>
{
:all
=>
"-density 400"
,
:thumb
=>
"-depth 8"
}
source_file_options:
{
all:
"-density 400"
,
thumb:
"-depth 8"
}
@style
=
@attachment
.
styles
[
:thumb
]
@style
=
@attachment
.
styles
[
:thumb
]
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
@file
.
stubs
(
:original_filename
).
returns
(
"file.jpg"
)
@file
.
stubs
(
:original_filename
).
returns
(
"file.jpg"
)
...
@@ -145,15 +145,15 @@ describe Paperclip::Style do
...
@@ -145,15 +145,15 @@ describe Paperclip::Style do
context
"A style rule with its own :processors"
do
context
"A style rule with its own :processors"
do
before
do
before
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:styles
=>
{
styles:
{
:foo
=>
{
foo:
{
:geometry
=>
"100x100#"
,
geometry:
"100x100#"
,
:format
=>
:png
,
format:
:png
,
:processors
=>
[
:test
]
processors:
[
:test
]
}
}
},
},
:processors
=>
[
:thumbnail
]
processors:
[
:thumbnail
]
@style
=
@attachment
.
styles
[
:foo
]
@style
=
@attachment
.
styles
[
:foo
]
end
end
...
@@ -170,15 +170,15 @@ describe Paperclip::Style do
...
@@ -170,15 +170,15 @@ describe Paperclip::Style do
context
"A style rule with :processors supplied as procs"
do
context
"A style rule with :processors supplied as procs"
do
before
do
before
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:styles
=>
{
styles:
{
:foo
=>
{
foo:
{
:geometry
=>
"100x100#"
,
geometry:
"100x100#"
,
:format
=>
:png
,
format:
:png
,
:processors
=>
lambda
{
|
a
|
[
:test
]}
processors:
lambda
{
|
a
|
[
:test
]}
}
}
},
},
:processors
=>
[
:thumbnail
]
processors:
[
:thumbnail
]
end
end
it
"defer processing of procs until they are needed"
do
it
"defer processing of procs until they are needed"
do
...
@@ -192,12 +192,12 @@ describe Paperclip::Style do
...
@@ -192,12 +192,12 @@ describe Paperclip::Style do
context
"An attachment with :convert_options and :source_file_options in :styles"
do
context
"An attachment with :convert_options and :source_file_options in :styles"
do
before
do
before
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
@attachment
=
attachment
path:
":basename.:extension"
,
:styles
=>
{
styles:
{
:thumb
=>
"100x100"
,
thumb:
"100x100"
,
:large
=>
{
:geometry
=>
"400x400"
,
large:
{
geometry:
"400x400"
,
:convert_options
=>
"-do_stuff"
,
convert_options:
"-do_stuff"
,
:source_file_options
=>
"-do_extra_stuff"
source_file_options:
"-do_extra_stuff"
}
}
}
}
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
...
@@ -217,13 +217,13 @@ describe Paperclip::Style do
...
@@ -217,13 +217,13 @@ describe Paperclip::Style do
context
"A style rule supplied with default format"
do
context
"A style rule supplied with default format"
do
before
do
before
do
@attachment
=
attachment
:default_format
=>
:png
,
@attachment
=
attachment
default_format:
:png
,
:styles
=>
{
styles:
{
:asstring
=>
"300x300#"
,
asstring:
"300x300#"
,
:aslist
=>
[
"300x300#"
,
:jpg
],
aslist:
[
"300x300#"
,
:jpg
],
:ashash
=>
{
ashash:
{
:geometry
=>
"300x300#"
,
geometry:
"300x300#"
,
:convert_options
=>
"-do_stuff"
convert_options:
"-do_stuff"
}
}
}
}
end
end
...
...
spec/paperclip/thumbnail_spec.rb
View file @
40010c4d
...
@@ -46,7 +46,7 @@ describe Paperclip::Thumbnail do
...
@@ -46,7 +46,7 @@ describe Paperclip::Thumbnail do
].
each
do
|
args
|
].
each
do
|
args
|
context
"being thumbnailed with a geometry of
#{
args
[
0
]
}
"
do
context
"being thumbnailed with a geometry of
#{
args
[
0
]
}
"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
args
[
0
])
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
args
[
0
])
end
end
it
"start with dimensions of 434x66"
do
it
"start with dimensions of 434x66"
do
...
@@ -73,7 +73,7 @@ describe Paperclip::Thumbnail do
...
@@ -73,7 +73,7 @@ describe Paperclip::Thumbnail do
context
"being thumbnailed at 100x50 with cropping"
do
context
"being thumbnailed at 100x50 with cropping"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"100x50#"
)
end
end
it
"let us know when a command isn't found versus a processing error"
do
it
"let us know when a command isn't found versus a processing error"
do
...
@@ -129,19 +129,19 @@ describe Paperclip::Thumbnail do
...
@@ -129,19 +129,19 @@ describe Paperclip::Thumbnail do
it
'properly crop a EXIF-rotated image'
do
it
'properly crop a EXIF-rotated image'
do
file
=
File
.
new
(
fixture_file
(
'rotated.jpg'
))
file
=
File
.
new
(
fixture_file
(
'rotated.jpg'
))
thumb
=
Paperclip
::
Thumbnail
.
new
(
file
,
:geometry
=>
"50x50#"
)
thumb
=
Paperclip
::
Thumbnail
.
new
(
file
,
geometry:
"50x50#"
)
output_file
=
thumb
.
make
output_file
=
thumb
.
make
command
=
Cocaine
::
CommandLine
.
new
(
"identify"
,
"-format %wx%h :file"
)
command
=
Cocaine
::
CommandLine
.
new
(
"identify"
,
"-format %wx%h :file"
)
assert_equal
"50x50"
,
command
.
run
(
:file
=>
output_file
.
path
).
strip
assert_equal
"50x50"
,
command
.
run
(
file:
output_file
.
path
).
strip
end
end
context
"being thumbnailed with source file options set"
do
context
"being thumbnailed with source file options set"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
,
geometry:
"100x50#"
,
:source_file_options
=>
"-strip"
)
source_file_options:
"-strip"
)
end
end
it
"have source_file_options value set"
do
it
"have source_file_options value set"
do
...
@@ -164,8 +164,8 @@ describe Paperclip::Thumbnail do
...
@@ -164,8 +164,8 @@ describe Paperclip::Thumbnail do
context
"redefined to have bad source_file_options setting"
do
context
"redefined to have bad source_file_options setting"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
,
geometry:
"100x50#"
,
:source_file_options
=>
"-this-aint-no-option"
)
source_file_options:
"-this-aint-no-option"
)
end
end
it
"error when trying to create the thumbnail"
do
it
"error when trying to create the thumbnail"
do
...
@@ -181,8 +181,8 @@ describe Paperclip::Thumbnail do
...
@@ -181,8 +181,8 @@ describe Paperclip::Thumbnail do
context
"being thumbnailed with convert options set"
do
context
"being thumbnailed with convert options set"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
,
geometry:
"100x50#"
,
:convert_options
=>
"-strip -depth 8"
)
convert_options:
"-strip -depth 8"
)
end
end
it
"have convert_options value set"
do
it
"have convert_options value set"
do
...
@@ -205,8 +205,8 @@ describe Paperclip::Thumbnail do
...
@@ -205,8 +205,8 @@ describe Paperclip::Thumbnail do
context
"redefined to have bad convert_options setting"
do
context
"redefined to have bad convert_options setting"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
,
geometry:
"100x50#"
,
:convert_options
=>
"-this-aint-no-option"
)
convert_options:
"-this-aint-no-option"
)
end
end
it
"error when trying to create the thumbnail"
do
it
"error when trying to create the thumbnail"
do
...
@@ -238,8 +238,8 @@ describe Paperclip::Thumbnail do
...
@@ -238,8 +238,8 @@ describe Paperclip::Thumbnail do
context
"being thumbnailed with a blank geometry string"
do
context
"being thumbnailed with a blank geometry string"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
""
,
geometry:
""
,
:convert_options
=>
"-gravity center -crop
\"
300x300+0-0
\"
"
)
convert_options:
"-gravity center -crop
\"
300x300+0-0
\"
"
)
end
end
it
"not get resized by default"
do
it
"not get resized by default"
do
...
@@ -249,7 +249,7 @@ describe Paperclip::Thumbnail do
...
@@ -249,7 +249,7 @@ describe Paperclip::Thumbnail do
context
"being thumbnailed with default animated option (true)"
do
context
"being thumbnailed with default animated option (true)"
do
it
"call identify to check for animated images when sent #make"
do
it
"call identify to check for animated images when sent #make"
do
thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
)
thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"100x50#"
)
thumb
.
expects
(
:identify
).
at_least_once
.
with
do
|*
arg
|
thumb
.
expects
(
:identify
).
at_least_once
.
with
do
|*
arg
|
arg
[
0
]
==
'-format %m :file'
&&
arg
[
0
]
==
'-format %m :file'
&&
arg
[
1
][
:file
]
==
"
#{
File
.
expand_path
(
thumb
.
file
.
path
)
}
[0]"
arg
[
1
][
:file
]
==
"
#{
File
.
expand_path
(
thumb
.
file
.
path
)
}
[0]"
...
@@ -274,7 +274,7 @@ describe Paperclip::Thumbnail do
...
@@ -274,7 +274,7 @@ describe Paperclip::Thumbnail do
end
end
end
end
thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
'50x50'
,
:file_geometry_parser
=>
::
GeoParser
)
thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
'50x50'
,
file_geometry_parser:
::
GeoParser
)
transformation_command
=
thumb
.
transformation_command
transformation_command
=
thumb
.
transformation_command
...
@@ -305,7 +305,7 @@ describe Paperclip::Thumbnail do
...
@@ -305,7 +305,7 @@ describe Paperclip::Thumbnail do
end
end
end
end
thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
'50x50'
,
:string_geometry_parser
=>
::
GeoParser
)
thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
'50x50'
,
string_geometry_parser:
::
GeoParser
)
transformation_command
=
thumb
.
transformation_command
transformation_command
=
thumb
.
transformation_command
...
@@ -329,7 +329,7 @@ describe Paperclip::Thumbnail do
...
@@ -329,7 +329,7 @@ describe Paperclip::Thumbnail do
context
"being thumbnailed at 100x100 with cropping"
do
context
"being thumbnailed at 100x100 with cropping"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x100#"
,
:format
=>
:png
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"100x100#"
,
format:
:png
)
end
end
it
"report its correct current and target geometries"
do
it
"report its correct current and target geometries"
do
...
@@ -362,7 +362,7 @@ describe Paperclip::Thumbnail do
...
@@ -362,7 +362,7 @@ describe Paperclip::Thumbnail do
context
"with static output"
do
context
"with static output"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"50x50"
,
:format
=>
:jpg
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"50x50"
,
format:
:jpg
)
end
end
it
"create the single frame thumbnail when sent #make"
do
it
"create the single frame thumbnail when sent #make"
do
...
@@ -374,7 +374,7 @@ describe Paperclip::Thumbnail do
...
@@ -374,7 +374,7 @@ describe Paperclip::Thumbnail do
context
"with animated output format"
do
context
"with animated output format"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"50x50"
,
:format
=>
:gif
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"50x50"
,
format:
:gif
)
end
end
it
"create the 12 frames thumbnail when sent #make"
do
it
"create the 12 frames thumbnail when sent #make"
do
...
@@ -396,7 +396,7 @@ describe Paperclip::Thumbnail do
...
@@ -396,7 +396,7 @@ describe Paperclip::Thumbnail do
context
"with omitted output format"
do
context
"with omitted output format"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"50x50"
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"50x50"
)
end
end
it
"create the 12 frames thumbnail when sent #make"
do
it
"create the 12 frames thumbnail when sent #make"
do
...
@@ -419,7 +419,7 @@ describe Paperclip::Thumbnail do
...
@@ -419,7 +419,7 @@ describe Paperclip::Thumbnail do
context
"with unidentified source format"
do
context
"with unidentified source format"
do
before
do
before
do
@unidentified_file
=
File
.
new
(
fixture_file
(
"animated.unknown"
),
'rb'
)
@unidentified_file
=
File
.
new
(
fixture_file
(
"animated.unknown"
),
'rb'
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"60x60"
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"60x60"
)
end
end
it
"create the 12 frames thumbnail when sent #make"
do
it
"create the 12 frames thumbnail when sent #make"
do
...
@@ -442,7 +442,7 @@ describe Paperclip::Thumbnail do
...
@@ -442,7 +442,7 @@ describe Paperclip::Thumbnail do
context
"with no source format"
do
context
"with no source format"
do
before
do
before
do
@unidentified_file
=
File
.
new
(
fixture_file
(
"animated"
),
'rb'
)
@unidentified_file
=
File
.
new
(
fixture_file
(
"animated"
),
'rb'
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"70x70"
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"70x70"
)
end
end
it
"create the 12 frames thumbnail when sent #make"
do
it
"create the 12 frames thumbnail when sent #make"
do
...
@@ -464,7 +464,7 @@ describe Paperclip::Thumbnail do
...
@@ -464,7 +464,7 @@ describe Paperclip::Thumbnail do
context
"with animated option set to false"
do
context
"with animated option set to false"
do
before
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"50x50"
,
:animated
=>
false
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"50x50"
,
animated:
false
)
end
end
it
"output the gif format"
do
it
"output the gif format"
do
...
...
spec/paperclip/url_generator_spec.rb
View file @
40010c4d
...
@@ -5,10 +5,10 @@ describe Paperclip::UrlGenerator do
...
@@ -5,10 +5,10 @@ describe Paperclip::UrlGenerator do
it
"use the given interpolator"
do
it
"use the given interpolator"
do
expected
=
"the expected result"
expected
=
"the expected result"
mock_attachment
=
MockAttachment
.
new
mock_attachment
=
MockAttachment
.
new
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
{
:interpolator
=>
mock_interpolator
})
{
interpolator:
mock_interpolator
})
result
=
url_generator
.
for
(
:style_name
,
{})
result
=
url_generator
.
for
(
:style_name
,
{})
assert_equal
expected
,
result
assert_equal
expected
,
result
...
@@ -20,7 +20,7 @@ describe Paperclip::UrlGenerator do
...
@@ -20,7 +20,7 @@ describe Paperclip::UrlGenerator do
mock_attachment
=
MockAttachment
.
new
mock_attachment
=
MockAttachment
.
new
mock_interpolator
=
MockInterpolator
.
new
mock_interpolator
=
MockInterpolator
.
new
default_url
=
"the default url"
default_url
=
"the default url"
options
=
{
:interpolator
=>
mock_interpolator
,
:default_url
=>
default_url
}
options
=
{
interpolator:
mock_interpolator
,
default_url:
default_url
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
.
for
(
:style_name
,
{})
url_generator
.
for
(
:style_name
,
{})
...
@@ -33,7 +33,7 @@ describe Paperclip::UrlGenerator do
...
@@ -33,7 +33,7 @@ describe Paperclip::UrlGenerator do
mock_attachment
=
MockAttachment
.
new
mock_attachment
=
MockAttachment
.
new
mock_interpolator
=
MockInterpolator
.
new
mock_interpolator
=
MockInterpolator
.
new
default_url
=
lambda
{
|
attachment
|
"the
#{
attachment
.
class
.
name
}
default url"
}
default_url
=
lambda
{
|
attachment
|
"the
#{
attachment
.
class
.
name
}
default url"
}
options
=
{
:interpolator
=>
mock_interpolator
,
:default_url
=>
default_url
}
options
=
{
interpolator:
mock_interpolator
,
default_url:
default_url
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
.
for
(
:style_name
,
{})
url_generator
.
for
(
:style_name
,
{})
...
@@ -44,10 +44,10 @@ describe Paperclip::UrlGenerator do
...
@@ -44,10 +44,10 @@ describe Paperclip::UrlGenerator do
it
"execute the method named by the symbol as the default URL when no file is assigned"
do
it
"execute the method named by the symbol as the default URL when no file is assigned"
do
mock_model
=
MockModel
.
new
mock_model
=
MockModel
.
new
mock_attachment
=
MockAttachment
.
new
(
:model
=>
mock_model
)
mock_attachment
=
MockAttachment
.
new
(
model:
mock_model
)
mock_interpolator
=
MockInterpolator
.
new
mock_interpolator
=
MockInterpolator
.
new
default_url
=
:to_s
default_url
=
:to_s
options
=
{
:interpolator
=>
mock_interpolator
,
:default_url
=>
default_url
}
options
=
{
interpolator:
mock_interpolator
,
default_url:
default_url
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
.
for
(
:style_name
,
{})
url_generator
.
for
(
:style_name
,
{})
...
@@ -59,11 +59,11 @@ describe Paperclip::UrlGenerator do
...
@@ -59,11 +59,11 @@ describe Paperclip::UrlGenerator do
it
"URL-escape spaces if asked to"
do
it
"URL-escape spaces if asked to"
do
expected
=
"the expected result"
expected
=
"the expected result"
mock_attachment
=
MockAttachment
.
new
mock_attachment
=
MockAttachment
.
new
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
options
=
{
:interpolator
=>
mock_interpolator
}
options
=
{
interpolator:
mock_interpolator
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
result
=
url_generator
.
for
(
:style_name
,
{
:escape
=>
true
})
result
=
url_generator
.
for
(
:style_name
,
{
escape:
true
})
assert_equal
"the%20expected%20result"
,
result
assert_equal
"the%20expected%20result"
,
result
end
end
...
@@ -75,11 +75,11 @@ describe Paperclip::UrlGenerator do
...
@@ -75,11 +75,11 @@ describe Paperclip::UrlGenerator do
end
end
end
.
new
end
.
new
mock_attachment
=
MockAttachment
.
new
mock_attachment
=
MockAttachment
.
new
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
options
=
{
:interpolator
=>
mock_interpolator
}
options
=
{
interpolator:
mock_interpolator
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
result
=
url_generator
.
for
(
:style_name
,
{
:escape
=>
true
})
result
=
url_generator
.
for
(
:style_name
,
{
escape:
true
})
assert_equal
"the escaped result"
,
result
assert_equal
"the escaped result"
,
result
end
end
...
@@ -87,11 +87,11 @@ describe Paperclip::UrlGenerator do
...
@@ -87,11 +87,11 @@ describe Paperclip::UrlGenerator do
it
"leave spaces unescaped as asked to"
do
it
"leave spaces unescaped as asked to"
do
expected
=
"the expected result"
expected
=
"the expected result"
mock_attachment
=
MockAttachment
.
new
mock_attachment
=
MockAttachment
.
new
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
options
=
{
:interpolator
=>
mock_interpolator
}
options
=
{
interpolator:
mock_interpolator
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
result
=
url_generator
.
for
(
:style_name
,
{
:escape
=>
false
})
result
=
url_generator
.
for
(
:style_name
,
{
escape:
false
})
assert_equal
"the expected result"
,
result
assert_equal
"the expected result"
,
result
end
end
...
@@ -99,8 +99,8 @@ describe Paperclip::UrlGenerator do
...
@@ -99,8 +99,8 @@ describe Paperclip::UrlGenerator do
it
"default to leaving spaces unescaped"
do
it
"default to leaving spaces unescaped"
do
expected
=
"the expected result"
expected
=
"the expected result"
mock_attachment
=
MockAttachment
.
new
mock_attachment
=
MockAttachment
.
new
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
options
=
{
:interpolator
=>
mock_interpolator
}
options
=
{
interpolator:
mock_interpolator
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
result
=
url_generator
.
for
(
:style_name
,
{})
result
=
url_generator
.
for
(
:style_name
,
{})
...
@@ -110,24 +110,24 @@ describe Paperclip::UrlGenerator do
...
@@ -110,24 +110,24 @@ describe Paperclip::UrlGenerator do
it
"produce URLs without the updated_at value when the object does not respond to updated_at"
do
it
"produce URLs without the updated_at value when the object does not respond to updated_at"
do
expected
=
"the expected result"
expected
=
"the expected result"
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
mock_attachment
=
MockAttachment
.
new
(
:responds_to_updated_at
=>
false
)
mock_attachment
=
MockAttachment
.
new
(
responds_to_updated_at:
false
)
options
=
{
:interpolator
=>
mock_interpolator
}
options
=
{
interpolator:
mock_interpolator
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
result
=
url_generator
.
for
(
:style_name
,
{
:timestamp
=>
true
})
result
=
url_generator
.
for
(
:style_name
,
{
timestamp:
true
})
assert_equal
expected
,
result
assert_equal
expected
,
result
end
end
it
"produce URLs without the updated_at value when the updated_at value is nil"
do
it
"produce URLs without the updated_at value when the updated_at value is nil"
do
expected
=
"the expected result"
expected
=
"the expected result"
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
mock_attachment
=
MockAttachment
.
new
(
:responds_to_updated_at
=>
true
,
:updated_at
=>
nil
)
mock_attachment
=
MockAttachment
.
new
(
responds_to_updated_at:
true
,
updated_at:
nil
)
options
=
{
:interpolator
=>
mock_interpolator
}
options
=
{
interpolator:
mock_interpolator
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
result
=
url_generator
.
for
(
:style_name
,
{
:timestamp
=>
true
})
result
=
url_generator
.
for
(
:style_name
,
{
timestamp:
true
})
assert_equal
expected
,
result
assert_equal
expected
,
result
end
end
...
@@ -135,12 +135,12 @@ describe Paperclip::UrlGenerator do
...
@@ -135,12 +135,12 @@ describe Paperclip::UrlGenerator do
it
"produce URLs with the updated_at when it exists"
do
it
"produce URLs with the updated_at when it exists"
do
expected
=
"the expected result"
expected
=
"the expected result"
updated_at
=
1231231234
updated_at
=
1231231234
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
mock_attachment
=
MockAttachment
.
new
(
:updated_at
=>
updated_at
)
mock_attachment
=
MockAttachment
.
new
(
updated_at:
updated_at
)
options
=
{
:interpolator
=>
mock_interpolator
}
options
=
{
interpolator:
mock_interpolator
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
result
=
url_generator
.
for
(
:style_name
,
{
:timestamp
=>
true
})
result
=
url_generator
.
for
(
:style_name
,
{
timestamp:
true
})
assert_equal
"
#{
expected
}
?
#{
updated_at
}
"
,
result
assert_equal
"
#{
expected
}
?
#{
updated_at
}
"
,
result
end
end
...
@@ -148,12 +148,12 @@ describe Paperclip::UrlGenerator do
...
@@ -148,12 +148,12 @@ describe Paperclip::UrlGenerator do
it
"produce URLs with the updated_at when it exists, separated with a & if a ? follow by = already exists"
do
it
"produce URLs with the updated_at when it exists, separated with a & if a ? follow by = already exists"
do
expected
=
"the?expected=result"
expected
=
"the?expected=result"
updated_at
=
1231231234
updated_at
=
1231231234
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
mock_attachment
=
MockAttachment
.
new
(
:updated_at
=>
updated_at
)
mock_attachment
=
MockAttachment
.
new
(
updated_at:
updated_at
)
options
=
{
:interpolator
=>
mock_interpolator
}
options
=
{
interpolator:
mock_interpolator
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
result
=
url_generator
.
for
(
:style_name
,
{
:timestamp
=>
true
})
result
=
url_generator
.
for
(
:style_name
,
{
timestamp:
true
})
assert_equal
"
#{
expected
}
&
#{
updated_at
}
"
,
result
assert_equal
"
#{
expected
}
&
#{
updated_at
}
"
,
result
end
end
...
@@ -161,21 +161,21 @@ describe Paperclip::UrlGenerator do
...
@@ -161,21 +161,21 @@ describe Paperclip::UrlGenerator do
it
"produce URLs without the updated_at when told to do as much"
do
it
"produce URLs without the updated_at when told to do as much"
do
expected
=
"the expected result"
expected
=
"the expected result"
updated_at
=
1231231234
updated_at
=
1231231234
mock_interpolator
=
MockInterpolator
.
new
(
:result
=>
expected
)
mock_interpolator
=
MockInterpolator
.
new
(
result:
expected
)
mock_attachment
=
MockAttachment
.
new
(
:updated_at
=>
updated_at
)
mock_attachment
=
MockAttachment
.
new
(
updated_at:
updated_at
)
options
=
{
:interpolator
=>
mock_interpolator
}
options
=
{
interpolator:
mock_interpolator
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
result
=
url_generator
.
for
(
:style_name
,
{
:timestamp
=>
false
})
result
=
url_generator
.
for
(
:style_name
,
{
timestamp:
false
})
assert_equal
expected
,
result
assert_equal
expected
,
result
end
end
it
"produce the correct URL when the instance has a file name"
do
it
"produce the correct URL when the instance has a file name"
do
expected
=
"the expected result"
expected
=
"the expected result"
mock_attachment
=
MockAttachment
.
new
(
:original_filename
=>
'exists'
)
mock_attachment
=
MockAttachment
.
new
(
original_filename:
'exists'
)
mock_interpolator
=
MockInterpolator
.
new
mock_interpolator
=
MockInterpolator
.
new
options
=
{
:interpolator
=>
mock_interpolator
,
:url
=>
expected
}
options
=
{
interpolator:
mock_interpolator
,
url:
expected
}
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
=
Paperclip
::
UrlGenerator
.
new
(
mock_attachment
,
options
)
url_generator
.
for
(
:style_name
,
{})
url_generator
.
for
(
:style_name
,
{})
...
...
spec/paperclip/validators/attachment_content_type_validator_spec.rb
View file @
40010c4d
...
@@ -8,14 +8,14 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -8,14 +8,14 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
def
build_validator
(
options
)
def
build_validator
(
options
)
@validator
=
Paperclip
::
Validators
::
AttachmentContentTypeValidator
.
new
(
options
.
merge
(
@validator
=
Paperclip
::
Validators
::
AttachmentContentTypeValidator
.
new
(
options
.
merge
(
:attributes
=>
:avatar
attributes:
:avatar
))
))
end
end
context
"with a nil content type"
do
context
"with a nil content type"
do
before
do
before
do
build_validator
:content_type
=>
"image/jpg"
build_validator
content_type:
"image/jpg"
@dummy
.
stubs
(
:avatar_content_type
=>
nil
)
@dummy
.
stubs
(
avatar_content_type:
nil
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -27,8 +27,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -27,8 +27,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with :allow_nil option"
do
context
"with :allow_nil option"
do
context
"as true"
do
context
"as true"
do
before
do
before
do
build_validator
:content_type
=>
"image/png"
,
:allow_nil
=>
true
build_validator
content_type:
"image/png"
,
allow_nil:
true
@dummy
.
stubs
(
:avatar_content_type
=>
nil
)
@dummy
.
stubs
(
avatar_content_type:
nil
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -39,8 +39,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -39,8 +39,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"as false"
do
context
"as false"
do
before
do
before
do
build_validator
:content_type
=>
"image/png"
,
:allow_nil
=>
false
build_validator
content_type:
"image/png"
,
allow_nil:
false
@dummy
.
stubs
(
:avatar_content_type
=>
nil
)
@dummy
.
stubs
(
avatar_content_type:
nil
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -52,8 +52,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -52,8 +52,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with a failing validation"
do
context
"with a failing validation"
do
before
do
before
do
build_validator
:content_type
=>
"image/png"
,
:allow_nil
=>
false
build_validator
content_type:
"image/png"
,
allow_nil:
false
@dummy
.
stubs
(
:avatar_content_type
=>
nil
)
@dummy
.
stubs
(
avatar_content_type:
nil
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -69,8 +69,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -69,8 +69,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with a successful validation"
do
context
"with a successful validation"
do
before
do
before
do
build_validator
:content_type
=>
"image/png"
,
:allow_nil
=>
false
build_validator
content_type:
"image/png"
,
allow_nil:
false
@dummy
.
stubs
(
:avatar_content_type
=>
"image/png"
)
@dummy
.
stubs
(
avatar_content_type:
"image/png"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -83,8 +83,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -83,8 +83,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with :allow_blank option"
do
context
"with :allow_blank option"
do
context
"as true"
do
context
"as true"
do
before
do
before
do
build_validator
:content_type
=>
"image/png"
,
:allow_blank
=>
true
build_validator
content_type:
"image/png"
,
allow_blank:
true
@dummy
.
stubs
(
:avatar_content_type
=>
""
)
@dummy
.
stubs
(
avatar_content_type:
""
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -95,8 +95,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -95,8 +95,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"as false"
do
context
"as false"
do
before
do
before
do
build_validator
:content_type
=>
"image/png"
,
:allow_blank
=>
false
build_validator
content_type:
"image/png"
,
allow_blank:
false
@dummy
.
stubs
(
:avatar_content_type
=>
""
)
@dummy
.
stubs
(
avatar_content_type:
""
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -110,8 +110,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -110,8 +110,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with an allowed type"
do
context
"with an allowed type"
do
context
"as a string"
do
context
"as a string"
do
before
do
before
do
build_validator
:content_type
=>
"image/jpg"
build_validator
content_type:
"image/jpg"
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@dummy
.
stubs
(
avatar_content_type:
"image/jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -122,8 +122,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -122,8 +122,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"as an regexp"
do
context
"as an regexp"
do
before
do
before
do
build_validator
:content_type
=>
/^image\/.*/
build_validator
content_type:
/^image\/.*/
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@dummy
.
stubs
(
avatar_content_type:
"image/jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -134,8 +134,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -134,8 +134,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"as a list"
do
context
"as a list"
do
before
do
before
do
build_validator
:content_type
=>
[
"image/png"
,
"image/jpg"
,
"image/jpeg"
]
build_validator
content_type:
[
"image/png"
,
"image/jpg"
,
"image/jpeg"
]
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@dummy
.
stubs
(
avatar_content_type:
"image/jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -148,8 +148,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -148,8 +148,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with a disallowed type"
do
context
"with a disallowed type"
do
context
"as a string"
do
context
"as a string"
do
before
do
before
do
build_validator
:content_type
=>
"image/png"
build_validator
content_type:
"image/png"
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@dummy
.
stubs
(
avatar_content_type:
"image/jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -161,8 +161,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -161,8 +161,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"as a regexp"
do
context
"as a regexp"
do
before
do
before
do
build_validator
:content_type
=>
/^text\/.*/
build_validator
content_type:
/^text\/.*/
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@dummy
.
stubs
(
avatar_content_type:
"image/jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -175,8 +175,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -175,8 +175,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with :message option"
do
context
"with :message option"
do
context
"without interpolation"
do
context
"without interpolation"
do
before
do
before
do
build_validator
:content_type
=>
"image/png"
,
:message
=>
"should be a PNG image"
build_validator
content_type:
"image/png"
,
message:
"should be a PNG image"
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@dummy
.
stubs
(
avatar_content_type:
"image/jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -187,8 +187,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -187,8 +187,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with interpolation"
do
context
"with interpolation"
do
before
do
before
do
build_validator
:content_type
=>
"image/png"
,
:message
=>
"should have content type %{types}"
build_validator
content_type:
"image/png"
,
message:
"should have content type %{types}"
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@dummy
.
stubs
(
avatar_content_type:
"image/jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -204,8 +204,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -204,8 +204,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with an allowed type"
do
context
"with an allowed type"
do
context
"as a string"
do
context
"as a string"
do
before
do
before
do
build_validator
:not
=>
"image/gif"
build_validator
not:
"image/gif"
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@dummy
.
stubs
(
avatar_content_type:
"image/jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -216,8 +216,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -216,8 +216,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"as an regexp"
do
context
"as an regexp"
do
before
do
before
do
build_validator
:not
=>
/^text\/.*/
build_validator
not:
/^text\/.*/
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@dummy
.
stubs
(
avatar_content_type:
"image/jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -228,8 +228,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -228,8 +228,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"as a list"
do
context
"as a list"
do
before
do
before
do
build_validator
:not
=>
[
"image/png"
,
"image/jpg"
,
"image/jpeg"
]
build_validator
not:
[
"image/png"
,
"image/jpg"
,
"image/jpeg"
]
@dummy
.
stubs
(
:avatar_content_type
=>
"image/gif"
)
@dummy
.
stubs
(
avatar_content_type:
"image/gif"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -242,8 +242,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -242,8 +242,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with a disallowed type"
do
context
"with a disallowed type"
do
context
"as a string"
do
context
"as a string"
do
before
do
before
do
build_validator
:not
=>
"image/png"
build_validator
not:
"image/png"
@dummy
.
stubs
(
:avatar_content_type
=>
"image/png"
)
@dummy
.
stubs
(
avatar_content_type:
"image/png"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -255,8 +255,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -255,8 +255,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"as a regexp"
do
context
"as a regexp"
do
before
do
before
do
build_validator
:not
=>
/^text\/.*/
build_validator
not:
/^text\/.*/
@dummy
.
stubs
(
:avatar_content_type
=>
"text/plain"
)
@dummy
.
stubs
(
avatar_content_type:
"text/plain"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -269,8 +269,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -269,8 +269,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with :message option"
do
context
"with :message option"
do
context
"without interpolation"
do
context
"without interpolation"
do
before
do
before
do
build_validator
:not
=>
"image/png"
,
:message
=>
"should not be a PNG image"
build_validator
not:
"image/png"
,
message:
"should not be a PNG image"
@dummy
.
stubs
(
:avatar_content_type
=>
"image/png"
)
@dummy
.
stubs
(
avatar_content_type:
"image/png"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -281,8 +281,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -281,8 +281,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"with interpolation"
do
context
"with interpolation"
do
before
do
before
do
build_validator
:not
=>
"image/png"
,
:message
=>
"should not have content type %{types}"
build_validator
not:
"image/png"
,
message:
"should not have content type %{types}"
@dummy
.
stubs
(
:avatar_content_type
=>
"image/png"
)
@dummy
.
stubs
(
avatar_content_type:
"image/png"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -296,7 +296,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -296,7 +296,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"using the helper"
do
context
"using the helper"
do
before
do
before
do
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
"image/jpg"
Dummy
.
validates_attachment_content_type
:avatar
,
content_type:
"image/jpg"
end
end
it
"add the validator to the class"
do
it
"add the validator to the class"
do
...
@@ -307,16 +307,16 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
...
@@ -307,16 +307,16 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context
"given options"
do
context
"given options"
do
it
"raise argument error if no required argument was given"
do
it
"raise argument error if no required argument was given"
do
assert_raises
(
ArgumentError
)
do
assert_raises
(
ArgumentError
)
do
build_validator
:message
=>
"Some message"
build_validator
message:
"Some message"
end
end
end
end
it
"not raise argument error if :content_type was given"
do
it
"not raise argument error if :content_type was given"
do
build_validator
:content_type
=>
"image/jpg"
build_validator
content_type:
"image/jpg"
end
end
it
"not raise argument error if :not was given"
do
it
"not raise argument error if :not was given"
do
build_validator
:not
=>
"image/jpg"
build_validator
not:
"image/jpg"
end
end
end
end
end
end
spec/paperclip/validators/attachment_file_name_validator_spec.rb
View file @
40010c4d
...
@@ -8,14 +8,14 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -8,14 +8,14 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
def
build_validator
(
options
)
def
build_validator
(
options
)
@validator
=
Paperclip
::
Validators
::
AttachmentFileNameValidator
.
new
(
options
.
merge
(
@validator
=
Paperclip
::
Validators
::
AttachmentFileNameValidator
.
new
(
options
.
merge
(
:attributes
=>
:avatar
attributes:
:avatar
))
))
end
end
context
"with a failing validation"
do
context
"with a failing validation"
do
before
do
before
do
build_validator
:matches
=>
/.*\.png$/
,
:allow_nil
=>
false
build_validator
matches:
/.*\.png$/
,
allow_nil:
false
@dummy
.
stubs
(
:avatar_file_name
=>
"data.txt"
)
@dummy
.
stubs
(
avatar_file_name:
"data.txt"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -30,8 +30,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -30,8 +30,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
end
end
it
"not add error to the base object with a successful validation"
do
it
"not add error to the base object with a successful validation"
do
build_validator
:matches
=>
/.*\.png$/
,
:allow_nil
=>
false
build_validator
matches:
/.*\.png$/
,
allow_nil:
false
@dummy
.
stubs
(
:avatar_file_name
=>
"image.png"
)
@dummy
.
stubs
(
avatar_file_name:
"image.png"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
assert
@dummy
.
errors
[
:avatar
].
blank?
,
"Error was added to base attribute"
assert
@dummy
.
errors
[
:avatar
].
blank?
,
"Error was added to base attribute"
...
@@ -41,8 +41,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -41,8 +41,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context
"with an allowed type"
do
context
"with an allowed type"
do
context
"as a single regexp"
do
context
"as a single regexp"
do
before
do
before
do
build_validator
:matches
=>
/.*\.jpg$/
build_validator
matches:
/.*\.jpg$/
@dummy
.
stubs
(
:avatar_file_name
=>
"image.jpg"
)
@dummy
.
stubs
(
avatar_file_name:
"image.jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -53,8 +53,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -53,8 +53,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context
"as a list"
do
context
"as a list"
do
before
do
before
do
build_validator
:matches
=>
[
/.*\.png$/
,
/.*\.jpe?g$/
]
build_validator
matches:
[
/.*\.png$/
,
/.*\.jpe?g$/
]
@dummy
.
stubs
(
:avatar_file_name
=>
"image.jpg"
)
@dummy
.
stubs
(
avatar_file_name:
"image.jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -66,8 +66,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -66,8 +66,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context
"with a disallowed type"
do
context
"with a disallowed type"
do
it
"set a correct default error message"
do
it
"set a correct default error message"
do
build_validator
:matches
=>
/^text\/.*/
build_validator
matches:
/^text\/.*/
@dummy
.
stubs
(
:avatar_file_name
=>
"image.jpg"
)
@dummy
.
stubs
(
avatar_file_name:
"image.jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
assert
@dummy
.
errors
[
:avatar_file_name
].
present?
assert
@dummy
.
errors
[
:avatar_file_name
].
present?
...
@@ -75,8 +75,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -75,8 +75,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
end
end
it
"set a correct custom error message"
do
it
"set a correct custom error message"
do
build_validator
:matches
=>
/.*\.png$/
,
:message
=>
"should be a PNG image"
build_validator
matches:
/.*\.png$/
,
message:
"should be a PNG image"
@dummy
.
stubs
(
:avatar_file_name
=>
"image.jpg"
)
@dummy
.
stubs
(
avatar_file_name:
"image.jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
expect
(
@dummy
.
errors
[
:avatar_file_name
]).
to
include
"should be a PNG image"
expect
(
@dummy
.
errors
[
:avatar_file_name
]).
to
include
"should be a PNG image"
...
@@ -88,8 +88,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -88,8 +88,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context
"with an allowed type"
do
context
"with an allowed type"
do
context
"as a single regexp"
do
context
"as a single regexp"
do
before
do
before
do
build_validator
:not
=>
/^text\/.*/
build_validator
not:
/^text\/.*/
@dummy
.
stubs
(
:avatar_file_name
=>
"image.jpg"
)
@dummy
.
stubs
(
avatar_file_name:
"image.jpg"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -100,8 +100,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -100,8 +100,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context
"as a list"
do
context
"as a list"
do
before
do
before
do
build_validator
:not
=>
[
/.*\.png$/
,
/.*\.jpe?g$/
]
build_validator
not:
[
/.*\.png$/
,
/.*\.jpe?g$/
]
@dummy
.
stubs
(
:avatar_file_name
=>
"image.gif"
)
@dummy
.
stubs
(
avatar_file_name:
"image.gif"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -113,8 +113,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -113,8 +113,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context
"with a disallowed type"
do
context
"with a disallowed type"
do
it
"set a correct default error message"
do
it
"set a correct default error message"
do
build_validator
:not
=>
/data.*/
build_validator
not:
/data.*/
@dummy
.
stubs
(
:avatar_file_name
=>
"data.txt"
)
@dummy
.
stubs
(
avatar_file_name:
"data.txt"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
assert
@dummy
.
errors
[
:avatar_file_name
].
present?
assert
@dummy
.
errors
[
:avatar_file_name
].
present?
...
@@ -122,8 +122,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -122,8 +122,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
end
end
it
"set a correct custom error message"
do
it
"set a correct custom error message"
do
build_validator
:not
=>
/.*\.png$/
,
:message
=>
"should not be a PNG image"
build_validator
not:
/.*\.png$/
,
message:
"should not be a PNG image"
@dummy
.
stubs
(
:avatar_file_name
=>
"image.png"
)
@dummy
.
stubs
(
avatar_file_name:
"image.png"
)
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
expect
(
@dummy
.
errors
[
:avatar_file_name
]).
to
include
"should not be a PNG image"
expect
(
@dummy
.
errors
[
:avatar_file_name
]).
to
include
"should not be a PNG image"
...
@@ -133,7 +133,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -133,7 +133,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context
"using the helper"
do
context
"using the helper"
do
before
do
before
do
Dummy
.
validates_attachment_file_name
:avatar
,
:matches
=>
/.*\.jpg$/
Dummy
.
validates_attachment_file_name
:avatar
,
matches:
/.*\.jpg$/
end
end
it
"add the validator to the class"
do
it
"add the validator to the class"
do
...
@@ -144,16 +144,16 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
...
@@ -144,16 +144,16 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context
"given options"
do
context
"given options"
do
it
"raise argument error if no required argument was given"
do
it
"raise argument error if no required argument was given"
do
assert_raises
(
ArgumentError
)
do
assert_raises
(
ArgumentError
)
do
build_validator
:message
=>
"Some message"
build_validator
message:
"Some message"
end
end
end
end
it
"not raise argument error if :matches was given"
do
it
"not raise argument error if :matches was given"
do
build_validator
:matches
=>
/.*\.jpg$/
build_validator
matches:
/.*\.jpg$/
end
end
it
"not raise argument error if :not was given"
do
it
"not raise argument error if :not was given"
do
build_validator
:not
=>
/.*\.jpg$/
build_validator
not:
/.*\.jpg$/
end
end
end
end
end
end
...
...
spec/paperclip/validators/attachment_presence_validator_spec.rb
View file @
40010c4d
...
@@ -8,7 +8,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
...
@@ -8,7 +8,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
def
build_validator
(
options
=
{})
def
build_validator
(
options
=
{})
@validator
=
Paperclip
::
Validators
::
AttachmentPresenceValidator
.
new
(
options
.
merge
(
@validator
=
Paperclip
::
Validators
::
AttachmentPresenceValidator
.
new
(
options
.
merge
(
:attributes
=>
:avatar
attributes:
:avatar
))
))
end
end
...
@@ -35,7 +35,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
...
@@ -35,7 +35,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
context
"with :if option"
do
context
"with :if option"
do
context
"returning true"
do
context
"returning true"
do
before
do
before
do
build_validator
:if
=>
true
build_validator
if:
true
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
@@ -46,7 +46,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
...
@@ -46,7 +46,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
context
"returning false"
do
context
"returning false"
do
before
do
before
do
build_validator
:if
=>
false
build_validator
if:
false
@validator
.
validate
(
@dummy
)
@validator
.
validate
(
@dummy
)
end
end
...
...
spec/paperclip/validators/attachment_size_validator_spec.rb
View file @
40010c4d
...
@@ -8,7 +8,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -8,7 +8,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
def
build_validator
(
options
)
def
build_validator
(
options
)
@validator
=
Paperclip
::
Validators
::
AttachmentSizeValidator
.
new
(
options
.
merge
(
@validator
=
Paperclip
::
Validators
::
AttachmentSizeValidator
.
new
(
options
.
merge
(
:attributes
=>
:avatar
attributes:
:avatar
))
))
end
end
...
@@ -60,7 +60,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -60,7 +60,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"with :in option"
do
context
"with :in option"
do
context
"as a range"
do
context
"as a range"
do
before
do
before
do
build_validator
:in
=>
(
5
.
kilobytes
..
10
.
kilobytes
)
build_validator
in:
(
5
.
kilobytes
..
10
.
kilobytes
)
end
end
should_allow_attachment_file_size
(
7
.
kilobytes
)
should_allow_attachment_file_size
(
7
.
kilobytes
)
...
@@ -70,7 +70,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -70,7 +70,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"as a proc"
do
context
"as a proc"
do
before
do
before
do
build_validator
:in
=>
lambda
{
|
avatar
|
(
5
.
kilobytes
..
10
.
kilobytes
)
}
build_validator
in:
lambda
{
|
avatar
|
(
5
.
kilobytes
..
10
.
kilobytes
)
}
end
end
should_allow_attachment_file_size
(
7
.
kilobytes
)
should_allow_attachment_file_size
(
7
.
kilobytes
)
...
@@ -82,7 +82,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -82,7 +82,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"with :greater_than option"
do
context
"with :greater_than option"
do
context
"as number"
do
context
"as number"
do
before
do
before
do
build_validator
:greater_than
=>
10
.
kilobytes
build_validator
greater_than:
10
.
kilobytes
end
end
should_allow_attachment_file_size
11
.
kilobytes
should_allow_attachment_file_size
11
.
kilobytes
...
@@ -91,7 +91,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -91,7 +91,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"as a proc"
do
context
"as a proc"
do
before
do
before
do
build_validator
:greater_than
=>
lambda
{
|
avatar
|
10
.
kilobytes
}
build_validator
greater_than:
lambda
{
|
avatar
|
10
.
kilobytes
}
end
end
should_allow_attachment_file_size
11
.
kilobytes
should_allow_attachment_file_size
11
.
kilobytes
...
@@ -102,7 +102,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -102,7 +102,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"with :less_than option"
do
context
"with :less_than option"
do
context
"as number"
do
context
"as number"
do
before
do
before
do
build_validator
:less_than
=>
10
.
kilobytes
build_validator
less_than:
10
.
kilobytes
end
end
should_allow_attachment_file_size
9
.
kilobytes
should_allow_attachment_file_size
9
.
kilobytes
...
@@ -111,7 +111,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -111,7 +111,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"as a proc"
do
context
"as a proc"
do
before
do
before
do
build_validator
:less_than
=>
lambda
{
|
avatar
|
10
.
kilobytes
}
build_validator
less_than:
lambda
{
|
avatar
|
10
.
kilobytes
}
end
end
should_allow_attachment_file_size
9
.
kilobytes
should_allow_attachment_file_size
9
.
kilobytes
...
@@ -122,8 +122,8 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -122,8 +122,8 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"with :greater_than and :less_than option"
do
context
"with :greater_than and :less_than option"
do
context
"as numbers"
do
context
"as numbers"
do
before
do
before
do
build_validator
:greater_than
=>
5
.
kilobytes
,
build_validator
greater_than:
5
.
kilobytes
,
:less_than
=>
10
.
kilobytes
less_than:
10
.
kilobytes
end
end
should_allow_attachment_file_size
7
.
kilobytes
should_allow_attachment_file_size
7
.
kilobytes
...
@@ -133,8 +133,8 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -133,8 +133,8 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"as a proc"
do
context
"as a proc"
do
before
do
before
do
build_validator
:greater_than
=>
lambda
{
|
avatar
|
5
.
kilobytes
},
build_validator
greater_than:
lambda
{
|
avatar
|
5
.
kilobytes
},
:less_than
=>
lambda
{
|
avatar
|
10
.
kilobytes
}
less_than:
lambda
{
|
avatar
|
10
.
kilobytes
}
end
end
should_allow_attachment_file_size
7
.
kilobytes
should_allow_attachment_file_size
7
.
kilobytes
...
@@ -146,54 +146,54 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -146,54 +146,54 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"with :message option"
do
context
"with :message option"
do
context
"given a range"
do
context
"given a range"
do
before
do
before
do
build_validator
:in
=>
(
5
.
kilobytes
..
10
.
kilobytes
),
build_validator
in:
(
5
.
kilobytes
..
10
.
kilobytes
),
:message
=>
"is invalid. (Between %{min} and %{max} please.)"
message:
"is invalid. (Between %{min} and %{max} please.)"
end
end
should_not_allow_attachment_file_size
11
.
kilobytes
,
should_not_allow_attachment_file_size
11
.
kilobytes
,
:message
=>
"is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
message:
"is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
end
end
context
"given :less_than and :greater_than"
do
context
"given :less_than and :greater_than"
do
before
do
before
do
build_validator
:less_than
=>
10
.
kilobytes
,
build_validator
less_than:
10
.
kilobytes
,
:greater_than
=>
5
.
kilobytes
,
greater_than:
5
.
kilobytes
,
:message
=>
"is invalid. (Between %{min} and %{max} please.)"
message:
"is invalid. (Between %{min} and %{max} please.)"
end
end
should_not_allow_attachment_file_size
11
.
kilobytes
,
should_not_allow_attachment_file_size
11
.
kilobytes
,
:message
=>
"is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
message:
"is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
end
end
end
end
context
"default error messages"
do
context
"default error messages"
do
context
"given :less_than and :greater_than"
do
context
"given :less_than and :greater_than"
do
before
do
before
do
build_validator
:greater_than
=>
5
.
kilobytes
,
build_validator
greater_than:
5
.
kilobytes
,
:less_than
=>
10
.
kilobytes
less_than:
10
.
kilobytes
end
end
should_not_allow_attachment_file_size
11
.
kilobytes
,
should_not_allow_attachment_file_size
11
.
kilobytes
,
:message
=>
"must be less than 10240 Bytes"
message:
"must be less than 10240 Bytes"
should_not_allow_attachment_file_size
4
.
kilobytes
,
should_not_allow_attachment_file_size
4
.
kilobytes
,
:message
=>
"must be greater than 5120 Bytes"
message:
"must be greater than 5120 Bytes"
end
end
context
"given a size range"
do
context
"given a size range"
do
before
do
before
do
build_validator
:in
=>
(
5
.
kilobytes
..
10
.
kilobytes
)
build_validator
in:
(
5
.
kilobytes
..
10
.
kilobytes
)
end
end
should_not_allow_attachment_file_size
11
.
kilobytes
,
should_not_allow_attachment_file_size
11
.
kilobytes
,
:message
=>
"must be in between 5120 Bytes and 10240 Bytes"
message:
"must be in between 5120 Bytes and 10240 Bytes"
should_not_allow_attachment_file_size
4
.
kilobytes
,
should_not_allow_attachment_file_size
4
.
kilobytes
,
:message
=>
"must be in between 5120 Bytes and 10240 Bytes"
message:
"must be in between 5120 Bytes and 10240 Bytes"
end
end
end
end
context
"using the helper"
do
context
"using the helper"
do
before
do
before
do
Dummy
.
validates_attachment_size
:avatar
,
:in
=>
(
5
.
kilobytes
..
10
.
kilobytes
)
Dummy
.
validates_attachment_size
:avatar
,
in:
(
5
.
kilobytes
..
10
.
kilobytes
)
end
end
it
"add the validator to the class"
do
it
"add the validator to the class"
do
...
@@ -204,7 +204,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -204,7 +204,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context
"given options"
do
context
"given options"
do
it
"raise argument error if no required argument was given"
do
it
"raise argument error if no required argument was given"
do
assert_raises
(
ArgumentError
)
do
assert_raises
(
ArgumentError
)
do
build_validator
:message
=>
"Some message"
build_validator
message:
"Some message"
end
end
end
end
...
@@ -215,7 +215,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
...
@@ -215,7 +215,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
end
end
it
"not raise argument error if :in was given"
do
it
"not raise argument error if :in was given"
do
build_validator
:in
=>
(
5
.
kilobytes
..
10
.
kilobytes
)
build_validator
in:
(
5
.
kilobytes
..
10
.
kilobytes
)
end
end
end
end
end
end
spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb
View file @
40010c4d
...
@@ -8,7 +8,7 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
...
@@ -8,7 +8,7 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
def
build_validator
(
options
=
{})
def
build_validator
(
options
=
{})
@validator
=
Paperclip
::
Validators
::
MediaTypeSpoofDetectionValidator
.
new
(
options
.
merge
(
@validator
=
Paperclip
::
Validators
::
MediaTypeSpoofDetectionValidator
.
new
(
options
.
merge
(
:attributes
=>
:avatar
attributes:
:avatar
))
))
end
end
...
...
spec/paperclip/validators_spec.rb
View file @
40010c4d
...
@@ -3,7 +3,7 @@ require 'spec_helper'
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
Paperclip
::
Validators
do
describe
Paperclip
::
Validators
do
context
"using the helper"
do
context
"using the helper"
do
before
do
before
do
Dummy
.
validates_attachment
:avatar
,
:presence
=>
true
,
:content_type
=>
{
:content_type
=>
"image/jpeg"
},
:size
=>
{
:in
=>
0
..
10240
}
Dummy
.
validates_attachment
:avatar
,
presence:
true
,
content_type:
{
content_type:
"image/jpeg"
},
size:
{
in:
0
..
10240
}
end
end
it
"adds the attachment_presence validator to the class"
do
it
"adds the attachment_presence validator to the class"
do
...
@@ -20,7 +20,7 @@ describe Paperclip::Validators do
...
@@ -20,7 +20,7 @@ describe Paperclip::Validators do
it
'prevents you from attaching a file that violates that validation'
do
it
'prevents you from attaching a file that violates that validation'
do
Dummy
.
class_eval
{
validate
(
:name
)
{
raise
"DO NOT RUN THIS"
}
}
Dummy
.
class_eval
{
validate
(
:name
)
{
raise
"DO NOT RUN THIS"
}
}
dummy
=
Dummy
.
new
(
:avatar
=>
File
.
new
(
fixture_file
(
"12k.png"
)))
dummy
=
Dummy
.
new
(
avatar:
File
.
new
(
fixture_file
(
"12k.png"
)))
assert_equal
[
:avatar_content_type
,
:avatar
,
:avatar_file_size
],
dummy
.
errors
.
keys
assert_equal
[
:avatar_content_type
,
:avatar
,
:avatar_file_size
],
dummy
.
errors
.
keys
assert_raises
(
RuntimeError
){
dummy
.
valid?
}
assert_raises
(
RuntimeError
){
dummy
.
valid?
}
end
end
...
@@ -29,10 +29,10 @@ describe Paperclip::Validators do
...
@@ -29,10 +29,10 @@ describe Paperclip::Validators do
context
"using the helper with a conditional"
do
context
"using the helper with a conditional"
do
before
do
before
do
rebuild_class
rebuild_class
Dummy
.
validates_attachment
:avatar
,
:presence
=>
true
,
Dummy
.
validates_attachment
:avatar
,
presence:
true
,
:content_type
=>
{
:content_type
=>
"image/jpeg"
},
content_type:
{
content_type:
"image/jpeg"
},
:size
=>
{
:in
=>
0
..
10240
},
size:
{
in:
0
..
10240
},
:if
=>
:title_present?
if:
:title_present?
end
end
it
"validates the attachment if title is present"
do
it
"validates the attachment if title is present"
do
...
@@ -41,7 +41,7 @@ describe Paperclip::Validators do
...
@@ -41,7 +41,7 @@ describe Paperclip::Validators do
true
true
end
end
end
end
dummy
=
Dummy
.
new
(
:avatar
=>
File
.
new
(
fixture_file
(
"12k.png"
)))
dummy
=
Dummy
.
new
(
avatar:
File
.
new
(
fixture_file
(
"12k.png"
)))
assert_equal
[
:avatar_content_type
,
:avatar
,
:avatar_file_size
],
dummy
.
errors
.
keys
assert_equal
[
:avatar_content_type
,
:avatar
,
:avatar_file_size
],
dummy
.
errors
.
keys
end
end
...
@@ -65,31 +65,31 @@ describe Paperclip::Validators do
...
@@ -65,31 +65,31 @@ describe Paperclip::Validators do
it
'raises an error when no content_type validation exists'
do
it
'raises an error when no content_type validation exists'
do
assert_raises
(
Paperclip
::
Errors
::
MissingRequiredValidatorError
)
do
assert_raises
(
Paperclip
::
Errors
::
MissingRequiredValidatorError
)
do
Dummy
.
new
(
:avatar
=>
File
.
new
(
fixture_file
(
"12k.png"
)))
Dummy
.
new
(
avatar:
File
.
new
(
fixture_file
(
"12k.png"
)))
end
end
end
end
it
'does not raise an error when a content_type validation exists'
do
it
'does not raise an error when a content_type validation exists'
do
Dummy
.
validates_attachment
:avatar
,
:content_type
=>
{
:content_type
=>
"image/jpeg"
}
Dummy
.
validates_attachment
:avatar
,
content_type:
{
content_type:
"image/jpeg"
}
assert_nothing_raised
do
assert_nothing_raised
do
Dummy
.
new
(
:avatar
=>
File
.
new
(
fixture_file
(
"12k.png"
)))
Dummy
.
new
(
avatar:
File
.
new
(
fixture_file
(
"12k.png"
)))
end
end
end
end
it
'does not raise an error when a file_name validation exists'
do
it
'does not raise an error when a file_name validation exists'
do
Dummy
.
validates_attachment
:avatar
,
:file_name
=>
{
:matches
=>
/png$/
}
Dummy
.
validates_attachment
:avatar
,
file_name:
{
matches:
/png$/
}
assert_nothing_raised
do
assert_nothing_raised
do
Dummy
.
new
(
:avatar
=>
File
.
new
(
fixture_file
(
"12k.png"
)))
Dummy
.
new
(
avatar:
File
.
new
(
fixture_file
(
"12k.png"
)))
end
end
end
end
it
'does not raise an error when a the validation has been explicitly rejected'
do
it
'does not raise an error when a the validation has been explicitly rejected'
do
Dummy
.
validates_attachment
:avatar
,
:file_type_ignorance
=>
true
Dummy
.
validates_attachment
:avatar
,
file_type_ignorance:
true
assert_nothing_raised
do
assert_nothing_raised
do
Dummy
.
new
(
:avatar
=>
File
.
new
(
fixture_file
(
"12k.png"
)))
Dummy
.
new
(
avatar:
File
.
new
(
fixture_file
(
"12k.png"
)))
end
end
end
end
end
end
...
...
spec/spec_helper.rb
View file @
40010c4d
...
@@ -54,7 +54,7 @@ end
...
@@ -54,7 +54,7 @@ end
def
reset_table
table_name
,
&
block
def
reset_table
table_name
,
&
block
block
||=
lambda
{
|
table
|
true
}
block
||=
lambda
{
|
table
|
true
}
ActiveRecord
::
Base
.
connection
.
create_table
:dummies
,
{
:force
=>
true
},
&
block
ActiveRecord
::
Base
.
connection
.
create_table
:dummies
,
{
force:
true
},
&
block
end
end
def
modify_table
table_name
,
&
block
def
modify_table
table_name
,
&
block
...
@@ -62,7 +62,7 @@ def modify_table table_name, &block
...
@@ -62,7 +62,7 @@ def modify_table table_name, &block
end
end
def
rebuild_model
options
=
{}
def
rebuild_model
options
=
{}
ActiveRecord
::
Base
.
connection
.
create_table
:dummies
,
:force
=>
true
do
|
table
|
ActiveRecord
::
Base
.
connection
.
create_table
:dummies
,
force:
true
do
|
table
|
table
.
column
:title
,
:string
table
.
column
:title
,
:string
table
.
column
:other
,
:string
table
.
column
:other
,
:string
table
.
column
:avatar_file_name
,
:string
table
.
column
:avatar_file_name
,
:string
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment