Commit Graph

699 Commits

Author SHA1 Message Date
George Claghorn
22c2d6011f Shush deprecation warnings in ASt tests 2019-09-24 07:41:22 -04:00
Julik Tarkhanov
3c35de7933 Always create ActiveStorage::Blob before uploading to service 2019-09-24 07:32:59 -04:00
Ryuta Kamizono
db6884a772 Fix typo /a HTTP/an HTTP/ [ci skip]
Follow up #37281.
2019-09-24 08:43:31 +09:00
Connor Shea
2bd56a1e7c Note ActiveStorage::Blob methods in Attachment docs [ci skip] 2019-09-20 21:43:29 -04:00
Takayuki Nakata
b08d428ba0 Fix typo in activestorage README [ci skip]
`a ActionDispatch::Http::UploadedFile object` ->
`an ActionDispatch::Http::UploadedFile object`
2019-09-18 09:19:22 +09:00
Akira Matsuda
855de1a700 Fix mocking test to mock kwargs 2019-09-07 02:44:36 +09:00
Akira Matsuda
dea19d4ead Passing in a Hash instance as kwargs parameters requires the "double splat" prefix 2019-09-07 02:44:36 +09:00
Akira Matsuda
d9933a7f9f Keyword arguments is not a Hash 2019-09-06 18:52:00 +09:00
Gannon McGibbon
78ced171ac
Merge pull request #36793 from peterzhu2118/content-disposition-direct-upload
Set content disposition in direct upload
2019-09-05 17:37:57 -04:00
Peter Zhu
9940c65a78 Implement content disposition in direct upload 2019-09-05 16:40:13 -04:00
Connor Shea
6b182ff13b
Fix grammar for attached? method doc
Attachments is plural, so it should be have.
2019-08-30 20:36:12 -06:00
Carlos Antonio da Silva
1f325fab01
Merge pull request #37053 from yahonda/ignore_sqlite3_parallel_testing_databases
Ignore SQLite3 database files generated by parallel testing
2019-08-27 09:15:58 -03:00
Yasuo Honda
c5e3c537a4 Ignore SQLite3 database files generated by parallel testing
Rails 6.0 introduces parallel testing and the default degree of parallelism is configured based on the number of CPU.
refer https://github.com/rails/rails/pull/34735 https://github.com/rails/rails/pull/31900

When any minitest executed under the OS where 2 or more CPU available,
SQLite 3 database files are not git-ignored.

Also updated other files which ignores SQLite database files.

* Steps to reproduce

```
$ git clone https://github.com/yahonda/rep_ignore_sqlite3_databases.git
$ cd rep_ignore_sqlite3_databases/
$ bin/rails test
$ git status
```

* Expected behavior:

- No `Untracked files:`

* Actual behavior:

- SQLite 3 database files appeared

```
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

	db/test.sqlite3-0
	db/test.sqlite3-1
	db/test.sqlite3-2
	db/test.sqlite3-3
	db/test.sqlite3-4
	db/test.sqlite3-5

nothing added to commit but untracked files present (use "git add" to track)
$
```
2019-08-27 11:42:04 +00:00
Dino Maric
df462d5880 Small docs fix inside ActiveStorage [ci skip]
`ActiveRecord::Base` -> `ApplicationRecord` for consistency with default
Rails generators and ActiveStorage guides.
2019-08-23 14:08:47 +02:00
Santiago Bartesaghi
a903c83902 Fix conditions 2019-08-22 16:19:36 -03:00
ohbarye
adccbecf9d Refactor max-age seconds
Same as https://github.com/rails/rails/pull/30244

`#to_i` always returns the number of seconds that this Duration represents.
2019-08-18 21:29:52 +09:00
George Claghorn
836eb915b1 Fix attaching many uploaded files one at a time
Closes #36806.
2019-08-15 16:36:34 -04:00
bogdanvlviv
f2819f7876
Remove AddForeignKeyConstraintToActiveStorageAttachmentsForBlobId migration
In https://github.com/rails/rails/pull/33419, we added this migration to
properly upgrade Active Storage from 5.2 to 6.0

On Rails 6.1 `rails app:update` shouldn't add this migration to users' app.

Note that, I've left implementation that makes `rails app:update` to generate
migrations for users' app that are in `activestorage/db/update_migrate/`
because we are likely to need it e.g.: https://github.com/rails/rails/pull/34935, https://github.com/rails/rails/pull/36835.
2019-08-12 15:37:51 +03:00
Peter Zhu
d0ed8305ae Add test for content type in direct upload to Azure 2019-08-09 14:54:09 -04:00
Gannon McGibbon
7fd006de0b Pass optional record in blob finder methods
Allow record to be optionally passed to blob finders to make sharding
easier.
2019-08-07 14:38:05 -04:00
Peter Zhu
ebedf0a6c0 Update azure-storage gem to latest version 2019-08-06 16:02:42 -04:00
Rafael Mendonça França
967beb7229
Revert "MethodCallAssertions is a regular player of the team ActiveSupport::TestCase now"
This reverts commit 98d0f7ebd34b858f12a12dcf37ae54fdbb5cab64.
2019-08-02 00:24:21 -04:00
Akira Matsuda
98d0f7ebd3 MethodCallAssertions is a regular player of the team ActiveSupport::TestCase now
It's used everywhere, clean and mature enough
2019-08-02 05:36:15 +09:00
Akira Matsuda
530f7805ed It may be better to explicitly require 'object/try' where we call try
In most cases it works now without explicit require because it's accidentally required through
active_support/core_ext/date_and_time/calculations.rb where we still call `try`,
but that would stop working if we changed the Calculations implementation and remove the require call there.
2019-08-01 18:51:51 +09:00
Gannon McGibbon
388e011b08
Merge pull request #36792 from peterzhu2118/azure-content-disposition
Upload filename and disposition for Azure
2019-07-31 18:44:58 -04:00
Peter Zhu
24ae11daae Upload file with filename and disposition for Azure 2019-07-31 15:44:40 -04:00
Gannon McGibbon
4b65173479
Merge pull request #36791 from peterzhu2118/s3-upload-disposition
Upload with filename and disposition for S3
2019-07-31 12:55:00 -04:00
Peter Zhu
e6d2e8bf9b Upload file with filename and disposition for S3 2019-07-31 09:54:51 -04:00
Akira Matsuda
0d981a2b3d Let the generated initializers/backtrace_silencers.rb code use Regexp#match? 2019-07-29 14:21:30 +09:00
Ershad Kunnakkadan
5fa6841028
Use a smaller TIFF file as fixture 2019-07-27 23:08:49 +05:30
Eileen M. Uchitelle
dc7b650e15
Merge pull request #36715 from peterzhu2118/azure-content-type
Add content_type to upload method for Azure
2019-07-24 15:13:23 -04:00
Peter Zhu
094fa9277d Add content_type to upload in Azure 2019-07-24 14:56:20 -04:00
Rafael França
fc175375e1
Merge pull request #36642 from wagenet/fix-disk-service-host
Fix host for ActiveStorage DiskService
2019-07-23 10:37:47 -04:00
Gannon McGibbon
3cf65bcb8e Make Active Storage routes optional
Add configuration option to turn off drawing of Active Storage routes.
2019-07-22 12:35:04 -04:00
George Claghorn
400b210354
Preserve existing attachment assignment behavior for upgraded apps
Assigning to a collection of attachments appends rather than replacing, as in 5.2. Existing 5.2 apps that rely on this behavior will no longer break when they're upgraded to 6.0.

