From 6768390a429d43539d72edc710175e3e84e17696 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 4 Aug 2017 09:22:57 +0900 Subject: Use `content_type.start_with?("...")` than `content_type =~ /^.../` `start_with?` is a little faster than regexp for prefix matching by a fixed string. --- activestorage/app/models/active_storage/blob.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 -- cgit v1.2.3 From 70d0e53db7e761eff321daa426a36c7cd8204984 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 5 Aug 2017 08:23:33 +0900 Subject: Fix repository URL [ci skip] changed `rails/activestorage` to `rails/rails`. --- activestorage/README.md | 2 +- activestorage/package.json | 6 +++--- 2 files changed, 4 insertions(+), 4 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/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 ", "license": "MIT", -- cgit v1.2.3 From 46db463d068d9b24c99f11a1c78dac1c1bfb45c2 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 5 Aug 2017 12:21:21 +0900 Subject: Fix ruby warnings This fixes following warnings: ``` test/models/variant_test.rb:11: warning: ambiguous first argument; put parentheses or a space even after `/' operator lib/active_storage/attached/macros.rb:63: warning: instance variable @active_storage_attached_highlights not initialized lib/active_storage/attached/macros.rb:25: warning: instance variable @active_storage_attached_avatar not initialized ``` --- activestorage/lib/active_storage/attached/macros.rb | 10 ++++++++-- .../test/controllers/direct_uploads_controller_test.rb | 4 ++-- activestorage/test/controllers/variants_controller_test.rb | 2 +- activestorage/test/models/variant_test.rb | 6 +++--- activestorage/test/service/disk_service_test.rb | 4 ++-- activestorage/test/service/s3_service_test.rb | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/activestorage/lib/active_storage/attached/macros.rb b/activestorage/lib/active_storage/attached/macros.rb index 89297e5bdf..f09f3e1f6d 100644 --- a/activestorage/lib/active_storage/attached/macros.rb +++ b/activestorage/lib/active_storage/attached/macros.rb @@ -22,8 +22,11 @@ module ActiveStorage::Attached::Macros # (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 @@ -60,8 +63,11 @@ module ActiveStorage::Attached::Macros # (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" 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 -- cgit v1.2.3 From 5a6c4c2e52317e128a41e592cdabb46b8c560eca Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 5 Aug 2017 14:01:40 +0900 Subject: Add missing blank line between `config.active_storage` and `config.action_cable` --- .../generators/rails/app/templates/config/environments/production.rb.tt | 1 + 1 file changed, 1 insertion(+) diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 5b16ada442..f68e13aa8b 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -47,6 +47,7 @@ Rails.application.configure do # Store uploaded files on the local file system (see config/storage.yml for options) config.active_storage.service = :local + <%- unless options[:skip_action_cable] -%> # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil -- cgit v1.2.3 From 10a7ae39c611b571719efcd1890b88d38017382c Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 5 Aug 2017 14:24:31 +0900 Subject: Change gem version of Active Storage to 5.2.0.alpha --- activestorage/lib/active_storage/gem_version.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" -- cgit v1.2.3 From d6b8b8c1429f8291105bea6bb59d407d442988e8 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sat, 5 Aug 2017 17:28:26 +0930 Subject: Revert "Merge pull request #15446 from akshay-vishnoi/doc_changes" It was right as originally written in #15440. --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 44e95f58a1..12291af443 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -236,7 +236,7 @@ module ActiveSupport # dup = hash.dup # dup[:a][:c] = 'c' # - # hash[:a][:c] # => nil + # hash[:a][:c] # => "c" # dup[:a][:c] # => "c" def dup self.class.new(self).tap do |new_hash| -- cgit v1.2.3 From 2b9e04b6f9b21087a8b44c4b3758d0b3ae1e7e12 Mon Sep 17 00:00:00 2001 From: dixpac Date: Thu, 3 Aug 2017 12:34:20 +0200 Subject: Remove unecesarry exception variable --- activestorage/lib/active_storage/service/azure_storage_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activestorage/lib/active_storage/service/azure_storage_service.rb b/activestorage/lib/active_storage/service/azure_storage_service.rb index 527dc57eeb..e13b32eb98 100644 --- a/activestorage/lib/active_storage/service/azure_storage_service.rb +++ b/activestorage/lib/active_storage/service/azure_storage_service.rb @@ -19,7 +19,7 @@ class ActiveStorage::Service::AzureStorageService < ActiveStorage::Service 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 -- cgit v1.2.3 From 1ab1f8759607cae037522717594c02b6c7a7b168 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Fri, 4 Aug 2017 22:32:34 -0400 Subject: Check for `app.secrets.secret_key_base`, not `app.config.secret_key_base` By default, apps only have the former set. --- activestorage/lib/active_storage/engine.rb | 2 +- railties/test/application/configuration_test.rb | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) 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/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 381bc2694f..c2f6a5a95c 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -453,10 +453,8 @@ module ApplicationTests secret_key_base: 123 YAML - app "development" - assert_raise(ArgumentError) do - app.key_generator + app "development" end end -- cgit v1.2.3