attachs 0.4.5 → 4.0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,29 +0,0 @@
|
|
1
|
-
module Attachs
|
2
|
-
module Types
|
3
|
-
class Default < Base
|
4
|
-
|
5
|
-
%w(
|
6
|
-
basename
|
7
|
-
extension
|
8
|
-
process
|
9
|
-
process_styles
|
10
|
-
destroy
|
11
|
-
destroy_styles
|
12
|
-
update
|
13
|
-
).each do |name|
|
14
|
-
define_method(name) {}
|
15
|
-
end
|
16
|
-
|
17
|
-
def image?
|
18
|
-
false
|
19
|
-
end
|
20
|
-
|
21
|
-
def url(*args)
|
22
|
-
if attachment.default?
|
23
|
-
storage.url *args
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Attachs
|
2
|
-
module Types
|
3
|
-
class Regular < Base
|
4
|
-
|
5
|
-
delegate :url, :process, :process_styles, :destroy, :destroy_styles, :update, to: :storage
|
6
|
-
|
7
|
-
def basename
|
8
|
-
@basename ||= File.basename(attachment.filename, ".#{extension}")
|
9
|
-
end
|
10
|
-
|
11
|
-
def extension
|
12
|
-
@extension ||= File.extname(attachment.filename).from(1)
|
13
|
-
end
|
14
|
-
|
15
|
-
def image?
|
16
|
-
@image ||= attachment.content_type.start_with?('image')
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
|
3
|
-
module Attachs
|
4
|
-
class InstallGenerator < Rails::Generators::Base
|
5
|
-
|
6
|
-
source_root File.expand_path('../templates', __FILE__)
|
7
|
-
|
8
|
-
def create_initializer
|
9
|
-
copy_file 'attachs.rb', 'config/initializers/attachs.rb'
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
data/test/dummy/README.rdoc
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
== README
|
2
|
-
|
3
|
-
This README would normally document whatever steps are necessary to get the
|
4
|
-
application up and running.
|
5
|
-
|
6
|
-
Things you may want to cover:
|
7
|
-
|
8
|
-
* Ruby version
|
9
|
-
|
10
|
-
* System dependencies
|
11
|
-
|
12
|
-
* Configuration
|
13
|
-
|
14
|
-
* Database creation
|
15
|
-
|
16
|
-
* Database initialization
|
17
|
-
|
18
|
-
* How to run the test suite
|
19
|
-
|
20
|
-
* Services (job queues, cache servers, search engines, etc.)
|
21
|
-
|
22
|
-
* Deployment instructions
|
23
|
-
|
24
|
-
* ...
|
25
|
-
|
26
|
-
|
27
|
-
Please feel free to use a different markup language if you do not plan to run
|
28
|
-
<tt>rake doc:app</tt>.
|
@@ -1,5 +0,0 @@
|
|
1
|
-
class Medium < ActiveRecord::Base
|
2
|
-
has_attached_file :attach, path: '/storage/:style/:filename'
|
3
|
-
has_attached_file :local_attach, storage: 'local', path: '/storage/:type/:size/:style/:month/:basename.:extension', styles: [:small]
|
4
|
-
has_attached_file :s3_attach, storage: 's3', path: '/storage/:type/:size/:style/:month/:basename.:extension', styles: [:small]
|
5
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
-
# If you change this key, all old signed cookies will become invalid!
|
5
|
-
|
6
|
-
# Make sure the secret is at least 30 characters and all random,
|
7
|
-
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
-
# You can use `rake secret` to generate a secure secret key.
|
9
|
-
|
10
|
-
# Make sure your secret_key_base is kept private
|
11
|
-
# if you're sharing your code publicly.
|
12
|
-
Dummy::Application.config.secret_token = '325198aee80c035ddba090e3307afe68ef17c12a25b60f987d673febf4164119cb1ce3772aa21fb6b16ede3b9362c0030f7d934f31f1f01f96dd61f289bc6f8c'
|
13
|
-
Dummy::Application.config.secret_key_base = '325198aee80c035ddba090e3307afe68ef17c12a25b60f987d673febf4164119cb1ce3772aa21fb6b16ede3b9362c0030f7d934f31f1f01f96dd61f289bc6f8c'
|
data/test/dummy/config/s3.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
|
2
|
-
development:
|
3
|
-
bucket: development-bucket
|
4
|
-
access_key_id: development_access_key_id
|
5
|
-
secret_access_key: development_secret_access_key
|
6
|
-
|
7
|
-
test:
|
8
|
-
bucket: test-bucket
|
9
|
-
access_key_id: test_access_key_id
|
10
|
-
secret_access_key: test_secret_access_key
|
11
|
-
|
12
|
-
production:
|
13
|
-
bucket: production-bucket
|
14
|
-
access_key_id: production_access_key_id
|
15
|
-
secret_access_key: production_secret_access_key
|
Binary file
|
data/test/local_storage_test.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LocalStorageTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
teardown do
|
6
|
-
clean_storage
|
7
|
-
end
|
8
|
-
|
9
|
-
test 'file url' do
|
10
|
-
medium = Medium.create(local_attach: file_upload)
|
11
|
-
assert_equal file_url(:original, medium, true), medium.local_attach.url
|
12
|
-
assert_equal file_url(:original, medium, false), medium.local_attach.url(cachebuster: false)
|
13
|
-
end
|
14
|
-
|
15
|
-
test 'image url' do
|
16
|
-
medium = Medium.create(local_attach: image_upload)
|
17
|
-
assert_equal image_url(:original, medium, true), medium.local_attach.url
|
18
|
-
assert_equal image_url(:original, medium, false), medium.local_attach.url(cachebuster: false)
|
19
|
-
assert_equal image_url(:small, medium, true), medium.local_attach.url(:small)
|
20
|
-
assert_equal image_url(:small, medium, false), medium.local_attach.url(:small, cachebuster: false)
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'crud' do
|
24
|
-
medium = Medium.create(local_attach: file_upload)
|
25
|
-
assert File.exist?(file_path(:original))
|
26
|
-
medium.update_attributes! local_attach: image_upload
|
27
|
-
assert !File.exist?(file_path(:original))
|
28
|
-
assert File.exist?(image_path(:original))
|
29
|
-
assert File.exist?(image_path(:small))
|
30
|
-
medium.destroy
|
31
|
-
assert !File.exist?(image_path(:original))
|
32
|
-
assert !File.exist?(image_path(:small))
|
33
|
-
end
|
34
|
-
|
35
|
-
test 'detroy attr' do
|
36
|
-
medium = Medium.create(local_attach: file_upload, destroy_attach: true)
|
37
|
-
assert File.exist?(file_path(:original))
|
38
|
-
medium.update_attributes! destroy_local_attach: true
|
39
|
-
assert !File.exist?(file_path(:original))
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def month
|
45
|
-
Time.zone.now.month
|
46
|
-
end
|
47
|
-
|
48
|
-
def file_url(style, record, cachebuster=true)
|
49
|
-
"/storage/text/11/#{style}/#{month}/file.txt".tap do |url|
|
50
|
-
if cachebuster
|
51
|
-
url << "?#{record.local_attach_updated_at.to_i}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def image_url(style, record, cachebuster=true)
|
57
|
-
"/storage/image/5461/#{style}/#{month}/image.gif".tap do |url|
|
58
|
-
if cachebuster
|
59
|
-
url << "?#{record.local_attach_updated_at.to_i}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def file_path(style)
|
65
|
-
Rails.root.join("public/storage/text/11/#{style}/#{month}/file.txt")
|
66
|
-
end
|
67
|
-
|
68
|
-
def image_path(style)
|
69
|
-
Rails.root.join("public/storage/image/5461/#{style}/#{month}/image.gif")
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
data/test/migration_test.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MigrationTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
ActiveRecord::Migration.verbose = false
|
7
|
-
end
|
8
|
-
|
9
|
-
test 'table migration' do
|
10
|
-
table_migration.migrate(:up)
|
11
|
-
assert_includes columns, ['image_filename', :string]
|
12
|
-
assert_includes columns, ['image_size', :integer]
|
13
|
-
assert_includes columns, ['image_content_type', :string]
|
14
|
-
assert_includes columns, ['image_updated_at', :datetime]
|
15
|
-
|
16
|
-
assert_nothing_raised do
|
17
|
-
table_migration.migrate(:down)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
test 'column migration' do
|
22
|
-
ActiveRecord::Base.connection.create_table :pictures
|
23
|
-
|
24
|
-
column_migration.migrate(:up)
|
25
|
-
assert_includes columns, ['image_filename', :string]
|
26
|
-
assert_includes columns, ['image_size', :integer]
|
27
|
-
assert_includes columns, ['image_content_type', :string]
|
28
|
-
assert_includes columns, ['image_updated_at', :datetime]
|
29
|
-
|
30
|
-
column_migration.migrate(:down)
|
31
|
-
refute_includes columns, ['image_filename', :string]
|
32
|
-
refute_includes columns, ['image_size', :integer]
|
33
|
-
refute_includes columns, ['image_content_type', :string]
|
34
|
-
refute_includes columns, ['image_updated_at', :datetime]
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def columns
|
40
|
-
Picture.reset_column_information
|
41
|
-
Picture.columns.map { |column| [column.name, column.type] }
|
42
|
-
end
|
43
|
-
|
44
|
-
def table_migration
|
45
|
-
Class.new(ActiveRecord::Migration) do
|
46
|
-
def change
|
47
|
-
create_table :pictures do |t|
|
48
|
-
t.attachment :image
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def column_migration
|
55
|
-
Class.new(ActiveRecord::Migration) do
|
56
|
-
def up
|
57
|
-
add_attachment :pictures, :image
|
58
|
-
end
|
59
|
-
def down
|
60
|
-
remove_attachment :pictures, :image
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
data/test/processor_test.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ProcessorTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
FileUtils.mkdir_p resized_path.dirname
|
7
|
-
FileUtils.cp source_path, resized_path
|
8
|
-
end
|
9
|
-
|
10
|
-
teardown do
|
11
|
-
clean_storage
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'force resize' do
|
15
|
-
Attachs::Processors::Thumbnail.new(nil, source_path).process(:big_force, resized_path)
|
16
|
-
assert_equal [160,130], dimensions(resized_path)
|
17
|
-
Attachs::Processors::Thumbnail.new(nil, source_path).process(:small_force, resized_path)
|
18
|
-
assert_equal [140,110], dimensions(resized_path)
|
19
|
-
end
|
20
|
-
|
21
|
-
test 'cover resize' do
|
22
|
-
Attachs::Processors::Thumbnail.new(nil, source_path).process(:big_cover, resized_path)
|
23
|
-
assert_equal [160,130], dimensions(resized_path)
|
24
|
-
Attachs::Processors::Thumbnail.new(nil, source_path).process(:small_cover, resized_path)
|
25
|
-
assert_equal [140,110], dimensions(resized_path)
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'contain resize' do
|
29
|
-
Attachs::Processors::Thumbnail.new(nil, source_path).process(:big_contain, resized_path)
|
30
|
-
assert_equal [156,130], dimensions(resized_path)
|
31
|
-
Attachs::Processors::Thumbnail.new(nil, source_path).process(:small_contain, resized_path)
|
32
|
-
assert_equal [132,110], dimensions(resized_path)
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def source_path
|
38
|
-
image_upload.path
|
39
|
-
end
|
40
|
-
|
41
|
-
def resized_path
|
42
|
-
Rails.root.join('public/storage/processor/resized.gif')
|
43
|
-
end
|
44
|
-
|
45
|
-
def dimensions(source)
|
46
|
-
`identify -format %wx%h '#{source}'`.split('x').map(&:to_i)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
data/test/s3_storage_tes.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class S3StorageTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
test 'file url' do
|
6
|
-
medium = Medium.create(s3_attach: file_upload)
|
7
|
-
assert_equal file_url(:original, medium, true, false), medium.s3_attach.url
|
8
|
-
assert_equal file_url(:original, medium, false, false), medium.s3_attach.url(cachebuster: false)
|
9
|
-
assert_equal file_url(:original, medium, true, true), medium.s3_attach.url(ssl: true)
|
10
|
-
assert_equal file_url(:original, medium, false, true), medium.s3_attach.url(ssl: true, cachebuster: false)
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'image url' do
|
14
|
-
medium = Medium.create(s3_attach: image_upload)
|
15
|
-
assert_equal image_url(:original, medium, true, false), medium.s3_attach.url
|
16
|
-
assert_equal image_url(:original, medium, false, false), medium.s3_attach.url(cachebuster: false)
|
17
|
-
assert_equal image_url(:original, medium, true, true), medium.s3_attach.url(ssl: true)
|
18
|
-
assert_equal image_url(:original, medium, false, true), medium.s3_attach.url(ssl: true, cachebuster: false)
|
19
|
-
assert_equal image_url(:small, medium, true, false), medium.s3_attach.url(:small)
|
20
|
-
assert_equal image_url(:small, medium, false, false), medium.s3_attach.url(:small, cachebuster: false)
|
21
|
-
assert_equal image_url(:small, medium, true, true), medium.s3_attach.url(:small, ssl: true)
|
22
|
-
assert_equal image_url(:small, medium, false, true), medium.s3_attach.url(:small, ssl: true, cachebuster: false)
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'storage' do
|
26
|
-
medium = Medium.create(s3_attach: file_upload)
|
27
|
-
assert_url file_url(:original, medium)
|
28
|
-
medium.update_attributes! s3_attach: image_upload
|
29
|
-
assert_not_url file_url(:original, medium)
|
30
|
-
assert_url image_url(:original, medium)
|
31
|
-
assert_url image_url(:small, medium)
|
32
|
-
medium.destroy
|
33
|
-
assert_not_url image_url(:original, medium)
|
34
|
-
assert_not_url image_url(:small, medium)
|
35
|
-
end
|
36
|
-
|
37
|
-
test 'detroy attr' do
|
38
|
-
medium = Medium.create(s3_attach: file_upload, destroy_s3_attach: true)
|
39
|
-
assert_url file_url(:original, medium)
|
40
|
-
medium.update_attributes! destroy_s3_attach: true
|
41
|
-
assert_not_url file_url(:original, medium)
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def month
|
47
|
-
Time.zone.now.month
|
48
|
-
end
|
49
|
-
|
50
|
-
def file_url(style, record, cachebuster=true, ssl=false)
|
51
|
-
"http#{'s' if ssl}://s3.amazonaws.com/attachs.test/storage/text/11/#{style}/#{month}/file.txt".tap do |url|
|
52
|
-
if cachebuster
|
53
|
-
url << "?#{record.s3_attach_updated_at.to_i}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def image_url(style, record, cachebuster=true, ssl=false)
|
59
|
-
"http#{'s' if ssl}://s3.amazonaws.com/attachs.test/storage/image/5461/#{style}/#{month}/image.gif".tap do |url|
|
60
|
-
if cachebuster
|
61
|
-
url << "?#{record.s3_attach_updated_at.to_i}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
data/test/tasks_test.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
class TasksTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
setup do
|
7
|
-
Dummy::Application.load_tasks
|
8
|
-
end
|
9
|
-
|
10
|
-
teardown do
|
11
|
-
clean_storage
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'refresh all styles' do
|
15
|
-
Medium.create(attach: image_upload)
|
16
|
-
original_small_time = small_time
|
17
|
-
original_big_time = big_time
|
18
|
-
ENV['CLASS'] = 'medium'
|
19
|
-
ENV['ATTACHMENT'] = 'attach'
|
20
|
-
sleep 1
|
21
|
-
Rake::Task['attachs:refresh:all'].invoke
|
22
|
-
assert File.file?(image_path(:small))
|
23
|
-
assert File.file?(image_path(:big))
|
24
|
-
assert_not_equal original_small_time, small_time
|
25
|
-
assert_not_equal original_big_time, big_time
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'refersh missing styles' do
|
29
|
-
Medium.create(attach: image_upload)
|
30
|
-
original_big_time = big_time
|
31
|
-
original_small_time = small_time
|
32
|
-
File.delete image_path(:small)
|
33
|
-
ENV['CLASS'] = 'medium'
|
34
|
-
ENV['ATTACHMENT'] = 'attach'
|
35
|
-
sleep 1
|
36
|
-
Rake::Task['attachs:refresh:missing'].invoke
|
37
|
-
assert File.file?(image_path(:small))
|
38
|
-
assert File.file?(image_path(:big))
|
39
|
-
assert_not_equal original_small_time, small_time
|
40
|
-
assert_equal original_big_time, big_time
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def image_path(style)
|
46
|
-
Rails.root.join("public/storage/#{style}/image.gif")
|
47
|
-
end
|
48
|
-
|
49
|
-
def small_time
|
50
|
-
File.mtime(image_path(:small))
|
51
|
-
end
|
52
|
-
|
53
|
-
def big_time
|
54
|
-
File.mtime(image_path(:big))
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|