For apps generated on 6.0 or newer, assigning replaces the existing attachments in the collection. #attach should be used to add new attachments to the collection without removing existing ones.

I expect that we'll deprecate the old behavior in 6.1.

Closes #36374.
2019-07-20 06:33:11 -04:00
Ryuta Kamizono
559ffacfd9 Revert "Merge pull request #36676 from wjessop/change_activestorage_metadata_duration_to_bound"
This reverts commit a307c697b28e3c8b2860d2274c23e4d95dc164ae, reversing
changes made to f30f76af747858826d3618866676cd5a4979e64a.

Reason: This assertion is not failed even without this PR since both
ffprobe versions (3.2.14 and 4.1.3) return the same duration 5.166648
for `video.mp4`.
So there is no need to touch this assertion at this point.
2019-07-17 09:59:03 +09:00
Will Jessop
564fd87b99
Different versions of ffprobe can return subtly different video lengths
Specify a range so we can take this into account, but not get caught out by 0, nil or way too large values.
2019-07-14 14:09:01 +01:00
Ryuta Kamizono
88cbe13741 Fix activestorage CI failure due to ffprove version differece
Our CI environment is upgraded from stretch to buster then ffprove
version is also upgraded from 3.2.14 to 4.1.3.

https://packages.debian.org/stretch/ffmpeg
https://packages.debian.org/buster/ffmpeg

Somehow those ffprove returns different metadata for
`rotated_video.mp4`.

```
$ ffprobe -print_format json -show_streams -v error rotated_video.mp4 > ffprobe41.json
$ diff -ub ffprobe32.json ffprobe41.json
--- ffprobe32.json      2019-07-14 20:02:13.000000000 +0900
+++ ffprobe41.json      2019-07-14 19:59:08.000000000 +0900
@@ -27,8 +27,8 @@
             "time_base": "1/17594",
             "start_pts": 3976,
             "start_time": "0.225986",
-            "duration_ts": 91981,
-            "duration": "5.227975",
+            "duration_ts": 88000,
+            "duration": "5.001705",
             "bit_rate": "321546",
             "bits_per_raw_sample": "8",
             "nb_frames": "44",
@@ -78,8 +78,8 @@
             "time_base": "1/44100",
             "start_pts": 0,
             "start_time": "0.000000",
-            "duration_ts": 227865,
-            "duration": "5.167007",
+            "duration_ts": 227850,
+            "duration": "5.166667",
             "bit_rate": "109732",
             "max_bit_rate": "109732",
             "nb_frames": "223",
```

In the case on the `test "analyzing a rotated video"`, most important
part is `assert_equal 90, metadata[:angle]`, the accidental difference
of duration for ffprove version is out of scope for the test.
2019-07-14 20:06:41 +09:00
Peter Wagenet
b07ce56a38 Fix host for ActiveStorage DiskService
Previous behavior would only set host, which didn't work correctly
if the default_url_options contained the protocol or the port.
2019-07-09 12:54:35 -07:00
Ryuta Kamizono
cc27e9988f Unify to use 4 spaces indentation in CHANGELOGs [ci skip]
Especially, somehow `CHANGELOG.md` in actiontext and activestorage in
master branch had used 3 spaces indentation.
2019-06-05 05:53:49 +09:00
George Claghorn
5ce1f66d7a Add a changelog entry for 165785e 2019-05-30 22:33:29 -04:00
George Claghorn
165785e8cf Skip image analysis on ImageMagick error 2019-05-30 18:20:55 -04:00
Matt Tanous
f002be148e Add :allow_nil option to delegate_missing_to; use in ActiveStorage
attachment
2019-05-23 12:11:39 -04:00
George Claghorn
d5a2f7ec14
Mirror direct uploads 2019-05-22 15:07:35 -04:00
George Claghorn
9c5135ce6a
S3: permit uploading files larger than 5 GB
Use multipart uploads for files larger than 100 MB. Dynamically calculate part size based on total object size and maximum part count.
2019-05-16 10:58:33 -04:00
George Claghorn
3d70e96097 Remove outdated cross-origin redirection tests 2019-05-15 15:57:45 -04:00
George Claghorn
5f50f4d63b Inline anemic methods 2019-05-15 15:53:43 -04:00
George Claghorn
61b2f3d336 Halve string allocations in S3 streaming and partial downloads
See 19770d6.
2019-04-26 08:14:06 -04:00
Rafael Mendonça França
9834be6565
Start Rails 6.1 development 2019-04-24 15:57:14 -04:00
Ryuta Kamizono
3a4aa49256 Fix markup in CHANGELOGs [ci skip]
Need to new line to break line in the markdown.
2019-04-25 03:19:15 +09:00
Sharang Dashputre
71ca83786e Update changelog for a bug-fix to read better [ci skip] 2019-04-24 18:17:39 +05:30
Guilherme Mansur
6133dad869 Don't fail ImageAnalyzer on unsupported types
Fix: #36065

The IamgeAnalyzer passes a image to ImageMagick without checking if the
image is supported by ImageMagick. This patch checks that image is
supported and if not logs an error and returns an empty hash instead of
raising an error. This is the same error handling we do when we
encounter a LoadError when mini_magick is not installed.
2019-04-24 07:59:12 -04:00
George Claghorn
a89e9cccb2
Merge pull request #36045 from yfxie/fix-normalize-the-hash-of-transformations
ActiveStorage - normalize the hash of transformations
2019-04-21 16:07:54 -04:00
Younes SERRAJ
bcf370d689 Allow ActiveStorage to generate variants of BMP images 2019-04-21 19:07:22 +02:00
Yi Feng
6be1446fc7 normalize the hash of transformations 2019-04-20 18:05:58 +08:00
Bernardo Araujo
0a8ff0be0c Set default of 28 characters in ActiveStorage::Blob.generate_unique_secure_token
The minimum character length is now 24 characters since it's inherited
from ActiveRecord::Base, but the default behaviour is still using 28
characters.
2019-04-09 19:45:26 -04:00
Fumiaki MATSUSHIMA
61c4be4777 Output junit format test report 2019-04-04 14:34:46 +09:00
Sharang Dashputre
771973c13d url -> URL where apt except inside actionpack/ 2019-04-01 22:56:35 +05:30
George Claghorn
7c5814c6e0 Revert "Add ActiveStorage.service_configurations and ActiveStorage.service"
This reverts commit 002684e36e813469c3585e193f0698784c88278b.
2019-03-31 19:23:11 -04:00
George Claghorn
002684e36e Add ActiveStorage.service_configurations and ActiveStorage.service
* Allow plugins to access the global service and alternative service configs before ActiveStorage::Blob loads.

