attachs 0.4.5 → 4.0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +83 -218
- data/Rakefile +1 -14
- data/lib/attachs.rb +98 -31
- data/lib/attachs/attachment.rb +301 -72
- data/lib/attachs/builder.rb +78 -0
- data/lib/attachs/collection.rb +84 -0
- data/lib/attachs/concern.rb +47 -0
- data/lib/attachs/configuration.rb +11 -0
- data/lib/attachs/console.rb +40 -0
- data/lib/attachs/extensions/active_record/base.rb +24 -0
- data/lib/attachs/extensions/active_record/validations/attachment_content_type_validator.rb +37 -0
- data/lib/attachs/extensions/active_record/validations/attachment_presence_validator.rb +27 -0
- data/lib/attachs/extensions/active_record/validations/attachment_size_validator.rb +55 -0
- data/lib/attachs/extensions/active_record/validations/attachment_validator.rb +24 -0
- data/lib/attachs/interpolations.rb +27 -0
- data/lib/attachs/jobs/base.rb +14 -0
- data/lib/attachs/jobs/delete_job.rb +15 -0
- data/lib/attachs/jobs/update_job.rb +11 -0
- data/lib/attachs/locales/en.yml +2 -6
- data/lib/attachs/locales/es.yml +2 -6
- data/lib/attachs/processors/base.rb +4 -14
- data/lib/attachs/processors/image.rb +45 -0
- data/lib/attachs/railtie.rb +7 -27
- data/lib/attachs/storages/base.rb +10 -59
- data/lib/attachs/storages/s3.rb +68 -63
- data/lib/attachs/version.rb +1 -1
- data/lib/generators/attachs/install/install_generator.rb +15 -0
- data/lib/generators/attachs/install/templates/initializer.rb +7 -0
- data/lib/generators/attachs/upload/templates/migration.rb +11 -0
- data/lib/generators/attachs/upload/templates/model.rb +19 -0
- data/lib/generators/attachs/upload/upload_generator.rb +24 -0
- data/lib/tasks/attachs.rake +12 -26
- data/test/attachment_test.rb +175 -12
- data/test/collection_test.rb +52 -0
- data/test/concern_test.rb +10 -0
- data/test/dummy/Rakefile +1 -2
- data/test/dummy/app/assets/javascripts/application.js +2 -2
- data/test/dummy/app/assets/stylesheets/application.css +6 -4
- data/test/dummy/app/models/product.rb +16 -0
- data/test/dummy/app/models/shop.rb +14 -0
- data/test/dummy/app/models/upload.rb +19 -0
- data/test/dummy/app/views/layouts/application.html.erb +9 -11
- data/test/dummy/bin/bundle +1 -0
- data/test/dummy/bin/rails +2 -1
- data/test/dummy/bin/rake +1 -0
- data/test/dummy/bin/setup +30 -0
- data/test/dummy/config.ru +1 -1
- data/test/dummy/config/application.rb +3 -2
- data/test/dummy/config/boot.rb +1 -1
- data/test/dummy/config/database.yml +4 -22
- data/test/dummy/config/database.yml.travis +3 -0
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +15 -3
- data/test/dummy/config/environments/production.rb +21 -26
- data/test/dummy/config/environments/test.rb +10 -12
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/attachs.rb +7 -21
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/mime_types.rb +1 -2
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/routes.rb +54 -0
- data/test/dummy/config/secrets.yml +24 -0
- data/test/dummy/db/migrate/20161024234003_create_shops.rb +11 -0
- data/test/dummy/db/migrate/20161024234029_create_products.rb +12 -0
- data/test/dummy/db/migrate/20161031135453_create_uploads.rb +11 -0
- data/test/dummy/db/schema.rb +27 -16
- data/test/dummy/log/development.log +61 -0
- data/test/dummy/log/test.log +5873 -0
- data/test/dummy/public/404.html +58 -55
- data/test/dummy/public/422.html +58 -55
- data/test/dummy/public/500.html +57 -54
- data/test/fixtures/big_file.txt +50 -0
- data/test/fixtures/big_image.jpg +0 -0
- data/test/fixtures/file.txt +1 -0
- data/test/fixtures/image.jpg +0 -0
- data/test/{dummy/test/fixtures/file.txt → fixtures/small_file.txt} +0 -0
- data/test/fixtures/small_image.jpg +0 -0
- data/test/generator_test.rb +14 -6
- data/test/helper_test.rb +28 -0
- data/test/query_test.rb +26 -0
- data/test/support/storage_helper.rb +65 -0
- data/test/task_test.rb +69 -0
- data/test/test_helper.rb +6 -45
- data/test/upload_test.rb +27 -0
- data/test/validator_test.rb +160 -0
- metadata +114 -68
- data/lib/attachs/active_record/base.rb +0 -103
- data/lib/attachs/active_record/connection_adapters.rb +0 -40
- data/lib/attachs/active_record/migration.rb +0 -17
- data/lib/attachs/active_record/validators.rb +0 -7
- data/lib/attachs/active_record/validators/attachment_content_type_validator.rb +0 -30
- data/lib/attachs/active_record/validators/attachment_presence_validator.rb +0 -22
- data/lib/attachs/active_record/validators/attachment_size_validator.rb +0 -47
- data/lib/attachs/processors/thumbnail.rb +0 -69
- data/lib/attachs/storages/local.rb +0 -95
- data/lib/attachs/types/base.rb +0 -22
- data/lib/attachs/types/default.rb +0 -29
- data/lib/attachs/types/regular.rb +0 -21
- data/lib/generators/attachs/install_generator.rb +0 -13
- data/lib/generators/attachs/templates/attachs.rb +0 -2
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/app/models/medium.rb +0 -5
- data/test/dummy/app/models/picture.rb +0 -2
- data/test/dummy/config/initializers/secret_token.rb +0 -13
- data/test/dummy/config/s3.yml +0 -15
- data/test/dummy/db/migrate/20140808012639_create_media.rb +0 -11
- data/test/dummy/test/fixtures/image.gif +0 -0
- data/test/local_storage_test.rb +0 -72
- data/test/migration_test.rb +0 -65
- data/test/processor_test.rb +0 -49
- data/test/s3_storage_tes.rb +0 -66
- data/test/tasks_test.rb +0 -57
- data/test/validators_test.rb +0 -100
data/test/query_test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class QueryTest < ActiveSupport::TestCase
|
4
|
+
include StorageHelper
|
5
|
+
|
6
|
+
test 'exist' do
|
7
|
+
shop = Shop.create(name: 'first', logo: image)
|
8
|
+
shop.run_callbacks :commit
|
9
|
+
shop_old_path = shop.logo.paths[:original]
|
10
|
+
shop.update name: 'second'
|
11
|
+
shop.run_callbacks :commit
|
12
|
+
shop_path = shop.logo.paths[:original]
|
13
|
+
|
14
|
+
product = Product.create(pictures: [image, image])
|
15
|
+
product.run_callbacks :commit
|
16
|
+
product_path = product.pictures.first.paths[:original]
|
17
|
+
|
18
|
+
assert Attachs.exists?(shop_old_path)
|
19
|
+
assert Attachs.exists?(shop_path)
|
20
|
+
assert Attachs.exists?(product_path)
|
21
|
+
|
22
|
+
shop.logo.destroy
|
23
|
+
product.pictures.destroy
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module StorageHelper
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def build_upload_file(path, content_type)
|
7
|
+
fixtures_path = File.expand_path('../../fixtures', __FILE__)
|
8
|
+
filename = File.basename(path)
|
9
|
+
extension = File.extname(path)
|
10
|
+
tempfile = Tempfile.new([filename, extension])
|
11
|
+
FileUtils.copy_file File.join(fixtures_path, path), tempfile.path
|
12
|
+
ActionDispatch::Http::UploadedFile.new(
|
13
|
+
tempfile: tempfile,
|
14
|
+
filename: filename,
|
15
|
+
type: content_type
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
%i(file small_file big_file).each do |name|
|
20
|
+
define_method name do
|
21
|
+
build_upload_file "#{name}.txt", 'text/plain'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
%i(image small_image big_image).each do |name|
|
26
|
+
define_method name do
|
27
|
+
build_upload_file "#{name}.jpg", 'image/jpeg'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def assert_url(url)
|
32
|
+
response = get(url)
|
33
|
+
assert_equal '200', response.code
|
34
|
+
end
|
35
|
+
|
36
|
+
def assert_not_url(url)
|
37
|
+
response = get(url)
|
38
|
+
assert_equal '403', response.code
|
39
|
+
end
|
40
|
+
|
41
|
+
def assert_url_content_type(value, url)
|
42
|
+
response = get(url)
|
43
|
+
assert_equal value, response.content_type
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_url_dimensions(value, url)
|
47
|
+
response = get(url)
|
48
|
+
tmp = Tempfile.new
|
49
|
+
tmp.binmode
|
50
|
+
tmp.write response.body
|
51
|
+
tmp.rewind
|
52
|
+
tmp.close
|
53
|
+
dimensions = `gm identify -format %wx%h '#{tmp.path}'`.strip
|
54
|
+
assert_equal value, dimensions
|
55
|
+
end
|
56
|
+
|
57
|
+
def get(url)
|
58
|
+
Net::HTTP.get_response URI.parse(url)
|
59
|
+
end
|
60
|
+
|
61
|
+
def humanize_size(size)
|
62
|
+
ActiveSupport::NumberHelper.number_to_human_size size
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/test/task_test.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TaskTest < ActiveSupport::TestCase
|
4
|
+
include StorageHelper
|
5
|
+
|
6
|
+
setup do
|
7
|
+
Dummy::Application.load_tasks
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'reprocess' do
|
11
|
+
shop = Shop.new(logo: image)
|
12
|
+
assert_raises do
|
13
|
+
shop.logo.reprocess
|
14
|
+
end
|
15
|
+
|
16
|
+
shop.save
|
17
|
+
shop.run_callbacks :commit
|
18
|
+
shop.logo.paths.except(:original).each do |style, path|
|
19
|
+
Attachs.storage.delete path
|
20
|
+
end
|
21
|
+
silence_stream(STDOUT) do
|
22
|
+
Rake::Task['attachs:reprocess'].invoke
|
23
|
+
end
|
24
|
+
shop.reload
|
25
|
+
shop.logo.paths.each do |style, path|
|
26
|
+
assert_url shop.logo.url(style)
|
27
|
+
end
|
28
|
+
shop.logo.destroy
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'fix missings' do
|
32
|
+
shop = Shop.new(logo: image)
|
33
|
+
assert_raises do
|
34
|
+
shop.logo.fix_missings
|
35
|
+
end
|
36
|
+
|
37
|
+
shop.save
|
38
|
+
shop.run_callbacks :commit
|
39
|
+
%i(tiny small).each do |style|
|
40
|
+
Attachs.storage.delete shop.logo.paths[style]
|
41
|
+
end
|
42
|
+
silence_stream(STDOUT) do
|
43
|
+
Rake::Task['attachs:fix_missings'].invoke
|
44
|
+
end
|
45
|
+
shop.logo.paths.each do |style, path|
|
46
|
+
assert_url shop.logo.url(style)
|
47
|
+
end
|
48
|
+
shop.logo.destroy
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'clear' do
|
52
|
+
shop1 = Shop.create(logo: image)
|
53
|
+
shop1.run_callbacks :commit
|
54
|
+
shop2 = Shop.create(logo: image)
|
55
|
+
shop2.run_callbacks :commit
|
56
|
+
shop2.delete
|
57
|
+
silence_stream(STDOUT) do
|
58
|
+
Rake::Task['attachs:clear'].invoke
|
59
|
+
end
|
60
|
+
shop1.logo.styles.each do |style, path|
|
61
|
+
assert_url shop1.logo.url(style)
|
62
|
+
end
|
63
|
+
shop2.logo.styles.each do |style, path|
|
64
|
+
assert_not_url shop2.logo.url(style)
|
65
|
+
end
|
66
|
+
shop1.logo.destroy
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,53 +1,14 @@
|
|
1
1
|
# Configure Rails Environment
|
2
2
|
ENV['RAILS_ENV'] = 'test'
|
3
3
|
|
4
|
-
require File.expand_path('
|
4
|
+
require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
|
5
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path('../../test/dummy/db/migrate', __FILE__)]
|
5
6
|
require 'rails/test_help'
|
7
|
+
require 'mocha/mini_test'
|
6
8
|
|
7
|
-
|
9
|
+
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
10
|
+
# to be shown.
|
11
|
+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
8
12
|
|
9
13
|
# Load support files
|
10
14
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
-
|
12
|
-
# Load fixtures from the engine
|
13
|
-
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
-
ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Load database
|
18
|
-
config = YAML::load(File.read(File.expand_path('../dummy/config/database.yml', __FILE__)))
|
19
|
-
config['test']['adapter'] = 'jdbcsqlite3' if RUBY_PLATFORM == 'java'
|
20
|
-
ActiveRecord::Base.establish_connection(config['test'])
|
21
|
-
load(File.expand_path('../dummy/db/schema.rb', __FILE__))
|
22
|
-
|
23
|
-
# Addons
|
24
|
-
class ActiveSupport::TestCase
|
25
|
-
include ActionView::Helpers::NumberHelper
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def clean_storage
|
30
|
-
FileUtils.rm_rf Rails.root.join('public/storage')
|
31
|
-
end
|
32
|
-
|
33
|
-
def fixture_file_upload(path, content_type)
|
34
|
-
Rack::Test::UploadedFile.new(Rails.root.join("test/fixtures/#{path}"), content_type)
|
35
|
-
end
|
36
|
-
|
37
|
-
def file_upload
|
38
|
-
fixture_file_upload('file.txt', 'text/plain')
|
39
|
-
end
|
40
|
-
|
41
|
-
def image_upload
|
42
|
-
fixture_file_upload('image.gif', 'image/gif')
|
43
|
-
end
|
44
|
-
|
45
|
-
def assert_url(url)
|
46
|
-
assert_equal '200', Net::HTTP.get_response(URI(url)).code
|
47
|
-
end
|
48
|
-
|
49
|
-
def assert_not_url(url)
|
50
|
-
assert_equal '403', Net::HTTP.get_response(URI(url)).code
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
data/test/upload_test.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UploadTest < ActiveSupport::TestCase
|
4
|
+
include StorageHelper
|
5
|
+
|
6
|
+
test 'upload' do
|
7
|
+
upload = Upload.create(file: image, record_type: 'Shop', record_attribute: 'logo')
|
8
|
+
upload.run_callbacks :commit
|
9
|
+
shop = Shop.create(logo: upload)
|
10
|
+
shop.run_callbacks :commit
|
11
|
+
assert_equal 5, shop.logo.paths.size
|
12
|
+
shop.logo.styles.each do |style, geometry|
|
13
|
+
assert_url shop.logo.url(style)
|
14
|
+
end
|
15
|
+
shop.logo.destroy
|
16
|
+
|
17
|
+
shop = Shop.create(logo: upload.id)
|
18
|
+
shop.run_callbacks :commit
|
19
|
+
assert_equal 5, shop.logo.paths.size
|
20
|
+
shop.logo.styles.each do |style, geometry|
|
21
|
+
assert_url shop.logo.url(style)
|
22
|
+
end
|
23
|
+
shop.logo.destroy
|
24
|
+
upload.file.destroy
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ValidatorTest < ActiveSupport::TestCase
|
4
|
+
include StorageHelper
|
5
|
+
|
6
|
+
teardown do
|
7
|
+
Product.clear_validators!
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'methods' do
|
11
|
+
%i(content_type size).each do |validator|
|
12
|
+
method = "validates_attachment_#{validator}_of"
|
13
|
+
assert Product.respond_to?(method)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'content type with' do
|
18
|
+
Product.class_eval do
|
19
|
+
validates :pictures, attachment_content_type: { with: /\Aimage/ }
|
20
|
+
validates :brief, attachment_content_type: { with: /\Atext/ }
|
21
|
+
end
|
22
|
+
|
23
|
+
product = Product.new(pictures: [file, image], brief: image)
|
24
|
+
assert_not product.valid?
|
25
|
+
assert product.errors.added?(:pictures, :invalid)
|
26
|
+
assert product.pictures.first.errors.added?(:content_type, :not_allowed)
|
27
|
+
assert product.pictures.second.valid?
|
28
|
+
assert product.errors.added?(:brief, :invalid)
|
29
|
+
assert product.brief.errors.added?(:content_type, :not_allowed)
|
30
|
+
|
31
|
+
product = Product.new(pictures: [image], brief: file)
|
32
|
+
assert product.valid?
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'content type in' do
|
36
|
+
Product.class_eval do
|
37
|
+
validates :pictures, attachment_content_type: { in: %w(image/jpeg) }
|
38
|
+
validates :brief, attachment_content_type: { in: %w(text/plain) }
|
39
|
+
end
|
40
|
+
|
41
|
+
product = Product.new(pictures: [file, image], brief: image)
|
42
|
+
assert_not product.valid?
|
43
|
+
assert product.errors.added?(:pictures, :invalid)
|
44
|
+
assert product.pictures.first.errors.added?(:content_type, :not_listed, list: 'image/jpeg')
|
45
|
+
assert product.pictures.second.valid?
|
46
|
+
assert product.errors.added?(:brief, :invalid)
|
47
|
+
assert product.brief.errors.added?(:content_type, :not_listed, list: 'text/plain')
|
48
|
+
|
49
|
+
product = Product.new(pictures: [image], brief: file)
|
50
|
+
assert product.valid?
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
test 'content type within' do
|
55
|
+
Product.class_eval do
|
56
|
+
validates :pictures, attachment_content_type: { within: %w(image/jpeg) }
|
57
|
+
validates :brief, attachment_content_type: { within: %w(text/plain) }
|
58
|
+
end
|
59
|
+
|
60
|
+
product = Product.new(pictures: [file, image], brief: image)
|
61
|
+
assert_not product.valid?
|
62
|
+
assert product.errors.added?(:pictures, :invalid)
|
63
|
+
assert product.pictures.first.errors.added?(:content_type, :not_listed, list: 'image/jpeg')
|
64
|
+
assert product.pictures.second.valid?
|
65
|
+
assert product.errors.added?(:brief, :invalid)
|
66
|
+
assert product.brief.errors.added?(:content_type, :not_listed, list: 'text/plain')
|
67
|
+
|
68
|
+
product = Product.new(pictures: [image], brief: file)
|
69
|
+
assert product.valid?
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'size in' do
|
73
|
+
Product.class_eval do
|
74
|
+
validates :pictures, attachment_size: { in: 15.kilobytes..250.kilobytes }
|
75
|
+
validates :brief, attachment_size: { in: 14.bytes..500.bytes }
|
76
|
+
end
|
77
|
+
|
78
|
+
product = Product.new(pictures: [big_image, image], brief: big_file)
|
79
|
+
assert_not product.valid?
|
80
|
+
assert product.errors.added?(:pictures, :invalid)
|
81
|
+
assert product.pictures.first.errors.added?(:size, :less_than_or_equal_to, count: humanize_size(250.kilobytes))
|
82
|
+
assert product.pictures.second.valid?
|
83
|
+
assert product.errors.added?(:brief, :invalid)
|
84
|
+
assert product.brief.errors.added?(:size, :less_than_or_equal_to, count: humanize_size(500.bytes))
|
85
|
+
|
86
|
+
product = Product.new(pictures: [small_image, image], brief: small_file)
|
87
|
+
assert_not product.valid?
|
88
|
+
assert product.errors.added?(:pictures, :invalid)
|
89
|
+
assert product.pictures.first.errors.added?(:size, :greater_than_or_equal_to, count: humanize_size(15.kilobytes))
|
90
|
+
assert product.pictures.second.valid?
|
91
|
+
assert product.errors.added?(:brief, :invalid)
|
92
|
+
assert product.brief.errors.added?(:size, :greater_than_or_equal_to, count: humanize_size(14.bytes))
|
93
|
+
|
94
|
+
product = Product.new(pictures: [image], brief: file)
|
95
|
+
assert product.valid?
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'size within' do
|
99
|
+
Product.class_eval do
|
100
|
+
validates :pictures, attachment_size: { within: 15.kilobytes..250.kilobytes }
|
101
|
+
validates :brief, attachment_size: { within: 14.bytes..500.bytes }
|
102
|
+
end
|
103
|
+
|
104
|
+
product = Product.new(pictures: [big_image, image], brief: big_file)
|
105
|
+
assert_not product.valid?
|
106
|
+
assert product.errors.added?(:pictures, :invalid)
|
107
|
+
assert product.pictures.first.errors.added?(:size, :less_than_or_equal_to, count: humanize_size(250.kilobytes))
|
108
|
+
assert product.pictures.second.valid?
|
109
|
+
assert product.errors.added?(:brief, :invalid)
|
110
|
+
assert product.brief.errors.added?(:size, :less_than_or_equal_to, count: humanize_size(500.bytes))
|
111
|
+
|
112
|
+
product = Product.new(pictures: [small_image, image], brief: small_file)
|
113
|
+
assert_not product.valid?
|
114
|
+
assert product.errors.added?(:pictures, :invalid)
|
115
|
+
assert product.pictures.first.errors.added?(:size, :greater_than_or_equal_to, count: humanize_size(15.kilobytes))
|
116
|
+
assert product.pictures.second.valid?
|
117
|
+
assert product.errors.added?(:brief, :invalid)
|
118
|
+
assert product.brief.errors.added?(:size, :greater_than_or_equal_to, count: humanize_size(14.bytes))
|
119
|
+
|
120
|
+
product = Product.new(pictures: [image], brief: file)
|
121
|
+
assert product.valid?
|
122
|
+
end
|
123
|
+
|
124
|
+
test 'size less than' do
|
125
|
+
Product.class_eval do
|
126
|
+
validates :pictures, attachment_size: { less_than: 250.kilobytes }
|
127
|
+
validates :brief, attachment_size: { less_than: 500.bytes }
|
128
|
+
end
|
129
|
+
|
130
|
+
product = Product.new(pictures: [big_image, image], brief: big_file)
|
131
|
+
assert_not product.valid?
|
132
|
+
assert product.errors.added?(:pictures, :invalid)
|
133
|
+
assert product.pictures.first.errors.added?(:size, :less_than, count: humanize_size(250.kilobytes))
|
134
|
+
assert product.pictures.second.valid?
|
135
|
+
assert product.errors.added?(:brief, :invalid)
|
136
|
+
assert product.brief.errors.added?(:size, :less_than, count: humanize_size(500.bytes))
|
137
|
+
|
138
|
+
product = Product.new(pictures: [image], brief: file)
|
139
|
+
assert product.valid?
|
140
|
+
end
|
141
|
+
|
142
|
+
test 'size greater than' do
|
143
|
+
Product.class_eval do
|
144
|
+
validates :pictures, attachment_size: { greater_than: 15.kilobytes }
|
145
|
+
validates :brief, attachment_size: { greater_than: 14.bytes }
|
146
|
+
end
|
147
|
+
|
148
|
+
product = Product.new(pictures: [small_image, image], brief: small_file)
|
149
|
+
assert_not product.valid?
|
150
|
+
assert product.errors.added?(:pictures, :invalid)
|
151
|
+
assert product.pictures.first.errors.added?(:size, :greater_than, count: humanize_size(15.kilobytes))
|
152
|
+
assert product.pictures.second.valid?
|
153
|
+
assert product.errors.added?(:brief, :invalid)
|
154
|
+
assert product.brief.errors.added?(:size, :greater_than, count: humanize_size(14.bytes))
|
155
|
+
|
156
|
+
product = Product.new(pictures: [image], brief: file)
|
157
|
+
assert product.valid?
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
metadata
CHANGED
@@ -1,66 +1,80 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attachs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 4.0.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mmontossi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.3.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.2.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.3.0
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: aws-sdk
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
16
36
|
requirements:
|
17
37
|
- - "~>"
|
18
38
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
39
|
+
version: '2.0'
|
40
|
+
type: :runtime
|
21
41
|
prerelease: false
|
22
42
|
version_requirements: !ruby/object:Gem::Requirement
|
23
43
|
requirements:
|
24
44
|
- - "~>"
|
25
45
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
46
|
+
version: '2.0'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
48
|
+
name: pg
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
30
50
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 4.0.0
|
34
|
-
- - "<"
|
51
|
+
- - "~>"
|
35
52
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
-
type: :
|
53
|
+
version: '0.18'
|
54
|
+
type: :development
|
38
55
|
prerelease: false
|
39
56
|
version_requirements: !ruby/object:Gem::Requirement
|
40
57
|
requirements:
|
41
|
-
- - "
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 4.0.0
|
44
|
-
- - "<"
|
58
|
+
- - "~>"
|
45
59
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
60
|
+
version: '0.18'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
62
|
+
name: mocha
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
50
64
|
requirements:
|
51
65
|
- - "~>"
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version: '1.
|
67
|
+
version: '1.1'
|
54
68
|
type: :development
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
71
|
requirements:
|
58
72
|
- - "~>"
|
59
73
|
- !ruby/object:Gem::Version
|
60
|
-
version: '1.
|
61
|
-
description:
|
74
|
+
version: '1.1'
|
75
|
+
description: Json based attachments for records in rails.
|
62
76
|
email:
|
63
|
-
- mmontossi@
|
77
|
+
- mmontossi@gmail.com
|
64
78
|
executables: []
|
65
79
|
extensions: []
|
66
80
|
extra_rdoc_files: []
|
@@ -69,77 +83,96 @@ files:
|
|
69
83
|
- README.md
|
70
84
|
- Rakefile
|
71
85
|
- lib/attachs.rb
|
72
|
-
- lib/attachs/active_record/base.rb
|
73
|
-
- lib/attachs/active_record/connection_adapters.rb
|
74
|
-
- lib/attachs/active_record/migration.rb
|
75
|
-
- lib/attachs/active_record/validators.rb
|
76
|
-
- lib/attachs/active_record/validators/attachment_content_type_validator.rb
|
77
|
-
- lib/attachs/active_record/validators/attachment_presence_validator.rb
|
78
|
-
- lib/attachs/active_record/validators/attachment_size_validator.rb
|
79
86
|
- lib/attachs/attachment.rb
|
87
|
+
- lib/attachs/builder.rb
|
88
|
+
- lib/attachs/collection.rb
|
89
|
+
- lib/attachs/concern.rb
|
90
|
+
- lib/attachs/configuration.rb
|
91
|
+
- lib/attachs/console.rb
|
92
|
+
- lib/attachs/extensions/active_record/base.rb
|
93
|
+
- lib/attachs/extensions/active_record/validations/attachment_content_type_validator.rb
|
94
|
+
- lib/attachs/extensions/active_record/validations/attachment_presence_validator.rb
|
95
|
+
- lib/attachs/extensions/active_record/validations/attachment_size_validator.rb
|
96
|
+
- lib/attachs/extensions/active_record/validations/attachment_validator.rb
|
97
|
+
- lib/attachs/interpolations.rb
|
98
|
+
- lib/attachs/jobs/base.rb
|
99
|
+
- lib/attachs/jobs/delete_job.rb
|
100
|
+
- lib/attachs/jobs/update_job.rb
|
80
101
|
- lib/attachs/locales/en.yml
|
81
102
|
- lib/attachs/locales/es.yml
|
82
103
|
- lib/attachs/processors/base.rb
|
83
|
-
- lib/attachs/processors/
|
104
|
+
- lib/attachs/processors/image.rb
|
84
105
|
- lib/attachs/railtie.rb
|
85
106
|
- lib/attachs/storages/base.rb
|
86
|
-
- lib/attachs/storages/local.rb
|
87
107
|
- lib/attachs/storages/s3.rb
|
88
|
-
- lib/attachs/types/base.rb
|
89
|
-
- lib/attachs/types/default.rb
|
90
|
-
- lib/attachs/types/regular.rb
|
91
108
|
- lib/attachs/version.rb
|
92
|
-
- lib/generators/attachs/install_generator.rb
|
93
|
-
- lib/generators/attachs/templates/
|
109
|
+
- lib/generators/attachs/install/install_generator.rb
|
110
|
+
- lib/generators/attachs/install/templates/initializer.rb
|
111
|
+
- lib/generators/attachs/upload/templates/migration.rb
|
112
|
+
- lib/generators/attachs/upload/templates/model.rb
|
113
|
+
- lib/generators/attachs/upload/upload_generator.rb
|
94
114
|
- lib/tasks/attachs.rake
|
95
115
|
- test/attachment_test.rb
|
96
|
-
- test/
|
116
|
+
- test/collection_test.rb
|
117
|
+
- test/concern_test.rb
|
97
118
|
- test/dummy/Rakefile
|
98
119
|
- test/dummy/app/assets/javascripts/application.js
|
99
120
|
- test/dummy/app/assets/stylesheets/application.css
|
100
121
|
- test/dummy/app/controllers/application_controller.rb
|
101
122
|
- test/dummy/app/helpers/application_helper.rb
|
102
|
-
- test/dummy/app/models/
|
103
|
-
- test/dummy/app/models/
|
123
|
+
- test/dummy/app/models/product.rb
|
124
|
+
- test/dummy/app/models/shop.rb
|
125
|
+
- test/dummy/app/models/upload.rb
|
104
126
|
- test/dummy/app/views/layouts/application.html.erb
|
105
127
|
- test/dummy/bin/bundle
|
106
128
|
- test/dummy/bin/rails
|
107
129
|
- test/dummy/bin/rake
|
130
|
+
- test/dummy/bin/setup
|
108
131
|
- test/dummy/config.ru
|
109
132
|
- test/dummy/config/application.rb
|
110
133
|
- test/dummy/config/boot.rb
|
111
134
|
- test/dummy/config/database.yml
|
135
|
+
- test/dummy/config/database.yml.travis
|
112
136
|
- test/dummy/config/environment.rb
|
113
137
|
- test/dummy/config/environments/development.rb
|
114
138
|
- test/dummy/config/environments/production.rb
|
115
139
|
- test/dummy/config/environments/test.rb
|
140
|
+
- test/dummy/config/initializers/assets.rb
|
116
141
|
- test/dummy/config/initializers/attachs.rb
|
117
142
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
143
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
118
144
|
- test/dummy/config/initializers/filter_parameter_logging.rb
|
119
145
|
- test/dummy/config/initializers/inflections.rb
|
120
146
|
- test/dummy/config/initializers/mime_types.rb
|
121
|
-
- test/dummy/config/initializers/secret_token.rb
|
122
147
|
- test/dummy/config/initializers/session_store.rb
|
123
148
|
- test/dummy/config/initializers/wrap_parameters.rb
|
124
149
|
- test/dummy/config/locales/en.yml
|
125
150
|
- test/dummy/config/routes.rb
|
126
|
-
- test/dummy/config/
|
127
|
-
- test/dummy/db/migrate/
|
151
|
+
- test/dummy/config/secrets.yml
|
152
|
+
- test/dummy/db/migrate/20161024234003_create_shops.rb
|
153
|
+
- test/dummy/db/migrate/20161024234029_create_products.rb
|
154
|
+
- test/dummy/db/migrate/20161031135453_create_uploads.rb
|
128
155
|
- test/dummy/db/schema.rb
|
156
|
+
- test/dummy/log/development.log
|
157
|
+
- test/dummy/log/test.log
|
129
158
|
- test/dummy/public/404.html
|
130
159
|
- test/dummy/public/422.html
|
131
160
|
- test/dummy/public/500.html
|
132
161
|
- test/dummy/public/favicon.ico
|
133
|
-
- test/
|
134
|
-
- test/
|
162
|
+
- test/fixtures/big_file.txt
|
163
|
+
- test/fixtures/big_image.jpg
|
164
|
+
- test/fixtures/file.txt
|
165
|
+
- test/fixtures/image.jpg
|
166
|
+
- test/fixtures/small_file.txt
|
167
|
+
- test/fixtures/small_image.jpg
|
135
168
|
- test/generator_test.rb
|
136
|
-
- test/
|
137
|
-
- test/
|
138
|
-
- test/
|
139
|
-
- test/
|
140
|
-
- test/tasks_test.rb
|
169
|
+
- test/helper_test.rb
|
170
|
+
- test/query_test.rb
|
171
|
+
- test/support/storage_helper.rb
|
172
|
+
- test/task_test.rb
|
141
173
|
- test/test_helper.rb
|
142
|
-
- test/
|
174
|
+
- test/upload_test.rb
|
175
|
+
- test/validator_test.rb
|
143
176
|
homepage: https://github.com/mmontossi/attachs
|
144
177
|
licenses:
|
145
178
|
- MIT
|
@@ -152,65 +185,78 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
185
|
requirements:
|
153
186
|
- - ">="
|
154
187
|
- !ruby/object:Gem::Version
|
155
|
-
version:
|
188
|
+
version: 2.0.0
|
156
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
190
|
requirements:
|
158
191
|
- - ">="
|
159
192
|
- !ruby/object:Gem::Version
|
160
193
|
version: '0'
|
161
194
|
requirements:
|
162
|
-
-
|
195
|
+
- GraphicsMagick
|
163
196
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
197
|
+
rubygems_version: 2.5.1
|
165
198
|
signing_key:
|
166
199
|
specification_version: 4
|
167
|
-
summary:
|
200
|
+
summary: File attachments for rails.
|
168
201
|
test_files:
|
169
202
|
- test/attachment_test.rb
|
203
|
+
- test/collection_test.rb
|
204
|
+
- test/concern_test.rb
|
170
205
|
- test/dummy/app/assets/javascripts/application.js
|
171
206
|
- test/dummy/app/assets/stylesheets/application.css
|
172
207
|
- test/dummy/app/controllers/application_controller.rb
|
173
208
|
- test/dummy/app/helpers/application_helper.rb
|
174
|
-
- test/dummy/app/models/
|
175
|
-
- test/dummy/app/models/
|
209
|
+
- test/dummy/app/models/product.rb
|
210
|
+
- test/dummy/app/models/shop.rb
|
211
|
+
- test/dummy/app/models/upload.rb
|
176
212
|
- test/dummy/app/views/layouts/application.html.erb
|
177
213
|
- test/dummy/bin/bundle
|
178
214
|
- test/dummy/bin/rails
|
179
215
|
- test/dummy/bin/rake
|
216
|
+
- test/dummy/bin/setup
|
180
217
|
- test/dummy/config/application.rb
|
181
218
|
- test/dummy/config/boot.rb
|
182
219
|
- test/dummy/config/database.yml
|
220
|
+
- test/dummy/config/database.yml.travis
|
183
221
|
- test/dummy/config/environment.rb
|
184
222
|
- test/dummy/config/environments/development.rb
|
185
223
|
- test/dummy/config/environments/production.rb
|
186
224
|
- test/dummy/config/environments/test.rb
|
225
|
+
- test/dummy/config/initializers/assets.rb
|
187
226
|
- test/dummy/config/initializers/attachs.rb
|
188
227
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
228
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
189
229
|
- test/dummy/config/initializers/filter_parameter_logging.rb
|
190
230
|
- test/dummy/config/initializers/inflections.rb
|
191
231
|
- test/dummy/config/initializers/mime_types.rb
|
192
|
-
- test/dummy/config/initializers/secret_token.rb
|
193
232
|
- test/dummy/config/initializers/session_store.rb
|
194
233
|
- test/dummy/config/initializers/wrap_parameters.rb
|
195
234
|
- test/dummy/config/locales/en.yml
|
196
235
|
- test/dummy/config/routes.rb
|
197
|
-
- test/dummy/config/
|
236
|
+
- test/dummy/config/secrets.yml
|
198
237
|
- test/dummy/config.ru
|
199
|
-
- test/dummy/db/migrate/
|
238
|
+
- test/dummy/db/migrate/20161024234003_create_shops.rb
|
239
|
+
- test/dummy/db/migrate/20161024234029_create_products.rb
|
240
|
+
- test/dummy/db/migrate/20161031135453_create_uploads.rb
|
200
241
|
- test/dummy/db/schema.rb
|
242
|
+
- test/dummy/log/development.log
|
243
|
+
- test/dummy/log/test.log
|
201
244
|
- test/dummy/public/404.html
|
202
245
|
- test/dummy/public/422.html
|
203
246
|
- test/dummy/public/500.html
|
204
247
|
- test/dummy/public/favicon.ico
|
205
248
|
- test/dummy/Rakefile
|
206
|
-
- test/
|
207
|
-
- test/
|
208
|
-
- test/
|
249
|
+
- test/fixtures/big_file.txt
|
250
|
+
- test/fixtures/big_image.jpg
|
251
|
+
- test/fixtures/file.txt
|
252
|
+
- test/fixtures/image.jpg
|
253
|
+
- test/fixtures/small_file.txt
|
254
|
+
- test/fixtures/small_image.jpg
|
209
255
|
- test/generator_test.rb
|
210
|
-
- test/
|
211
|
-
- test/
|
212
|
-
- test/
|
213
|
-
- test/
|
214
|
-
- test/tasks_test.rb
|
256
|
+
- test/helper_test.rb
|
257
|
+
- test/query_test.rb
|
258
|
+
- test/support/storage_helper.rb
|
259
|
+
- test/task_test.rb
|
215
260
|
- test/test_helper.rb
|
216
|
-
- test/
|
261
|
+
- test/upload_test.rb
|
262
|
+
- test/validator_test.rb
|