dynamic_paperclip 0.0.4 → 1.0.0a.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +33 -25
- data/lib/dynamic_paperclip/attachment.rb +5 -1
- data/lib/dynamic_paperclip/attachment_registry.rb +4 -0
- data/lib/dynamic_paperclip/attachment_style_generator.rb +73 -0
- data/lib/dynamic_paperclip/errors.rb +0 -9
- data/lib/dynamic_paperclip/has_attached_file.rb +3 -19
- data/lib/dynamic_paperclip/railtie.rb +9 -0
- data/lib/dynamic_paperclip/version.rb +1 -1
- data/lib/dynamic_paperclip.rb +6 -1
- data/lib/generators/dynamic_paperclip/install_generator.rb +1 -3
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +5561 -0
- data/test/generators/install_generator_test.rb +1 -3
- data/test/tmp/config/initializers/dynamic_paperclip.rb +1 -1
- data/test/unit/attachment_style_generator_test.rb +95 -0
- data/test/unit/attachment_test.rb +2 -2
- data/test/unit/has_attached_file_test.rb +4 -22
- metadata +68 -16
- data/app/controllers/dynamic_paperclip/attachment_styles_controller.rb +0 -43
- data/lib/dynamic_paperclip/engine.rb +0 -4
- data/test/controllers/attachment_style_controller_test.rb +0 -129
@@ -13,8 +13,6 @@ class InstallGeneratorTest < Rails::Generators::TestCase
|
|
13
13
|
|
14
14
|
run_generator
|
15
15
|
|
16
|
-
assert_file "config/initializers/dynamic_paperclip.rb",
|
17
|
-
DynamicPaperclip.config.secret = 'supersecurestring'
|
18
|
-
init
|
16
|
+
assert_file "config/initializers/dynamic_paperclip.rb", "DynamicPaperclip.config.secret = 'supersecurestring'"
|
19
17
|
end
|
20
18
|
end
|
@@ -1 +1 @@
|
|
1
|
-
DynamicPaperclip.config.secret = 'supersecurestring'
|
1
|
+
DynamicPaperclip.config.secret = 'supersecurestring'
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Foo < ActiveRecord::Base
|
4
|
+
has_dynamic_attached_file :image,
|
5
|
+
:url => '/system/:class/:attachment/:id/:style/:filename'
|
6
|
+
|
7
|
+
has_dynamic_attached_file :image_with_id_partition_in_url,
|
8
|
+
:url => '/system/:class/:attachment/:id_partition/:style/:filename'
|
9
|
+
end
|
10
|
+
|
11
|
+
class DynamicPaperclip::AttachmentStyleGeneratorTest < Test::Unit::TestCase
|
12
|
+
include Rack::Test::Methods
|
13
|
+
|
14
|
+
def app
|
15
|
+
DynamicPaperclip::AttachmentStyleGenerator.new(@app)
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@app = stub('Application', :call => [200, {}, ''])
|
20
|
+
|
21
|
+
@foo = stub('foo')
|
22
|
+
@attachment = stub('image attachment', :path => File.join(FIXTURES_DIR, 'rails.png'), :content_type => 'image/jpeg')
|
23
|
+
@attachment.stubs(:exists?).returns(true)
|
24
|
+
|
25
|
+
Foo.stubs(:find).with(1).returns @foo
|
26
|
+
@foo.stubs(:image).returns @attachment
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'not process style if it already exists' do
|
30
|
+
@attachment.expects(:exists?).with(:dynamic_42x42).returns(true)
|
31
|
+
@attachment.expects(:process_dynamic_style).never
|
32
|
+
|
33
|
+
get '/system/foos/images/1/dynamic_42x42/file', { s: DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42') }
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'process style if it is dynamic and does not exist' do
|
37
|
+
@attachment.expects(:exists?).with(:dynamic_42x42).returns(false)
|
38
|
+
@attachment.expects(:process_dynamic_style).once
|
39
|
+
|
40
|
+
get '/system/foos/images/1/dynamic_42x42/file', { s: DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42') }
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'find record when an ID is used' do
|
44
|
+
Foo.expects(:find).with(1).returns @foo
|
45
|
+
|
46
|
+
get '/system/foos/images/1/dynamic_42x42/file', { s: DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42') }
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'find record when an ID partition is used' do
|
50
|
+
@foo.stubs(:image_with_id_partition_in_url).returns @attachment
|
51
|
+
Foo.expects(:find).with(10042).returns @foo
|
52
|
+
|
53
|
+
get '/system/foos/image_with_id_partition_in_urls/000/010/042/dynamic_42x42/file', { s: DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42') }
|
54
|
+
end
|
55
|
+
|
56
|
+
should 'respond with correct content type' do
|
57
|
+
get '/system/foos/images/1/dynamic_42x42/file', { s: DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42') }
|
58
|
+
|
59
|
+
assert_equal 'image/jpeg', last_response.header['Content-Type']
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'respond with correct content-disposition' do
|
63
|
+
get '/system/foos/images/1/dynamic_42x42/file', { s: DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42') }
|
64
|
+
|
65
|
+
assert_equal 'inline; filename=rails.png', last_response.header['Content-Disposition']
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'respond with correct content-transfer-encoding' do
|
69
|
+
get '/system/foos/images/1/dynamic_42x42/file', { s: DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42') }
|
70
|
+
|
71
|
+
assert_equal 'binary', last_response.header['Content-Transfer-Encoding']
|
72
|
+
end
|
73
|
+
|
74
|
+
should 'respond with FileBody' do
|
75
|
+
file_body = ActionController::DataStreaming::FileBody.new(File.join(FIXTURES_DIR, 'rails.png'))
|
76
|
+
ActionController::DataStreaming::FileBody.expects(:new).with(File.join(FIXTURES_DIR, 'rails.png')).returns(file_body)
|
77
|
+
|
78
|
+
response = app.call(Rack::MockRequest.env_for('/system/foos/images/1/dynamic_42x42/file?s='+DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42')))
|
79
|
+
|
80
|
+
assert_equal file_body, response[2]
|
81
|
+
end
|
82
|
+
|
83
|
+
should 'respond with success' do
|
84
|
+
get '/system/foos/images/1/dynamic_42x42/file', { s: DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42') }
|
85
|
+
|
86
|
+
assert last_response.ok?
|
87
|
+
end
|
88
|
+
|
89
|
+
should '403 with empty body if hash does not match style name' do
|
90
|
+
get '/system/foos/images/1/dynamic_42x42/file', { s: 'this is an invalid hash' }
|
91
|
+
|
92
|
+
assert_equal 403, last_response.status
|
93
|
+
assert_equal '', last_response.body
|
94
|
+
end
|
95
|
+
end
|
@@ -10,7 +10,7 @@ class AttachmentTest < ActiveSupport::TestCase
|
|
10
10
|
should 'generate correct secure attachment URL when given a style definition' do
|
11
11
|
DynamicPaperclip::Config.any_instance.stubs(:secret).returns('abc123')
|
12
12
|
|
13
|
-
assert_equal "/system/photos/images/000/000/001/dynamic_50x50%
|
13
|
+
assert_equal "/system/photos/images/000/000/001/dynamic_50x50%2523/rails.png?s=#{Digest::SHA1.hexdigest("abc123dynamic_50x50%23")}", photos(:rails).image.dynamic_url('50x50#')
|
14
14
|
end
|
15
15
|
|
16
16
|
should 'raise error if no secret has been configured' do
|
@@ -34,7 +34,7 @@ class AttachmentTest < ActiveSupport::TestCase
|
|
34
34
|
|
35
35
|
attachment.expects(:reprocess!).with(:dynamic_42x42).once
|
36
36
|
|
37
|
-
attachment.process_dynamic_style
|
37
|
+
attachment.process_dynamic_style :dynamic_42x42
|
38
38
|
|
39
39
|
assert_equal '42x42', attachment.styles[:dynamic_42x42].geometry
|
40
40
|
end
|
@@ -1,29 +1,11 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class Foo; end
|
3
|
+
class Foo < ActiveRecord::Base; end
|
4
4
|
|
5
5
|
class HasAttachedFileTest < Test::Unit::TestCase
|
6
|
-
should '
|
7
|
-
DynamicPaperclip::
|
6
|
+
should 'register dynamic attachment' do
|
7
|
+
DynamicPaperclip::AttachmentRegistry.expects(:register).with(Foo, :bar, { url: '/system/foos/bars/:id_partition/:style/:filename' })
|
8
8
|
|
9
|
-
|
10
|
-
route.path.spec == '/system/foos/bars/*id_partition/:style/:filename(.:format)'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
should 'interpolate :class' do
|
15
|
-
DynamicPaperclip::HasAttachedFile.new Foo, :bar, { url: '/system/:class/bars/:id/:style/:filename' }
|
16
|
-
|
17
|
-
assert Rails.application.routes.routes.any? do |route|
|
18
|
-
route.path.spec == '/system/foos/bars/:id/:style/:filename(.:format)'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
should "use Paperclip's default URL if none is specified" do
|
23
|
-
DynamicPaperclip::HasAttachedFile.new Foo, :bar, {}
|
24
|
-
|
25
|
-
assert Rails.application.routes.routes.any? do |route|
|
26
|
-
route.path.spec == '/system/foos/:attachment/*id_partition/:style/:filename(.:format)'
|
27
|
-
end
|
9
|
+
DynamicPaperclip::HasAttachedFile.define_on Foo, :bar, { url: '/system/foos/bars/:id_partition/:style/:filename' }
|
28
10
|
end
|
29
11
|
end
|
metadata
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0a.1
|
5
|
+
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jim Ryan
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: rack
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - ! '
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - ! '
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: paperclip
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 3.5.
|
37
|
+
version: 3.5.1
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,39 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 3.5.
|
45
|
+
version: 3.5.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activesupport
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: actionpack
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.2'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.2'
|
46
78
|
- !ruby/object:Gem::Dependency
|
47
79
|
name: sqlite3
|
48
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,6 +123,22 @@ dependencies:
|
|
91
123
|
- - ! '>='
|
92
124
|
- !ruby/object:Gem::Version
|
93
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rails
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>'
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '3.2'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>'
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '3.2'
|
94
142
|
description: Let's your views define attachment styles, and delays processing all
|
95
143
|
the way to the first user who requests it.
|
96
144
|
email:
|
@@ -99,13 +147,14 @@ executables: []
|
|
99
147
|
extensions: []
|
100
148
|
extra_rdoc_files: []
|
101
149
|
files:
|
102
|
-
- app/controllers/dynamic_paperclip/attachment_styles_controller.rb
|
103
150
|
- lib/dynamic_paperclip/attachment.rb
|
151
|
+
- lib/dynamic_paperclip/attachment_registry.rb
|
152
|
+
- lib/dynamic_paperclip/attachment_style_generator.rb
|
104
153
|
- lib/dynamic_paperclip/config.rb
|
105
|
-
- lib/dynamic_paperclip/engine.rb
|
106
154
|
- lib/dynamic_paperclip/errors.rb
|
107
155
|
- lib/dynamic_paperclip/has_attached_file.rb
|
108
156
|
- lib/dynamic_paperclip/paperclip_shim.rb
|
157
|
+
- lib/dynamic_paperclip/railtie.rb
|
109
158
|
- lib/dynamic_paperclip/style_naming.rb
|
110
159
|
- lib/dynamic_paperclip/url_security.rb
|
111
160
|
- lib/dynamic_paperclip/version.rb
|
@@ -114,7 +163,6 @@ files:
|
|
114
163
|
- MIT-LICENSE
|
115
164
|
- Rakefile
|
116
165
|
- README.md
|
117
|
-
- test/controllers/attachment_style_controller_test.rb
|
118
166
|
- test/dummy/app/controllers/application_controller.rb
|
119
167
|
- test/dummy/app/models/photo.rb
|
120
168
|
- test/dummy/config/application.rb
|
@@ -150,6 +198,7 @@ files:
|
|
150
198
|
- test/integration/dynamic_attachment_styles_test.rb
|
151
199
|
- test/test_helper.rb
|
152
200
|
- test/tmp/config/initializers/dynamic_paperclip.rb
|
201
|
+
- test/unit/attachment_style_generator_test.rb
|
153
202
|
- test/unit/attachment_test.rb
|
154
203
|
- test/unit/has_attached_file_test.rb
|
155
204
|
homepage: http://github.com/room118solutions/dynamic_paperclip
|
@@ -164,12 +213,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
213
|
- - ! '>='
|
165
214
|
- !ruby/object:Gem::Version
|
166
215
|
version: '0'
|
216
|
+
segments:
|
217
|
+
- 0
|
218
|
+
hash: 2045189592495985284
|
167
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
220
|
none: false
|
169
221
|
requirements:
|
170
|
-
- - ! '
|
222
|
+
- - ! '>'
|
171
223
|
- !ruby/object:Gem::Version
|
172
|
-
version:
|
224
|
+
version: 1.3.1
|
173
225
|
requirements: []
|
174
226
|
rubyforge_project:
|
175
227
|
rubygems_version: 1.8.25
|
@@ -177,7 +229,6 @@ signing_key:
|
|
177
229
|
specification_version: 3
|
178
230
|
summary: Generate Paperclip attachment styles on the fly
|
179
231
|
test_files:
|
180
|
-
- test/controllers/attachment_style_controller_test.rb
|
181
232
|
- test/dummy/app/controllers/application_controller.rb
|
182
233
|
- test/dummy/app/models/photo.rb
|
183
234
|
- test/dummy/config/application.rb
|
@@ -213,5 +264,6 @@ test_files:
|
|
213
264
|
- test/integration/dynamic_attachment_styles_test.rb
|
214
265
|
- test/test_helper.rb
|
215
266
|
- test/tmp/config/initializers/dynamic_paperclip.rb
|
267
|
+
- test/unit/attachment_style_generator_test.rb
|
216
268
|
- test/unit/attachment_test.rb
|
217
269
|
- test/unit/has_attached_file_test.rb
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module DynamicPaperclip
|
2
|
-
class AttachmentStylesController < ApplicationController
|
3
|
-
def action_missing(name, *args, &block)
|
4
|
-
if name =~ /^generate_(.+)$/
|
5
|
-
send :generate, $1
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def generate(class_name)
|
12
|
-
klass = class_name.camelize.constantize
|
13
|
-
attachment_name = params[:attachment].singularize.to_sym
|
14
|
-
|
15
|
-
# Ensure that we have a valid attachment name and an ID
|
16
|
-
raise Errors::UndefinedAttachment unless klass.attachment_definitions[attachment_name]
|
17
|
-
raise Errors::MissingID unless params[:id] || params[:id_partition]
|
18
|
-
|
19
|
-
id = params[:id] || id_from_partition(params[:id_partition])
|
20
|
-
|
21
|
-
attachment = klass.find(id).send(attachment_name)
|
22
|
-
|
23
|
-
# The definition will be escaped twice in the URL, Rails will unescape it once for us,
|
24
|
-
# so it will already be escaped once, so we don't need to escape it again. We should always
|
25
|
-
# reference dynamic style names after escaping once - that's how they reside on the FS.
|
26
|
-
style_name = StyleNaming.dynamic_style_name_from_definition(params[:definition], false)
|
27
|
-
|
28
|
-
# Validate URL hash against requested style name
|
29
|
-
raise Errors::InvalidHash unless DynamicPaperclip::UrlSecurity.valid_hash?(params[:s], style_name)
|
30
|
-
|
31
|
-
# Only process style if it doesn't exist,
|
32
|
-
# otherwise we may just be fielding a request for
|
33
|
-
# an existing style (i.e. serve_static_assets is true)
|
34
|
-
attachment.process_dynamic_style style_name unless attachment.exists?(style_name)
|
35
|
-
|
36
|
-
send_file attachment.path(style_name), :disposition => 'inline', :type => attachment.content_type
|
37
|
-
end
|
38
|
-
|
39
|
-
def id_from_partition(partition)
|
40
|
-
partition.gsub('/', '').to_i
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Foo < ActiveRecord::Base
|
4
|
-
has_dynamic_attached_file :image,
|
5
|
-
:url => '/system/:class/:attachment/:id/:style/:filename'
|
6
|
-
|
7
|
-
has_dynamic_attached_file :image_with_id_partition_in_url,
|
8
|
-
:url => '/system/:class/:attachment/:id_partition/:style/:filename'
|
9
|
-
end
|
10
|
-
|
11
|
-
class DynamicPaperclip::AttachmentStylesControllerTest < ActionController::TestCase
|
12
|
-
setup do
|
13
|
-
@foo = stub('foo')
|
14
|
-
@attachment = stub('image attachment', :path => File.join(FIXTURES_DIR, 'rails.png'), :content_type => 'image/jpeg')
|
15
|
-
@attachment.stubs(:exists?).returns(true)
|
16
|
-
|
17
|
-
Foo.stubs(:find).with('1').returns @foo
|
18
|
-
@foo.stubs(:image).returns @attachment
|
19
|
-
end
|
20
|
-
|
21
|
-
should 'raise error if attachment is not defined on class' do
|
22
|
-
assert_raises(DynamicPaperclip::Errors::UndefinedAttachment) {
|
23
|
-
get :generate_foo,
|
24
|
-
:attachment => 'bars',
|
25
|
-
:id => '1',
|
26
|
-
:style => 'style',
|
27
|
-
:filename => 'file',
|
28
|
-
:use_route => :dynamic_paperclip_engine
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
should 'raise error if no ID is given' do
|
33
|
-
assert_raises(DynamicPaperclip::Errors::MissingID) {
|
34
|
-
get :generate_foo,
|
35
|
-
:attachment => 'images',
|
36
|
-
:style => 'style',
|
37
|
-
:filename => 'file',
|
38
|
-
:use_route => :dynamic_paperclip_engine
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
should 'not process style if it already exists' do
|
43
|
-
@attachment.expects(:exists?).with(:dynamic_42x42).returns(true)
|
44
|
-
@attachment.expects(:process_dynamic_style).never
|
45
|
-
|
46
|
-
get :generate_foo,
|
47
|
-
:attachment => 'images',
|
48
|
-
:id => '1',
|
49
|
-
:definition => '42x42',
|
50
|
-
:filename => 'file',
|
51
|
-
:s => DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42'),
|
52
|
-
:use_route => :dynamic_paperclip_engine
|
53
|
-
end
|
54
|
-
|
55
|
-
should 'process style if it is dynamic and does not exist' do
|
56
|
-
@attachment.expects(:exists?).with(:dynamic_42x42).returns(false)
|
57
|
-
@attachment.expects(:process_dynamic_style).once
|
58
|
-
|
59
|
-
get :generate_foo,
|
60
|
-
:attachment => 'images',
|
61
|
-
:id => '1',
|
62
|
-
:definition => '42x42',
|
63
|
-
:filename => 'file',
|
64
|
-
:s => DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42'),
|
65
|
-
:use_route => :dynamic_paperclip_engine
|
66
|
-
end
|
67
|
-
|
68
|
-
should 'find record when an ID is used' do
|
69
|
-
Foo.expects(:find).with('1').returns @foo
|
70
|
-
|
71
|
-
get :generate_foo,
|
72
|
-
:attachment => 'images',
|
73
|
-
:id => '1',
|
74
|
-
:definition => '42x42',
|
75
|
-
:filename => 'file',
|
76
|
-
:s => DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42'),
|
77
|
-
:use_route => :dynamic_paperclip_engine
|
78
|
-
end
|
79
|
-
|
80
|
-
should 'find record when an ID partition is used' do
|
81
|
-
@foo.stubs(:image_with_id_partition_in_url).returns @attachment
|
82
|
-
Foo.expects(:find).with(10042).returns @foo
|
83
|
-
|
84
|
-
get :generate_foo,
|
85
|
-
:attachment => 'image_with_id_partition_in_urls',
|
86
|
-
:id_partition => '000/010/042',
|
87
|
-
:definition => '42x42',
|
88
|
-
:filename => 'file',
|
89
|
-
:s => DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42'),
|
90
|
-
:use_route => :dynamic_paperclip_engine
|
91
|
-
end
|
92
|
-
|
93
|
-
should 'respond with correct content type' do
|
94
|
-
get :generate_foo,
|
95
|
-
:attachment => 'images',
|
96
|
-
:id => '1',
|
97
|
-
:definition => '42x42',
|
98
|
-
:filename => 'file',
|
99
|
-
:s => DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42'),
|
100
|
-
:use_route => :dynamic_paperclip_engine
|
101
|
-
|
102
|
-
assert_equal 'image/jpeg', @response.header['Content-Type']
|
103
|
-
end
|
104
|
-
|
105
|
-
should 'send image to client with correct content type and disposition' do
|
106
|
-
@controller.stubs(:render)
|
107
|
-
@controller.expects(:send_file).with(@attachment.path, :disposition => 'inline', :type => @attachment.content_type)
|
108
|
-
|
109
|
-
get :generate_foo,
|
110
|
-
:attachment => 'images',
|
111
|
-
:id => '1',
|
112
|
-
:definition => '42x42',
|
113
|
-
:filename => 'file',
|
114
|
-
:s => DynamicPaperclip::UrlSecurity.generate_hash('dynamic_42x42'),
|
115
|
-
:use_route => :dynamic_paperclip_engine
|
116
|
-
end
|
117
|
-
|
118
|
-
should 'raise error if hash does not match style name' do
|
119
|
-
assert_raises(DynamicPaperclip::Errors::InvalidHash) do
|
120
|
-
get :generate_foo,
|
121
|
-
:attachment => 'images',
|
122
|
-
:id => '1',
|
123
|
-
:definition => '42x42',
|
124
|
-
:filename => 'file',
|
125
|
-
:s => 'this is an invalid hash',
|
126
|
-
:use_route => :dynamic_paperclip_engine
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|