* Make ActiveStorage.service_configurations the default second argument to ActiveStorage::Service.configure. Plugins that just want to use an alternative service defined in config/storage.yml needn't pass in the config themselves.
2019-03-31 07:46:18 -04:00
George Claghorn
197fe2222e Require railties for all Active Storage dependencies 2019-03-30 10:03:41 -04:00
George Claghorn
11d66a8e4c Specify Active Storage's dependency on Active Job 2019-03-30 10:03:19 -04:00
George Claghorn
da2c92377c Add load hook for ActiveStorage::Attachment 2019-03-28 18:52:02 -04:00
George Claghorn
562f3a2d21 Add ActiveStorage::Service#open 2019-03-28 18:47:42 -04:00
Eugeniu Tambur
135d8a0dc1 Traducir del: inglés
44/5000
Checking for the existence of only one table
2019-03-19 13:16:57 +01:00
Eugeniu Tambur
417c625ab2 Fix for migration active_storage migration
*ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "active_storage_attachments" does not exist*

Updating to rails 6.0.0.beta3 if the command rake app:update is used a new migration file is generated:

```ruby
# db/migrate/add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb
class AddForeignKeyConstraintToActiveStorageAttachmentsForBlobId < ActiveRecord::Migration[6.0]
  def up
    unless foreign_key_exists?(:active_storage_attachments, column: :blob_id)
  		add_foreign_key :active_storage_attachments, :active_storage_blobs, column: :blob_id
    end
  end
end
```

**If the project does not have previously installed active storage** this mgiration causes an error:

    ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "active_storage_attachments" does not exist

**Error output:**

    PG::UndefinedTable: ERROR:  relation "active_storage_attachments" does not exist
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/postgresql/database_statements.rb:90:in `async_exec'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/postgresql/database_statements.rb:90:in `block (2 levels) in execute'
    activesupport-6.0.0.beta3/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
    activesupport-6.0.0.beta3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
    activesupport-6.0.0.beta3/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/postgresql/database_statements.rb:89:in `block in execute'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract_adapter.rb:643:in `block (2 levels) in log'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract_adapter.rb:642:in `block in log'
    activesupport-6.0.0.beta3/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract_adapter.rb:633:in `log'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/postgresql/database_statements.rb:88:in `execute'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/schema_statements.rb:977:in `add_foreign_key'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:875:in `block in method_missing'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:843:in `block in say_with_time'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:843:in `say_with_time'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:864:in `method_missing'
    /db/migrate/20190315102607_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb:5:in `up'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:816:in `exec_migration'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:797:in `block (2 levels) in migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:796:in `block in migrate'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:795:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:985:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1293:in `block in execute_migration_in_transaction'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1344:in `block in ddl_transaction'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/database_statements.rb:265:in `block in transaction'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/transaction.rb:272:in `block in within_new_transaction'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/transaction.rb:270:in `within_new_transaction'
    activerecord-6.0.0.beta3/lib/active_record/connection_adapters/abstract/database_statements.rb:265:in `transaction'
    activerecord-6.0.0.beta3/lib/active_record/transactions.rb:212:in `transaction'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1344:in `ddl_transaction'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1292:in `execute_migration_in_transaction'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1264:in `block in migrate_without_lock'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1263:in `each'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1263:in `migrate_without_lock'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1211:in `block in migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1364:in `with_advisory_lock'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1211:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1044:in `up'
    activerecord-6.0.0.beta3/lib/active_record/migration.rb:1019:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/tasks/database_tasks.rb:191:in `migrate'
    activerecord-6.0.0.beta3/lib/active_record/railties/databases.rake:78:in `block (3 levels) in <main>'
    activerecord-6.0.0.beta3/lib/active_record/railties/databases.rake:76:in `each'
    activerecord-6.0.0.beta3/lib/active_record/railties/databases.rake:76:in `block (2 levels) in <main>'
    railties-6.0.0.beta3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
    railties-6.0.0.beta3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
    railties-6.0.0.beta3/lib/rails/command.rb:48:in `invoke'
    railties-6.0.0.beta3/lib/rails/commands.rb:18:in `<main>'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:83:in `register'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    activesupport-6.0.0.beta3/lib/active_support/dependencies.rb:297:in `block in require'
    activesupport-6.0.0.beta3/lib/active_support/dependencies.rb:263:in `load_dependency'
    activesupport-6.0.0.beta3/lib/active_support/dependencies.rb:297:in `require'
    bin/rails:4:in `<main>'
2019-03-15 12:54:42 +01:00
George Claghorn
43fc7b476b GCS service: skip unnecessary bucket lookups 2019-03-14 10:56:41 -04:00
eileencodes
a2bd669ed2 v6.0.0.beta3 release
-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEEvJkGf0BARV+D0L2ulxXUSC76N8FAlyJN4cACgkQulxXUSC7
 6N9ZXAf/Wx7edIct8kZzcC6irlROx4DzpNbrrH792sO1OAcnoFDE7DPkokllTEP/
 4kzC42lca/XG27MCl7E0dtVD8hIyAl89nxid6cwKFVZVTPIRVc1wjXkoiWy/cvd7
 6+9IjxhlgrzxGnw3aWZJG7H3iqz69yr55aoSDU/TbMqq5kQrqNF95vr2nc8LEUco
 SLQj0pO/tfJdHquSeX0JiXn3VSEHT+5TdLGQ3J/w0wFU6mkecH4MJMJvMwLFx/v4
 llnvF6HyfSLASWbrpdD3h6MQHpImDoee5vILXAHzPdSaEVcVa1cDFtMcPMYiu8Dw
 AGdCAaHQhZFFGoYK472+o6pur0dxEA==
 =5dET
 -----END PGP SIGNATURE-----

Merge tag 'v6.0.0.beta3'

v6.0.0.beta3 release
2019-03-13 13:11:10 -04:00
eileencodes
7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Prathamesh Sonpatki
538a459a3b
Squish the deprecation messages across the codebase
Sample example ->

