uploader 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -0
- data/VERSION +1 -1
- data/lib/active_record/acts/uploader_upload.rb +4 -8
- data/rdoc/created.rid +1 -1
- data/rdoc/files/lib/uploader_rb.html +2 -3
- data/test/rails_root/app/models/upload.rb +4 -3
- data/test/rails_root/config/environment.rb +1 -0
- data/test/rails_root/config/initializers/uploader.rb +9 -9
- data/test/rails_root/test/fixtures/files/5k.png +0 -0
- data/test/rails_root/test/shoulda_macros/paperclip.rb +68 -0
- data/test/rails_root/test/test_helper.rb +1 -0
- data/test/rails_root/test/unit/upload_test.rb +45 -2
- data/uploader.gemspec +4 -2
- metadata +4 -2
- data/pkg/uploader-0.1.13.gem +0 -0
data/README.rdoc
CHANGED
@@ -55,6 +55,9 @@ We recommend creating a model called upload.rb. acts_as_uploader accepts all va
|
|
55
55
|
# only allow images:
|
56
56
|
# validates_attachment_content_type :file, :content_type => ['image/jpeg', 'image/pjpeg', 'image/jpg']
|
57
57
|
|
58
|
+
# limit uploads to 10 MB
|
59
|
+
# validates_attachment_size :local, :less_than => 10.megabytes
|
60
|
+
|
58
61
|
# The following method is implemented in 'acts_as_uploader'. This is the method destroy will check to see if
|
59
62
|
# the user has permission to delete the object. Add additional logic as needed or if the existing logic
|
60
63
|
# looks fine then feel free to delete this comment and the can_edit? method.
|
@@ -319,5 +322,10 @@ The following jQuery code will do an ajax delete for you
|
|
319
322
|
}
|
320
323
|
|
321
324
|
|
325
|
+
=== Testing
|
326
|
+
If you intend to develop code and wish to run the tests you may do so using rake test. However, note that you will need to install the gem first using
|
327
|
+
rake install since the embedded test application will use the gem that is install and not the current code from the project. This is a limitation
|
328
|
+
I attempted to overcome using a special initializer in rails_root/config/initializers/uploader.rb but I didn't have any success getting it working.
|
329
|
+
|
322
330
|
|
323
331
|
Copyright (c) 2009 Justin Ball, released under the MIT license
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.15
|
@@ -27,21 +27,17 @@ module ActiveRecord
|
|
27
27
|
named_scope :files, :conditions => "local_content_type NOT IN (#{Uploader::MimeTypeGroups::IMAGE_TYPES.collect{|type| "'#{type}'"}.join(',')})"
|
28
28
|
named_scope :since, lambda { |*args| { :conditions => ["created_at > ?", (args.first || 7.days.ago.to_s(:db)) ]} }
|
29
29
|
named_scope :pending_s3_migration, lambda { { :conditions => ["remote_file_name IS NULL AND created_at <= ?", 20.minutes.ago.to_s(:db)], :order => 'created_at DESC' } }
|
30
|
-
|
30
|
+
|
31
31
|
# Paperclip
|
32
32
|
has_attached_file :local, options[:has_attached_file].merge(:storage => :filesystem) # Override any storage settings. This one has to be local.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
:storage => :s3)
|
37
|
-
end
|
38
|
-
|
33
|
+
has_attached_file :remote, options[:has_attached_file].merge(:url => ':s3_alias_url',
|
34
|
+
:path => options[:s3_path],
|
35
|
+
:storage => :s3)
|
39
36
|
|
40
37
|
belongs_to :uploadable, :polymorphic => true
|
41
38
|
belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
|
42
39
|
|
43
40
|
class_eval <<-EOV
|
44
|
-
validates_attachment_size :local, :less_than => 10.megabytes
|
45
41
|
|
46
42
|
before_post_process :transliterate_file_name
|
47
43
|
before_create :add_width_and_height
|
data/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Thu, 04 Jun 2009 14:32:21 -0600
|
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Thu Jun 04 14:21:29 -0600 2009</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -73,11 +73,10 @@
|
|
73
73
|
<h3 class="section-bar">Required files</h3>
|
74
74
|
|
75
75
|
<div class="name-list">
|
76
|
+
active_record/acts/uploader_upload
|
76
77
|
uploader/exceptions
|
77
78
|
uploader/mime_type_groups
|
78
79
|
uploader/middleware/flash_session_cookie_middleware
|
79
|
-
thoughtbot-paperclip
|
80
|
-
mime/types
|
81
80
|
</div>
|
82
81
|
</div>
|
83
82
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Upload < ActiveRecord::Base
|
2
|
-
|
3
|
-
acts_as_uploader :enable_s3 =>
|
2
|
+
|
3
|
+
acts_as_uploader :enable_s3 => true,
|
4
4
|
:has_attached_file => {
|
5
5
|
:url => "/system/:attachment/:id_partition/:style/:basename.:extension",
|
6
6
|
:path => ":rails_root/public/system/:attachment/:id_partition/:style/:basename.:extension",
|
@@ -20,9 +20,10 @@ class Upload < ActiveRecord::Base
|
|
20
20
|
}
|
21
21
|
|
22
22
|
validates_attachment_presence :local
|
23
|
+
validates_attachment_size :local, :less_than => 10.megabytes
|
23
24
|
|
24
25
|
def can_edit?(user)
|
25
26
|
return true
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
end
|
@@ -19,4 +19,5 @@ Rails::Initializer.run do |config|
|
|
19
19
|
config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
|
20
20
|
config.time_zone = 'UTC'
|
21
21
|
config.gem 'thoughtbot-paperclip', :version => '~> 2.2.2', :lib => 'paperclip', :source => 'http://gems.github.com'
|
22
|
+
config.gem 'uploader'
|
22
23
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# This simulates loading the uploader gem, but without relying on vendor/gems
|
2
2
|
|
3
|
-
path = File.join(File.dirname(__FILE__), *%w(.. .. .. ..))
|
4
|
-
lib_path = File.join(path, "lib")
|
5
|
-
app_path = File.join(path, "app")
|
6
|
-
|
7
|
-
require File.join(app_path, 'helpers', 'uploader_helper')
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift(lib_path)
|
10
|
-
$LOAD_PATH.unshift(app_path)
|
11
|
-
load File.join(path, 'rails', 'init.rb')
|
3
|
+
# path = File.join(File.dirname(__FILE__), *%w(.. .. .. ..))
|
4
|
+
# lib_path = File.join(path, "lib")
|
5
|
+
# app_path = File.join(path, "app")
|
6
|
+
#
|
7
|
+
# require File.join(app_path, 'helpers', 'uploader_helper')
|
8
|
+
#
|
9
|
+
# $LOAD_PATH.unshift(lib_path)
|
10
|
+
# $LOAD_PATH.unshift(app_path)
|
11
|
+
# load File.join(path, 'rails', 'init.rb')
|
Binary file
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'paperclip/matchers'
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
# =Paperclip Shoulda Macros
|
5
|
+
#
|
6
|
+
# These macros are intended for use with shoulda, and will be included into
|
7
|
+
# your tests automatically. All of the macros use the standard shoulda
|
8
|
+
# assumption that the name of the test is based on the name of the model
|
9
|
+
# you're testing (that is, UserTest is the test for the User model), and
|
10
|
+
# will load that class for testing purposes.
|
11
|
+
module Shoulda
|
12
|
+
include Matchers
|
13
|
+
# This will test whether you have defined your attachment correctly by
|
14
|
+
# checking for all the required fields exist after the definition of the
|
15
|
+
# attachment.
|
16
|
+
def should_have_attached_file name
|
17
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
18
|
+
matcher = have_attached_file name
|
19
|
+
should matcher.description do
|
20
|
+
assert_accepts(matcher, klass)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Tests for validations on the presence of the attachment.
|
25
|
+
def should_validate_attachment_presence name
|
26
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
27
|
+
matcher = validate_attachment_presence name
|
28
|
+
should matcher.description do
|
29
|
+
assert_accepts(matcher, klass)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Tests that you have content_type validations specified. There are two
|
34
|
+
# options, :valid and :invalid. Both accept an array of strings. The
|
35
|
+
# strings should be a list of content types which will pass and fail
|
36
|
+
# validation, respectively.
|
37
|
+
def should_validate_attachment_content_type name, options = {}
|
38
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
39
|
+
valid = [options[:valid]].flatten
|
40
|
+
invalid = [options[:invalid]].flatten
|
41
|
+
matcher = validate_attachment_content_type(name).allowing(valid).rejecting(invalid)
|
42
|
+
should matcher.description do
|
43
|
+
assert_accepts(matcher, klass)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Tests to ensure that you have file size validations turned on. You
|
48
|
+
# can pass the same options to this that you can to
|
49
|
+
# validate_attachment_file_size - :less_than, :greater_than, and :in.
|
50
|
+
# :less_than checks that a file is less than a certain size, :greater_than
|
51
|
+
# checks that a file is more than a certain size, and :in takes a Range or
|
52
|
+
# Array which specifies the lower and upper limits of the file size.
|
53
|
+
def should_validate_attachment_size name, options = {}
|
54
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
55
|
+
min = options[:greater_than] || (options[:in] && options[:in].first) || 0
|
56
|
+
max = options[:less_than] || (options[:in] && options[:in].last) || (1.0/0)
|
57
|
+
range = (min..max)
|
58
|
+
matcher = validate_attachment_size(name).in(range)
|
59
|
+
should matcher.description do
|
60
|
+
assert_accepts(matcher, klass)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class Test::Unit::TestCase #:nodoc:
|
67
|
+
extend Paperclip::Shoulda
|
68
|
+
end
|
@@ -9,6 +9,7 @@ require 'ruby-debug'
|
|
9
9
|
require 'mocha'
|
10
10
|
require 'redgreen' rescue LoadError
|
11
11
|
require File.expand_path(File.dirname(__FILE__) + '/factories')
|
12
|
+
require File.join(File.dirname(__FILE__), 'shoulda_macros', 'paperclip')
|
12
13
|
class ActiveSupport::TestCase
|
13
14
|
|
14
15
|
VALID_FILE = ActionController::TestUploadedFile.new(File.join(RAILS_ROOT, 'public/images/rails.png'), 'image/png')
|
@@ -1,5 +1,48 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class UploadTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
|
5
|
+
context 'upload instance' do
|
6
|
+
|
7
|
+
should_belong_to :uploadable
|
8
|
+
should_belong_to :creator
|
9
|
+
|
10
|
+
should_have_attached_file :local
|
11
|
+
should_have_attached_file :remote
|
12
|
+
should_not_allow_mass_assignment_of :creator_id, :uploadable_id, :uploadable_type
|
13
|
+
should_validate_attachment_size :local, :less_than => 10.megabytes
|
14
|
+
|
15
|
+
should 'use id_partitioning' do
|
16
|
+
upload = Upload.new
|
17
|
+
upload.stubs(:id).returns(12345)
|
18
|
+
upload.local = VALID_FILE
|
19
|
+
assert_equal "#{RAILS_ROOT}/public/system/locals/000/012/345/original/rails.png", upload.local.path
|
20
|
+
assert_equal '/system/locals/000/012/345/original/rails.png', upload.local.url(:original, false)
|
21
|
+
end
|
22
|
+
|
23
|
+
should 'transliterate the filename' do
|
24
|
+
upload = Upload.new
|
25
|
+
file = fixture_file %Q{IT'sUPPERCASE!AND WeIRD.JPG}
|
26
|
+
upload.local = file
|
27
|
+
assert_equal 'it-suppercase-and-weird.jpg', upload.local.original_filename
|
28
|
+
file.close
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
# Named scopes
|
34
|
+
should_have_named_scope :newest_first
|
35
|
+
should_have_named_scope :alphabetic
|
36
|
+
should_have_named_scope :recent
|
37
|
+
should_have_named_scope :public
|
38
|
+
should_have_named_scope :images
|
39
|
+
should_have_named_scope :documents
|
40
|
+
should_have_named_scope :files
|
41
|
+
should_have_named_scope :since
|
42
|
+
should_have_named_scope :pending_s3_migration
|
43
|
+
|
44
|
+
private
|
45
|
+
def fixture_file(name)
|
46
|
+
File.new(File.join(RAILS_ROOT, 'test', 'fixtures', 'files', name), 'rb')
|
47
|
+
end
|
48
|
+
end
|
data/uploader.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{uploader}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.15"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Justin Ball", "David South"]
|
@@ -64,7 +64,6 @@ Gem::Specification.new do |s|
|
|
64
64
|
"locales/zh-CN.yml",
|
65
65
|
"locales/zh-TW.yml",
|
66
66
|
"locales/zh.yml",
|
67
|
-
"pkg/uploader-0.1.13.gem",
|
68
67
|
"public/images/SWFUploadButton.png",
|
69
68
|
"public/images/file_icons/excel.gif",
|
70
69
|
"public/images/file_icons/file.gif",
|
@@ -223,11 +222,13 @@ Gem::Specification.new do |s|
|
|
223
222
|
"test/rails_root/script/runner",
|
224
223
|
"test/rails_root/script/server",
|
225
224
|
"test/rails_root/test/factories.rb",
|
225
|
+
"test/rails_root/test/fixtures/files/5k.png",
|
226
226
|
"test/rails_root/test/functional/.keep",
|
227
227
|
"test/rails_root/test/functional/uploads_controller_test.rb",
|
228
228
|
"test/rails_root/test/integration/.keep",
|
229
229
|
"test/rails_root/test/mocks/development/.keep",
|
230
230
|
"test/rails_root/test/mocks/test/.keep",
|
231
|
+
"test/rails_root/test/shoulda_macros/paperclip.rb",
|
231
232
|
"test/rails_root/test/test_helper.rb",
|
232
233
|
"test/rails_root/test/unit/.keep",
|
233
234
|
"test/rails_root/test/unit/upload_test.rb",
|
@@ -267,6 +268,7 @@ Gem::Specification.new do |s|
|
|
267
268
|
"test/rails_root/script/create_project.rb",
|
268
269
|
"test/rails_root/test/factories.rb",
|
269
270
|
"test/rails_root/test/functional/uploads_controller_test.rb",
|
271
|
+
"test/rails_root/test/shoulda_macros/paperclip.rb",
|
270
272
|
"test/rails_root/test/test_helper.rb",
|
271
273
|
"test/rails_root/test/unit/upload_test.rb"
|
272
274
|
]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Ball
|
@@ -93,7 +93,6 @@ files:
|
|
93
93
|
- locales/zh-CN.yml
|
94
94
|
- locales/zh-TW.yml
|
95
95
|
- locales/zh.yml
|
96
|
-
- pkg/uploader-0.1.13.gem
|
97
96
|
- public/images/SWFUploadButton.png
|
98
97
|
- public/images/file_icons/excel.gif
|
99
98
|
- public/images/file_icons/file.gif
|
@@ -250,11 +249,13 @@ files:
|
|
250
249
|
- test/rails_root/script/runner
|
251
250
|
- test/rails_root/script/server
|
252
251
|
- test/rails_root/test/factories.rb
|
252
|
+
- test/rails_root/test/fixtures/files/5k.png
|
253
253
|
- test/rails_root/test/functional/.keep
|
254
254
|
- test/rails_root/test/functional/uploads_controller_test.rb
|
255
255
|
- test/rails_root/test/integration/.keep
|
256
256
|
- test/rails_root/test/mocks/development/.keep
|
257
257
|
- test/rails_root/test/mocks/test/.keep
|
258
|
+
- test/rails_root/test/shoulda_macros/paperclip.rb
|
258
259
|
- test/rails_root/test/test_helper.rb
|
259
260
|
- test/rails_root/test/unit/.keep
|
260
261
|
- test/rails_root/test/unit/upload_test.rb
|
@@ -312,5 +313,6 @@ test_files:
|
|
312
313
|
- test/rails_root/script/create_project.rb
|
313
314
|
- test/rails_root/test/factories.rb
|
314
315
|
- test/rails_root/test/functional/uploads_controller_test.rb
|
316
|
+
- test/rails_root/test/shoulda_macros/paperclip.rb
|
315
317
|
- test/rails_root/test/test_helper.rb
|
316
318
|
- test/rails_root/test/unit/upload_test.rb
|
data/pkg/uploader-0.1.13.gem
DELETED
Binary file
|