diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-08-05 09:11:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-05 09:11:02 -0500 |
commit | 616f3611d525b97c5cdb1a5feee25621cca27daf (patch) | |
tree | 79591ed29b2a9670519438bce2d53f1a096cee06 /activestorage | |
parent | bb7599a6c84aba44cbb5f21486ffdb4a549717dd (diff) | |
parent | 6df24c693ed50a66feaf116c90df7eba5acf4033 (diff) | |
download | rails-616f3611d525b97c5cdb1a5feee25621cca27daf.tar.gz rails-616f3611d525b97c5cdb1a5feee25621cca27daf.tar.bz2 rails-616f3611d525b97c5cdb1a5feee25621cca27daf.zip |
Merge branch 'master' into ast-module
Diffstat (limited to 'activestorage')
-rw-r--r-- | activestorage/README.md | 2 | ||||
-rw-r--r-- | activestorage/app/models/active_storage/blob.rb | 8 | ||||
-rw-r--r-- | activestorage/lib/active_storage/attached/macros.rb | 12 | ||||
-rw-r--r-- | activestorage/lib/active_storage/engine.rb | 2 | ||||
-rw-r--r-- | activestorage/lib/active_storage/gem_version.rb | 4 | ||||
-rw-r--r-- | activestorage/lib/active_storage/service/azure_storage_service.rb | 2 | ||||
-rw-r--r-- | activestorage/package.json | 6 | ||||
-rw-r--r-- | activestorage/test/controllers/direct_uploads_controller_test.rb | 4 | ||||
-rw-r--r-- | activestorage/test/controllers/variants_controller_test.rb | 2 | ||||
-rw-r--r-- | activestorage/test/models/variant_test.rb | 6 | ||||
-rw-r--r-- | activestorage/test/service/disk_service_test.rb | 4 | ||||
-rw-r--r-- | activestorage/test/service/s3_service_test.rb | 2 |
12 files changed, 30 insertions, 24 deletions
diff --git a/activestorage/README.md b/activestorage/README.md index 22e77e2837..06594a3ecb 100644 --- a/activestorage/README.md +++ b/activestorage/README.md @@ -9,7 +9,7 @@ MiniMagick supported transformation. ## Compared to other storage solutions -A key difference to how Active Storage works compared to other attachment solutions in Rails is through the use of built-in [Blob](https://github.com/rails/activestorage/blob/master/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/activestorage/blob/master/app/models/active_storage/attachment.rb) models (backed by Active Record). This means existing application models do not need to be modified with additional columns to associate with files. Active Storage uses polymorphic associations via the join model of `Attachment`, which then connects to the actual `Blob`. +A key difference to how Active Storage works compared to other attachment solutions in Rails is through the use of built-in [Blob](https://github.com/rails/rails/blob/master/activestorage/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/rails/blob/master/activestorage/app/models/active_storage/attachment.rb) models (backed by Active Record). This means existing application models do not need to be modified with additional columns to associate with files. Active Storage uses polymorphic associations via the join model of `Attachment`, which then connects to the actual `Blob`. These `Blob` models are intended to be immutable in spirit. One file, one blob. You can associate the same blob with multiple application models as well. And if you want to do transformations of a given `Blob`, the idea is that you'll simply create a new one, rather than attempt to mutate the existing (though of course you can delete that later if you don't need it). diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb index debc62bd41..c72073f9f6 100644 --- a/activestorage/app/models/active_storage/blob.rb +++ b/activestorage/app/models/active_storage/blob.rb @@ -80,22 +80,22 @@ class ActiveStorage::Blob < ActiveRecord::Base # Returns true if the content_type of this blob is in the image range, like image/png. def image? - content_type =~ /^image/ + content_type.start_with?("image") end # Returns true if the content_type of this blob is in the audio range, like audio/mpeg. def audio? - content_type =~ /^audio/ + content_type.start_with?("audio") end # Returns true if the content_type of this blob is in the video range, like video/mp4. def video? - content_type =~ /^video/ + content_type.start_with?("video") end # Returns true if the content_type of this blob is in the text range, like text/plain. def text? - content_type =~ /^text/ + content_type.start_with?("text") end # Returns a `ActiveStorage::Variant` instance with the set of `transformations` passed in. This is only relevant diff --git a/activestorage/lib/active_storage/attached/macros.rb b/activestorage/lib/active_storage/attached/macros.rb index fbd64b5edc..5779348148 100644 --- a/activestorage/lib/active_storage/attached/macros.rb +++ b/activestorage/lib/active_storage/attached/macros.rb @@ -23,8 +23,11 @@ module ActiveStorage # (i.e. destroyed) whenever the record is destroyed. def has_one_attached(name, dependent: :purge_later) define_method(name) do - instance_variable_get("@active_storage_attached_#{name}") || + if instance_variable_defined?("@active_storage_attached_#{name}") + instance_variable_get("@active_storage_attached_#{name}") + else instance_variable_set("@active_storage_attached_#{name}", ActiveStorage::Attached::One.new(name, self)) + end end has_one :"#{name}_attachment", -> { where(name: name) }, class_name: "ActiveStorage::Attachment", as: :record @@ -61,8 +64,11 @@ module ActiveStorage # (i.e. destroyed) whenever the record is destroyed. def has_many_attached(name, dependent: :purge_later) define_method(name) do - instance_variable_get("@active_storage_attached_#{name}") || + if instance_variable_defined?("@active_storage_attached_#{name}") + instance_variable_get("@active_storage_attached_#{name}") + else instance_variable_set("@active_storage_attached_#{name}", ActiveStorage::Attached::Many.new(name, self)) + end end has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "ActiveStorage::Attachment" @@ -75,4 +81,4 @@ module ActiveStorage end end end -end +end
\ No newline at end of file diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb index 1d345920fa..da83d3908a 100644 --- a/activestorage/lib/active_storage/engine.rb +++ b/activestorage/lib/active_storage/engine.rb @@ -27,7 +27,7 @@ module ActiveStorage initializer "active_storage.verifier" do config.after_initialize do |app| - if app.config.secret_key_base.present? + if app.secrets.secret_key_base.present? ActiveStorage.verifier = app.message_verifier("ActiveStorage") end end diff --git a/activestorage/lib/active_storage/gem_version.rb b/activestorage/lib/active_storage/gem_version.rb index cde112a006..db79c669bf 100644 --- a/activestorage/lib/active_storage/gem_version.rb +++ b/activestorage/lib/active_storage/gem_version.rb @@ -5,8 +5,8 @@ module ActiveStorage end module VERSION - MAJOR = 0 - MINOR = 1 + MAJOR = 5 + MINOR = 2 TINY = 0 PRE = "alpha" diff --git a/activestorage/lib/active_storage/service/azure_storage_service.rb b/activestorage/lib/active_storage/service/azure_storage_service.rb index 62b13433fe..c2e1b25a43 100644 --- a/activestorage/lib/active_storage/service/azure_storage_service.rb +++ b/activestorage/lib/active_storage/service/azure_storage_service.rb @@ -20,7 +20,7 @@ module ActiveStorage instrument :upload, key, checksum: checksum do begin blobs.create_block_blob(container, key, io, content_md5: checksum) - rescue Azure::Core::Http::HTTPError => e + rescue Azure::Core::Http::HTTPError raise ActiveStorage::IntegrityError end end diff --git a/activestorage/package.json b/activestorage/package.json index 299898017c..56d307f9d6 100644 --- a/activestorage/package.json +++ b/activestorage/package.json @@ -6,13 +6,13 @@ "files": [ "app/assets/javascripts/*.js" ], - "homepage": "https://github.com/rails/activestorage", + "homepage": "http://rubyonrails.org/", "repository": { "type": "git", - "url": "git+https://github.com/rails/activestorage.git" + "url": "git+https://github.com/rails/rails.git" }, "bugs": { - "url": "https://github.com/rails/activestorage/issues" + "url": "https://github.com/rails/rails/issues" }, "author": "Javan Makhmali <javan@javan.us>", "license": "MIT", diff --git a/activestorage/test/controllers/direct_uploads_controller_test.rb b/activestorage/test/controllers/direct_uploads_controller_test.rb index e056b629bb..4f335c7759 100644 --- a/activestorage/test/controllers/direct_uploads_controller_test.rb +++ b/activestorage/test/controllers/direct_uploads_controller_test.rb @@ -25,7 +25,7 @@ if SERVICE_CONFIGURATIONS[:s3] && SERVICE_CONFIGURATIONS[:s3][:access_key_id].pr assert_equal checksum, details["checksum"] assert_equal "text/plain", details["content_type"] assert_match SERVICE_CONFIGURATIONS[:s3][:bucket], details["direct_upload"]["url"] - assert_match /s3\.(\S+)?amazonaws\.com/, details["direct_upload"]["url"] + assert_match(/s3\.(\S+)?amazonaws\.com/, details["direct_upload"]["url"]) assert_equal({ "Content-Type" => "text/plain", "Content-MD5" => checksum }, details["direct_upload"]["headers"]) end end @@ -115,7 +115,7 @@ class ActiveStorage::DiskDirectUploadsControllerTest < ActionDispatch::Integrati assert_equal 6, details["byte_size"] assert_equal checksum, details["checksum"] assert_equal "text/plain", details["content_type"] - assert_match /rails\/active_storage\/disk/, details["direct_upload"]["url"] + assert_match(/rails\/active_storage\/disk/, details["direct_upload"]["url"]) assert_equal({ "Content-Type" => "text/plain" }, details["direct_upload"]["headers"]) end end diff --git a/activestorage/test/controllers/variants_controller_test.rb b/activestorage/test/controllers/variants_controller_test.rb index fa8d15977d..b3ff83e95e 100644 --- a/activestorage/test/controllers/variants_controller_test.rb +++ b/activestorage/test/controllers/variants_controller_test.rb @@ -12,7 +12,7 @@ class ActiveStorage::VariantsControllerTest < ActionDispatch::IntegrationTest signed_blob_id: @blob.signed_id, variation_key: ActiveStorage::Variation.encode(resize: "100x100")) - assert_redirected_to /racecar.jpg\?.*disposition=inline/ + assert_redirected_to(/racecar.jpg\?.*disposition=inline/) image = read_image_variant(@blob.variant(resize: "100x100")) assert_equal 100, image.width diff --git a/activestorage/test/models/variant_test.rb b/activestorage/test/models/variant_test.rb index 7d52f005a7..04ebaccb6a 100644 --- a/activestorage/test/models/variant_test.rb +++ b/activestorage/test/models/variant_test.rb @@ -8,7 +8,7 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase test "resized variation" do variant = @blob.variant(resize: "100x100").processed - assert_match /racecar.jpg/, variant.service_url + assert_match(/racecar.jpg/, variant.service_url) image = read_image_variant(variant) assert_equal 100, image.width @@ -17,11 +17,11 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase test "resized and monochrome variation" do variant = @blob.variant(resize: "100x100", monochrome: true).processed - assert_match /racecar.jpg/, variant.service_url + assert_match(/racecar.jpg/, variant.service_url) image = read_image_variant(variant) assert_equal 100, image.width assert_equal 67, image.height - assert_match /Gray/, image.colorspace + assert_match(/Gray/, image.colorspace) end end diff --git a/activestorage/test/service/disk_service_test.rb b/activestorage/test/service/disk_service_test.rb index a625521601..2fdb113616 100644 --- a/activestorage/test/service/disk_service_test.rb +++ b/activestorage/test/service/disk_service_test.rb @@ -6,7 +6,7 @@ class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase include ActiveStorage::Service::SharedServiceTests test "url generation" do - assert_match /rails\/active_storage\/disk\/.*\/avatar\.png\?.+disposition=inline/, - @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png", content_type: "image/png") + assert_match(/rails\/active_storage\/disk\/.*\/avatar\.png\?.+disposition=inline/, + @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png", content_type: "image/png")) end end diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb index 6d613fd4fc..57e13e6538 100644 --- a/activestorage/test/service/s3_service_test.rb +++ b/activestorage/test/service/s3_service_test.rb @@ -33,7 +33,7 @@ if SERVICE_CONFIGURATIONS[:s3] && SERVICE_CONFIGURATIONS[:s3][:access_key_id].pr url = @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png", content_type: "image/png") - assert_match /s3\.(\S+)?amazonaws.com.*response-content-disposition=inline.*avatar\.png.*response-content-type=image%2Fpng/, url + assert_match(/s3\.(\S+)?amazonaws.com.*response-content-disposition=inline.*avatar\.png.*response-content-type=image%2Fpng/, url) assert_match SERVICE_CONFIGURATIONS[:s3][:bucket], url end |