Before:

prathamesh@Prathameshs-MacBook-Pro-2 blog *$ rails server thin
DEPRECATION WARNING: Passing the Rack server name as a regular argument is deprecated
and will be removed in the next Rails version. Please, use the -u
option instead.

After:

prathamesh@Prathameshs-MacBook-Pro-2 squish_app *$ rails server thin
DEPRECATION WARNING: Passing the Rack server name as a regular argument is deprecated and will be removed in the next Rails version. Please, use the -u option instead.
2019-03-11 19:22:37 +05:30
Kasper Timm Hansen
0fc1397784
Merge pull request #35559 from ashishprajapati/ashishprajapati/important_textual_improvements
Added missing guide links in documentation and minor wording fix
2019-03-09 22:54:21 +01:00
ashishprajapati
e3ef12b310 Added missing guide links in README documentation and minor wording fix [ci skip] 2019-03-10 03:17:01 +05:30
Abhay Nikam
027e492b6f Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
Abhay Nikam
476abd403b Updated links from http to https in guides, docs, etc 2019-03-09 16:43:47 +05:30
Matthew Draper
5083f3fd60 Decrypt the ASt test config if available 2019-03-05 15:33:00 +10:30
George Claghorn
7c95c52247
Merge pull request #35412 from abhchand/correctly-load-blob-association
Ensure that the `_blob` association is properly loaded when attaching `::One`
2019-02-26 12:11:50 -05:00
Abhishek Chandrasekhar
32438ed64f [ActiveStorage] Ensure that the _blob association is properly loaded when attaching ::One
Consider a model with `One` and `Many` attachments configured:

    class User < ActiveRecord::Base
      has_one_attached :avatar
      has_many_attached :highlights
    end

=== One Attachment

After attaching `One` attachment (`:avatar`), we can see that the associated
`_blob` record (`:avatar_blob`) still returns as `nil`.

    user.avatar.attach(blob)
    user.avatar_attachment.present?  => true
    user.avatar_blob.present?        => false    # Incorrect!

This is a false negative. It happens because after the attachment and blob
are built:

  1. The record already has its `_blob` association loaded, as `nil`
  2. the `::Attachment` is associated with the record but the `::Blob` only gets
    associated with the `::Attachment`, not the record itself

In reality, the blob does in fact exist. We can verify this as follows:

    user.avatar.attach(blob)
    user.avatar_attachment.blob.present?    => true  # Blob does exist!

The fix in this change is to simply assign the `::Blob` when assigning
the `::Attachment`. After this fix is applied, we correctly observe:

    user.avatar.attach(blob)
    user.avatar_attachment.present?  => true
    user.avatar_blob.present?        => true    # Woohoo!

=== Many Attachments

We don't see this issue with `Many` attachments because the `_blob` association
is already loaded as part of attaching more/newer blobs.

    user.highlights.attach(blob)
    user.highlights_attachments.any?    => true
    user.highlights_blobs.any?          => true
2019-02-26 11:10:38 -05:00
Rafael Mendonça França
5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05:00
Eugene Kenny
817ffc08bf Add missing require to active_storage.rb
Since b21f50d8ae36d9b50b673579e17bccbe55363b34, requiring active_storage
on its own has failed with the following error:

    activestorage/lib/active_storage.rb:55:in `<module:ActiveStorage>': undefined method `minutes' for 5:Integer (NoMethodError)
2019-02-20 21:07:34 +00:00
Abhay Nikam
d3f9226190 Delegated path_for to primary in the MirrorService 2019-02-14 23:06:42 +05:30
garytaylor
457dfc0621 Allow configuring the Azure Storage service with extra client options 2019-02-04 09:08:55 -05:00
Eileen M. Uchitelle
300c62f75c
Merge pull request #35043 from simoleone/activestorage/s3/content-type
include the content type when uploading to S3
2019-02-01 09:37:08 -05:00
alkesh26
a57f4defa7 ActiveStorage typo fix. 2019-01-31 19:42:32 +05:30
Carlos Ramirez III
f70defa1ba
Fix usage documentation in VideoAnalyzer
The code snippet within the usage documentation comment used the wrong object namespace for the ActiveStorage::Analyzer::VideoAnalyzer
2019-01-28 21:13:11 -08:00
Javan Makhmali
e3d43333db Add CHANGELOG entries for npm package renames [ci skip] 2019-01-28 06:29:26 -05:00
Simo Leone
c5b71c9bae
include the content type when uploading to S3 2019-01-24 17:05:49 +00:00
George Claghorn
c1e949e9e6 Prefer ImageProcessing's resize_to_limit macro over resize_to_fit
Don't upsize images smaller than the specified dimensions.
2019-01-24 11:46:42 -05:00
Gannon McGibbon
2e0ca9284a Revert ensure external redirects are explicitly allowed 2019-01-22 11:40:13 -05:00
Yuichi Takeuchi
ee65ca46e5 Fix ArgumentError: Unsafe redirect 2019-01-21 14:15:34 +09:00
Rafael Mendonça França
5a0230c67f
Preparing for 6.0.0.beta1 release 2019-01-18 15:42:12 -05:00
George Claghorn
9e34df0003
Merge pull request #33419 from bogdanvlviv/update-active_storage
`rake app:update` should update active_storage
2019-01-16 17:04:47 -06:00
Javan Makhmali
385d31d209 Minimize boilerplate setup code for JavaScript libraries 2019-01-16 16:15:43 -05:00
bogdanvlviv
2bad3f46cd
Add foreign key to active_storage_attachments for blob_id via new migration
We need this in order to be able to add this migration for users that
use ActiveStorage during update their apps from Rails 5.2 to Rails 6.0.

Related to #33405

`rake app:update` should update active_storage

`rake app:update` should execute `rake active_storage:update`
if it is used in the app that is being updated.
It will add new active_storage's migrations to users' apps during update Rails.

Context https://github.com/rails/rails/pull/33405#discussion_r204239399

Also, see a related discussion in the Campfire:
https://3.basecamp.com/3076981/buckets/24956/chats/12416418@1236713081
2019-01-16 13:13:23 +00:00
Javan Makhmali
86b489e3d6 Move all npm packages to @rails scope
Fixes #33083
2019-01-10 11:01:57 -05:00
Kasper Timm Hansen
647d7e6167
Revert "Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json""
I reverted the wrong commit. Damn it.

This reverts commit f66a977fc7ae30d2a07124ad91924c4ee638a703.
2019-01-08 22:19:22 +01:00
Kasper Timm Hansen
f66a977fc7
Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json"
We had a discussion on the Core team and we don't want to expose this information
as a JSON endpoint and not by default.

It doesn't make sense to expose this JSON locally and this controller is only
accessible in dev, so the proposed access from a production app seems off.

This reverts commit 8eaffe7e89719ac62ff29c2e4208cfbeb1cd1c38, reversing
changes made to b6e4305c3bca4c673996d0af9db0f4cfbf50215e.
2019-01-08 22:16:58 +01:00
Rafael França
1858614219
Merge pull request #34132 from ConfusedVorlon/enable_fragment_cache_log_in_dev
enable_fragment_cache_logging in dev by default
2019-01-08 14:15:16 -05:00
George Claghorn
ed51351536
Permit sending Active Storage purge and analysis jobs to separate queues 2019-01-01 19:40:59 -05:00
Arun Agrawal
50e3680768 Bump license years for 2019 2018-12-31 10:24:38 +07:00
Luciano Sousa
c329d323fc Permit generating variants of TIFF images 2018-12-30 18:14:49 -05:00
Julik Tarkhanov
e5f4162b61 Make Active Storage blob keys lowercase
Accommodate case-insensitive filesystems and database collations.
2018-12-30 11:56:22 -05:00
bogdanvlviv
2cfbdff63e
Use 6.0 default configs in Active Storage test dummy app 2018-12-30 03:10:31 +02:00
Cameron Bothner
372dda2a29 Don’t include an undefined X-CSRF-Token header
If there is not a `csrf-token` meta tag in the document, the blob record
XHR was including an `X-CSRF-Token` header set to the string
"undefined." Instead of setting it to undefined, it should not be
included in the absence of a meta tag.
2018-12-27 12:44:19 -05:00
Ryuta Kamizono
892e38c78e Enable Style/RedundantBegin cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00
Ryuta Kamizono
8034dde023 Module#{define_method,alias_method,undef_method,remove_method} become public since Ruby 2.5
https://bugs.ruby-lang.org/issues/14133
2018-12-21 01:39:18 +09:00
Kasper Timm Hansen
1b7c3222e8
Require Ruby 2.5 for Rails 6.
Generally followed the pattern for https://github.com/rails/rails/pull/32034

* Removes needless CI configs for 2.4
* Targets 2.5 in rubocop
* Updates existing CHANGELOG entries for fewer merge conflicts
* Removes Hash#slice extension as that's inlined on Ruby 2.5.
* Removes the need for send on define_method in MethodCallAssertions.
2018-12-19 21:47:50 +01:00
Yuji Yaginuma
222757618e
Merge pull request #34585 from marceloperini/marceloperini/33795
add require 'database/setup' in activestorage/test/service/s3_service_test.rb
2018-12-03 08:29:57 +09:00
Richard Macklin
fb0c81d349 Remove obsolete yarn.lock files and check in root yarn.lock file 2018-12-02 10:02:14 -08:00
Marcelo Perini Veloso
ce40e85194
add require 'database/setup' in activestorage/test/service/s3_service_test.rb 2018-12-01 15:47:54 -02:00
yuuji.yaginuma
6ca2f2acb2 metadata is not passed to service
Ref: 604fac6d71/activestorage/app/models/active_storage/blob.rb (L256-L264)

This fixes broken `GCSServiceTest`.
https://travis-ci.org/rails/rails/jobs/461868394#L6624-L6626

Follow up to  #34576.
2018-12-01 09:12:55 +09:00
Yannick Schutz
7bd21e8575
Add a test with extra keys to active_storage Service#upload 2018-11-30 15:54:38 +01:00
Hiroki Sanpei
4deb88ca26 Fix ArgumentError when uploading to amazon s3 2018-11-28 17:06:29 +09:00
yuuji.yaginuma
ac721c8552 Fix "warning: ambiguous first argument; put parentheses or a space even after `/' operator" 2018-11-28 11:29:03 +09:00
yuuji.yaginuma
b7ec129de5 text is treated as attachment 2018-11-28 10:35:57 +09:00
yuuji.yaginuma
c2ef8bbf52 Fix broken ActiveStorage::BlobTest
`ActiveStorage::Filename#parameters` was removed by #33829.
2018-11-28 10:16:07 +09:00
yuuji.yaginuma
7e7a60bd3f Remove duplicated test
Since 06ab7b27ea1c1ab357085439abacdb464f6742bf,
`GCSServiceTest#test_signed_URL_response_headers` is broken.
https://travis-ci.org/rails/rails/jobs/460454477#L7084-L7087

This seems to be due to lack of `content_type` at upload.
This is solved by specifying `conten_type`.

However, since the same content is also tested with `test_upload_with_content_type`,
it will be duplicated content, so I think that can remove `test_signed_URL_response_headers`.
2018-11-28 10:01:03 +09:00
Adrian Hawrylak
2c279aa980 Fix minor Active Storage docs typo [ci skip] 2018-11-28 00:27:58 +01:00
Rosa Gutierrez
06ab7b27ea Prevent content type and disposition bypass in storage service URLs
* Force content-type to binary on service urls for relevant content types

We have a list of content types that must be forcibly served as binary,
but in practice this only means to serve them as attachment always. We
should also set the Content-Type to the configured binary type.

As a bonus: add text/cache-manifest to the list of content types to be
served as binary by default.

* Store content-disposition and content-type in GCS

Forcing these in the service_url when serving the file works fine for S3
and Azure, since these services include params in the signature.
However, GCS specifically excludes response-content-disposition and
response-content-type from the signature, which means an attacker can
modify these and have files that should be served as text/plain attachments
served as inline HTML for example. This makes our attempt to force
specific files to be served as binary and as attachment can be easily
bypassed.

The only way this can be forced in GCS is by storing
content-disposition and content-type in the object metadata.

* Update GCS object metadata after identifying blob

In some cases we create the blob and upload the data before identifying
the content-type, which means we can't store that in GCS right when
uploading. In these, after creating the attachment, we enqueue a job to
identify the blob, and set the content-type.

In other cases, files are uploaded to the storage service via direct
upload link. We create the blob before the direct upload, which happens
independently from the blob creation itself. We then mark the blob as
identified, but we have already the content-type we need without having
put it in the service.

In these two cases, then, we need to update the metadata in the GCS
service.

* Include content-type and disposition in the verified key for disk service

This prevents an attacker from modifying these params in the service
signed URL, which is particularly important when we want to force them
to have specific values for security reasons.

* Allow only a list of specific content types to be served inline

This is different from the content types that must be served as binary
in the sense that any content type not in this list will be always
served as attachment but with its original content type. Only types in
this list are allowed to be served either inline or as attachment.

Apart from forcing this in the service URL, for GCS we need to store the
disposition in the metadata.

Fix CVE-2018-16477.
2018-11-27 15:36:27 -05:00
Tasos Maschalidis
d6fcc419fe ASt direct uploads: account for <button type="submit"> elements 2018-11-24 14:54:05 -05:00
Maurice Kühlborn
455a122ef0 Add progressive JPG to default variable content types 2018-11-21 23:21:01 +01:00
Gannon McGibbon
e74fdbe00c Amend CVE note and security guide section wordings
Reword first sentence of dep management and CVE section of
security guide. Also, reword and move gemspec notes above deps.

[ci skip]
2018-11-06 18:06:57 -05:00
Gannon McGibbon
1c11688b56 Add CVE note to security guide and gemspecs
[ci skip]
2018-11-06 14:25:36 -05:00
Kyle Keesling
79e086efc4
update activestorage attachment model documentation reflect recent behavior changes 2018-10-24 09:08:45 -04:00
Rob Jonson
d8707e0dfc enable_fragment_cache_logging
fragment caching was refactored in (I think 5.2) and by default doesn't log cache info

this is confusing in development where rails dev:cache now turns on caching, but doesn't show any different logging output

better to enable debugging by default for dev - and let people turn it off if preferred
2018-10-09 11:48:40 +01:00
Donnie Propst
b4e827d80a Point to requiring the ASt engine in the installation instructions [ci skip] 2018-10-08 11:26:51 -04:00
Graham Conzett
bba5ecc923 Use content_mime_type 2018-10-08 09:50:51 -04:00
Graham Conzett
1986048d27 Fix issue ActiveStorage direct upload disk
Fix an issue in ActiveStorage where a direct upload to disk storage
would fail due to a content type mismatch if the file was uploaded using
a mime-type synonym.
2018-10-07 16:07:09 -04:00
David Heinemeier Hansson
4838c1716a
Make Webpacker the default JavaScript compiler for Rails 6 (#33079)
* Use Webpacker by default on new apps

* Stop including coffee-rails by default

* Drop using a js_compressor by default

* Drop extra test for coffeescript inclusion by default

* Stick with skip_javascript to signify skipping webpack

* Don't install a JS runtime by default any more

* app/javascript will be the new default directory for JS

* Make it clear that this is just for configuring the default Webpack framework setup now

* Start using the Webpack tag in the default layout

* Irrelevant test

* jQuery is long gone

* Stop having asset pipeline compile default application.js

* Add rails-ujs by default to the Webpack setup

* Add Active Storage JavaScript to application.js pack by default

* Consistent quoting

* Add Turbolinks to default pack

* Add Action Cable to default pack

Need some work on how to set the global consumer that channels will
work with. @javan?

* Require all channels by default and use a separate consumer stub

* Channel generator now targets Webpack style

* Update task docs to match new generator style

* Use uniform import style

* Drop the JS assets generator

It was barely helpful as it was. It’s no longer helpful in a Webpacked
world. Sayonara!

* Add app/javascript to the stats directories

* Simpler import style

Which match the other imports.

* Address test failures from dropping JS compilation (and compression)

* webpacker-default: Modify `AssetsGeneratorTest`

Before:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 46201

F

Failure:
AssetsGeneratorTest#test_assets [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:12]:
Expected file "app/assets/javascripts/posts.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:10

.

Finished in 0.031343s, 63.8101 runs/s, 95.7152 assertions/s.
2 runs, 3 assertions, 1 failures, 0 errors, 0 skips
```

After:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 43571

..

Finished in 0.030370s, 65.8545 runs/s, 65.8545 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```

* webpacker-default: Modify `ChannelGeneratorTest`

Before:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 8986

.F

Failure:
ChannelGeneratorTest#test_channel_with_multiple_actions_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:43]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:34

.F

Failure:
ChannelGeneratorTest#test_channel_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:29]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:22

E

Error:
ChannelGeneratorTest#test_cable_js_is_created_if_not_present_already:
Errno::ENOENT: No such file or directory @ apply2files - /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/fixtures/tmp/app/assets/javascripts/cable.js

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:60

F

Failure:
ChannelGeneratorTest#test_channel_suffix_is_not_duplicated [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:87]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:80

F

Failure:
ChannelGeneratorTest#test_channel_on_revoke [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:77]:
Expected file "app/assets/javascripts/cable.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:68

Finished in 0.064384s, 108.7227 runs/s, 481.4861 assertions/s.
7 runs, 31 assertions, 4 failures, 1 errors, 0 skips
```

After:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 44857

.......

Finished in 0.060243s, 116.1961 runs/s, 697.1764 assertions/s.
7 runs, 42 assertions, 0 failures, 0 errors, 0 skips
```

* Fix shared generator tests.

* webpacker-default: Modify `ControllerGeneratorTest`

The JS assets generator was dropped. ref. 46215b1794

* Revert "Simpler import style". It's currently failing with an error of "TypeError: undefined is not an object (evaluating '__WEBPACK_IMPORTED_MODULE_2_activestorage___default.a.start')". Waiting for @javan to have a look.

This reverts commit 5d3ebb71059f635d3756cbda4ab9752027e09256.

* require webpacker in test app

* Add webpacker without making the build hang/timeout. (#33640)

* use yarn workspaces to allow for installing unreleased packages and only generate js/bootsnap when required

* no longer need to have webpacker in env templates as webpacker moved this config to yml file

* Fix rubocop violation

* Got the test passing for the running scaffold

* update expected lines of code

* update middleware tests to account for webpacker

* disable js in plugins be default to get the tests passing (#34009)

* clear codeclimate report issues

* Anything newer than currently released is good

* Use Webpacker development version during development of Rails

* Edge should get development webpacker as well

* Add changelog entry for Webpacker change
2018-09-30 22:31:21 -07:00
Rafael Mendonça França
f679933daa
Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
Kasper Timm Hansen
ed56a03104
Merge pull request #33829 from mtsmfm/encode-filename
Encode Content-Disposition filenames on send_data and send_file
2018-09-23 19:43:06 +02:00
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
bogdanvlviv
be0d22a8e1
Raise ActiveRecord::InvalidForeignKey in before_destroy for a blob if attachments exist
The issue #32584 was fixed in #33405 by adding foreign key constraint
to the `active_storage_attachments` table for blobs.
This commit implements fix on app-level in order to ensure that users
can't delete a blob with attachments even if they don't have the foreign key constraint.
See a related discussion in the Campfire:
https://3.basecamp.com/3076981/buckets/24956/chats/12416418@1236718899

Note that, we should backport it to `5-2-stable` too.

Related to #33405
2018-09-16 22:44:30 +03:00
Chris Bisnett
7dd9916c0d Configure Active Storage route prefix
Applications can configure the route prefix prepended to the Active
Storage routes. By default this maintains the previous prefix
`/rails/active_storage` but supports custom prefixes.

Before this change the route for serving blobs is fixed to
`/rails/active_storage/blobs/:signed_id/*filename`. After this change
it's possible to configure the route to something like
`/files/blobs/:signed_id/*filename`.
2018-09-14 10:40:18 -04:00
Fumiaki MATSUSHIMA
890485cfce Encode Content-Disposition filenames on send_data and send_file 2018-09-13 21:38:46 +09:00
Xavier Noria
f589e20b0a use "minitest" consistently
The name of the minitest library is spelled that way: regular font, and
lowercase. Lowercase is used even at the beginning of sentences, see

    http://docs.seattlerb.org/minitest/

I double-checked this with @zenspider too (thanks!).
2018-09-11 23:57:25 +02:00
Marcelo Perini Veloso
0d4ba40688 Fix zero-byte files upload 2018-09-06 20:04:21 -03:00
Cameron Bothner
aae56c3529 Handle only specifically relevant Azure HTTPErrors
The Azure gem uses `Azure::Core::Http::HTTPError` for everything:
checksum mismatch, missing object, network unavailable, and many more.
(https://www.rubydoc.info/github/yaxia/azure-storage-ruby/Azure/Core/Http/HTTPError).
Rescuing that class obscures all sorts of  configuration errors. We
should check the type of error in those rescue  blocks, and reraise when
needed.
2018-08-23 23:36:43 -04:00
George Claghorn
3868648cae Revert "Merge pull request #33667 from cbothner/azure-service-swallowing-all-errors"
This reverts commit b204d167c5cfebd59f771d406178e371811ac43a, reversing
changes made to de6a200f82a3de399fa685d583503bc88dbc5e9f.
2018-08-23 19:07:29 -04:00
Cameron Bothner
6acf2fa363 Handle only specifically relevant Azure HTTPErrors
The Azure gem uses `Azure::Core::Http::HTTPError` for everything:
checksum mismatch, missing object, network unavailable, and many more.
(https://www.rubydoc.info/github/yaxia/azure-storage-ruby/Azure/Core/Http/HTTPError).
Rescuing that class obscures all sorts of  configuration errors. We
should check the type of error in those rescue  blocks, and reraise when
needed.
2018-08-23 17:54:35 -04:00
George Claghorn
dc001dbd58
Merge pull request #33666 from cbothner/fail-gracefully-from-activestorage-file-not-found
Fail more gracefully from ActiveStorage missing file exceptions
2018-08-22 22:56:10 -04:00
Cameron Bothner
22efb2ec49 Respond with 404 in ActiveStorage::DiskController#show when file missing
`ActiveStorage::DiskController#show` generates a 404 Not Found response when
the requested file is missing from the disk service. It previously raised
`Errno::ENOENT`.
2018-08-21 15:35:58 -04:00
Cameron Bothner
5cd2d07bdc Translate service-specific missing object exceptions into a generic one
`ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
`ActiveStorage::FileNotFoundError` when the corresponding file is missing
from the storage service. Services translate service-specific missing
object exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service
and `Errno::ENOENT` for the disk service) into
`ActiveStorage::FileNotFoundError`.
2018-08-21 15:31:14 -04:00
bogdanvlviv
0e77706dc5
activestorage: yarn build
Context https://github.com/rails/rails/pull/33413#issuecomment-414137587
2018-08-19 19:33:16 +03:00
George Claghorn
093d8d3953 Retry ActiveStorage::AnalyzeJobs on download integrity check failures 2018-08-19 01:19:51 -04:00
George Claghorn
116fae6ef9 Remove superfluous test
This test no longer covers the behavior of ActiveStorage::PurgeJob. Attached blobs are ignored by ActiveStorage::Blob#purge as of 934fccd, which includes an equivalent model test.
2018-08-19 01:10:50 -04:00
Chris Seelus
880f977925 Enable multiple submit buttons for Active Storage forms 2018-08-18 19:31:39 +02:00
George Claghorn
e33c3cd8cc Extract ActiveStorage::SetCurrent
Provide a handy concern for custom Active Storage controllers that can't inherit from ActiveStorage::BaseController.
2018-08-16 01:41:15 -04:00
George Claghorn
2d3a28b949 Document all Active Storage error classes [ci skip] 2018-08-10 18:38:28 -04:00
George Claghorn
18425b8371 Add a generic base class for Active Storage exceptions
Closes #33292.

[Andrei Makarov & George Claghorn]
2018-08-10 18:35:49 -04:00
George Claghorn
697f4a93ad Extract transformers 2018-08-10 12:42:14 -04:00
George Claghorn
10129fbf57 DRY up web image checks in ActiveStorage::Variant 2018-08-09 19:53:12 -04:00
George Claghorn
79573b3aff Camelize instead of classifying
Avoid mangling service names that end in S:

    "GCS".classify # => "GC"
    "GCS".camelize # => "GCS"
2018-08-06 22:23:47 -04:00
Joel Taylor
3082786be6 Improve ActiveStorage service adapter error handling 2018-08-06 18:17:49 -07:00
George Claghorn
bd680dd59a Fix uploading Tempfiles to Azure Storage
Closes #32530.
2018-08-03 22:41:19 -04:00
George Claghorn
bba4d2dd8c Remove another unused require 2018-08-02 14:38:33 -04:00
George Claghorn
bd01f9831c Remove unused require 2018-08-01 09:59:04 -04:00
George Claghorn
fee7fba893 Retry ActiveStorage::PurgeJobs on DB deadlock 2018-07-31 19:29:23 -04:00
George Claghorn
cd2fe237f7 Guard against missing blobs caused by concurrent purges 2018-07-30 21:42:20 -04:00
George Claghorn
362042c0d7 Ignore concurrently-deleted files when deleting by prefix from GCS 2018-07-30 13:13:00 -04:00
George Claghorn
6a0b0154e3 Update ActiveStorage::Previewer docs
PDFPreviewer became MuPDFPreviewer in 0b717c2. Previewers are simple enough that we can just provide a single example.
2018-07-29 11:48:11 -04:00
George Claghorn
046bd75b0e Clarify condition
&& binds tighter than || in JavaScript, but we ought not expect readers to remember language trivia.
2018-07-27 00:20:47 -04:00
George Claghorn
195463736c Fix directly uploading zero-byte files
Closes #33450.
2018-07-27 00:11:22 -04:00
George Claghorn
e03add2248 Log streaming downloads 2018-07-26 18:48:04 -04:00
Jasper Martin
934fccd522 Ignore ActiveRecord::InvalidForeignKey in ActiveStorage::Blob#purge
Do nothing instead of raising an error when it’s called on an attached blob.
2018-07-26 09:24:31 -04:00
Matthew Draper
ec387c6dd9
Merge pull request #33229 from albertoalmagro/albertoalmagro/prefer-rails-command-over-bin-rails
Prefer rails command over bin/rails
2018-07-25 04:10:29 +09:30
George Claghorn
0f57f75008 Remove unused attribute 2018-07-21 14:21:14 -04:00
George Claghorn
6c45b04a73 Discard ActiveStorage::PurgeJobs on ActiveRecord::InvalidForeignKey 2018-07-20 11:18:37 -04:00
George Claghorn
562ec3dcd1 Test that ActiveStorage::Blob#purge fails when attachments exist 2018-07-20 10:28:14 -04:00
George Claghorn
2ae3a29508 Add a foreign-key constraint to the attachments table for blobs 2018-07-19 20:43:33 -04:00
George Claghorn
3f53296f18 Delete attachment before purging blob 2018-07-19 20:26:56 -04:00
George Claghorn
07ecaa614b Destroy blob record before deleting stored data 2018-07-19 20:26:40 -04:00
George Claghorn
3ccec9b80d Link between ActiveStorage::Blob#purge, #purge_later, and #delete [ci skip] 2018-07-18 22:06:15 -04:00
George Claghorn
ac6e6c6b99 Clarify the ActiveStorage::Attachment#purge and #purge_later docs
Link to the corresponding ActiveStorage::Blob methods, whose docs more accurately describe their effects. [ci skip]
2018-07-18 21:59:31 -04:00
George Claghorn
af02b9b78f Remove unnecessary tap 2018-07-17 16:23:53 -04:00
George Claghorn
e13e16f5ad Fix replacing many attachments via assign and attach 2018-07-17 09:33:48 -04:00
George Claghorn
379d98dcd4 Correct test name 2018-07-16 15:59:17 -04:00
George Claghorn
36ec5428bf Fix that successive ActiveStorage::Attached::Many#attach calls would overwrite previous attachments 2018-07-16 15:57:43 -04:00
George Claghorn
1d13de4e39 Test removing attachments via #attach 2018-07-16 08:59:23 -04:00
George Claghorn
94f2558f6a Restore inadvertently-removed fallback 2018-07-15 20:12:53 -04:00
George Claghorn
390097531b Support HTTP Range downloads from disk
Closes #32193.
2018-07-15 19:58:14 -04:00
George Claghorn
bd5eba1adf Clear attachment changes on reload 2018-07-13 14:48:45 -04:00
George Claghorn
28db8ba60e Implement ActiveStorage::Attached::{One,Many}#attach in terms of changes 2018-07-13 13:29:33 -04:00
George Claghorn
d20d6c7326 Fix that detaching could purge 2018-07-13 12:17:33 -04:00
George Claghorn
63951072af Fix analyzing new blobs from uploaded files on attach 2018-07-13 06:33:45 -04:00
George Claghorn
16f435f931 Discard ActiveStorage::PurgeJobs for missing blobs 2018-07-11 22:09:23 -04:00
George Claghorn
a1735a0dde Remove overly-broad retry in ActiveStorage::PurgeJob
We've never intentionally tripped this retry in production. Add retries for specific errors as needed.
2018-07-11 22:04:42 -04:00
George Claghorn
0b85123cd8 Raise an ArgumentError instead of a RuntimeError 2018-07-08 11:35:27 -04:00
George Claghorn
e8682c5bf0
Store newly-uploaded files on save rather than assignment 2018-07-07 23:25:33 -04:00
George Claghorn
03afddd2eb Fix that models can clobber each others' attachment reflections
Consider the following model definitions:

    class User < ApplicationRecord
      has_one_attached :avatar
    end

    class Group < ApplicationRecord
      has_one_attached :avatar
    end

If you attempt to reflect on the User model's avatar attachment via User.reflect_on_attachment, you could receive a reflection for the Group model's avatar attachment. Fix this by ensuring that each model class uses its own Hash object to track attachment reflections.
2018-07-07 17:09:31 -04:00
Alberto Almagro
40b209db53 Recommend use of rails over bin/rails
As discussed in #33203 rails command already looks for, and runs,
bin/rails if it is present.

We were mixing recommendations within guides and USAGE guidelines,
in some files we recommended using rails, in others bin/rails and
in some cases we even had both options mixed together.
2018-07-06 22:46:35 +02:00
Bibek Shrestha
637a8cde59 Remove vestigial require on ActiveStorage GCSService
The file `filename.rb` as mentioned in `require "active_storage/filename"`
belongs to the `app` folder while GCSService belongs to the lib folder.

Looking at the git blame, it was added in commit ccac681122 (diff-bda6a610ef1575b2c8458c96b7f12578)
where ActiveStorage::Filename was actually used. But it is no longer
required on master and therefore can be removed.

This allows anyone to use GCSService directly without enabling
ActiveStorage engine.
2018-07-04 17:04:26 -04:00
utilum
875ef6e748 Tweak Previewer::PopplerPDFPreviewer#pdftoppm_exists?
Does not warn `instance variable @pdftoppm_exists not initialized`.
2018-06-29 07:58:28 +02:00
George Claghorn
56b9d0fd3a Generate a new key for each service test
Sidestep Google Cloud Storage's restrictive per-object rate limit.
2018-06-25 18:49:26 -04:00
ishanray
d3715e67f1
Update service.rb 2018-06-24 00:09:31 -04:00
George Claghorn
b21f50d8ae Permit configuring the default service URL expiry 2018-06-21 11:06:32 -04:00
yuuji.yaginuma
38dbc8e2b8 Fix "warning: Net::HTTPResponse#header is obsolete"
Ref: cc77a81129/lib/net/http/response.rb (L138-L155)
2018-06-17 21:35:07 +09:00
utilum
d70bd73f05 Update ffmpeg -> FFmpeg, mutools|mupdf -> muPDF
[ci skip]
2018-06-08 11:28:11 +02:00
bogdanvlviv
8bc9062aee
Refactor activestorage/test/models/attached_test.rb
Don't include `ActiveJob::TestHelper` since there is no test that uses it.

Ensure removing of overridden User's methods.

Related to https://github.com/rails/rails/pull/33085#issuecomment-395548563
Module#remove_method is private in Ruby 2.4.

Related to fd0bd1bf682622f064ac437ceee4e1b2a6b6d3b9
2018-06-07 23:29:03 +03:00
George Claghorn
d3e0a9f110 Exclude upload time from instrumented preview time 2018-06-03 20:24:51 -04:00
Rafael França
c1844477a1
Merge pull request #33018 from kddeisz/defined-attachments
ActiveStorage reflection
2018-06-01 14:24:06 -04:00