From 091abfc9445ff2a508df4dfc0011cc53d094eae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 27 Jul 2021 20:48:33 +0200 Subject: [PATCH] Use Active Storage to render attachments This way we fix a bug we mentioned in commit 930bb753c which caused links to documents to be broken when editing their title because the title was used to generate the URL of the document. Note we're still using Paperclip to render cached attachments because this is the only case where we store files with just Paperclip and not Active Storage. With Active Storage, we render attachments just like any other resource, using `polymorphic_path`. Paperclip included the `url` method in the model; since the model doesn't have access to the request parameters (like the host), this was inconvenient because it wasn't possible to generate absolute URLs with Paperclip. In order to simplify the code and make it similar to the way we used Paperclip, we're adding a `variant` method accepting the name of a variant and returning the variant. --- Gemfile | 1 + Gemfile.lock | 2 ++ .../admin/widget/cards/row_component.html.erb | 2 +- .../attachable/fields_component.html.erb | 2 +- app/components/attachable/fields_component.rb | 2 +- .../budgets/budget_component.html.erb | 2 +- .../budgets/investment_component.html.erb | 2 +- .../budgets/phases_component.html.erb | 2 +- .../widget/feeds/proposal_component.html.erb | 2 +- app/helpers/documents_helper.rb | 2 +- app/helpers/images_helper.rb | 11 ++++------ app/helpers/welcome_helper.rb | 5 +++-- app/models/concerns/imageable.rb | 4 ---- app/models/image.rb | 16 +++++++++++++++ .../admin/milestones/_milestones.html.erb | 4 ++-- .../poll/questions/answers/documents.html.erb | 4 ++-- .../documents/index.html.erb | 6 +++--- app/views/budgets/executions/_image.html.erb | 4 ++-- .../budgets/investments/_investment.html.erb | 2 +- .../investments/_investment_show.html.erb | 4 ++-- app/views/dashboard/_document.html.erb | 2 +- app/views/dashboard/mailer/forward.html.erb | 2 +- app/views/dashboard/mailing/index.html.erb | 2 +- app/views/dashboard/poster/index.html.erb | 2 +- app/views/dashboard/poster/index.pdf.erb | 2 +- app/views/documents/_document.html.erb | 2 +- app/views/images/_image.html.erb | 2 +- .../legislation/processes/_header.html.erb | 2 +- .../legislation/proposals/_proposal.html.erb | 2 +- app/views/milestones/_milestone.html.erb | 4 ++-- app/views/polls/_gallery.html.erb | 4 ++-- app/views/polls/_poll_group.html.erb | 2 +- app/views/polls/show.html.erb | 2 +- app/views/proposals/_proposal.html.erb | 2 +- app/views/proposals/show.html.erb | 4 ++-- app/views/shared/_card.html.erb | 2 +- app/views/shared/_header.html.erb | 2 +- spec/shared/system/nested_documentable.rb | 20 +++++++++++++++++++ .../site_customization/documents_spec.rb | 4 ++-- 39 files changed, 88 insertions(+), 55 deletions(-) diff --git a/Gemfile b/Gemfile index f71cb950b..28833049f 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,7 @@ gem "jquery-fileupload-rails" gem "jquery-rails", "~> 4.4.0" gem "jquery-ui-rails", "~> 6.0.1" gem "kaminari", "~> 1.2.1" +gem "mini_magick", "~> 4.11.0" gem "omniauth", "~> 2.0.4" gem "omniauth-facebook", "~> 8.0.0" gem "omniauth-google-oauth2", "~> 1.0.0" diff --git a/Gemfile.lock b/Gemfile.lock index dd0425134..1ea2c5adb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -373,6 +373,7 @@ GEM mimemagic (0.3.10) nokogiri (~> 1) rake + mini_magick (4.11.0) mini_mime (1.1.0) mini_portile2 (2.6.1) minitest (5.14.4) @@ -742,6 +743,7 @@ DEPENDENCIES launchy (~> 2.5.0) letter_opener_web (~> 1.4.0) mdl (~> 0.11.0) + mini_magick (~> 4.11.0) omniauth (~> 2.0.4) omniauth-facebook (~> 8.0.0) omniauth-google-oauth2 (~> 1.0.0) diff --git a/app/components/admin/widget/cards/row_component.html.erb b/app/components/admin/widget/cards/row_component.html.erb index 974753dc8..c66b28708 100644 --- a/app/components/admin/widget/cards/row_component.html.erb +++ b/app/components/admin/widget/cards/row_component.html.erb @@ -12,7 +12,7 @@ <% if card.image.present? %> - <%= link_to t("admin.shared.show_image"), card.image_url(:large), + <%= link_to t("admin.shared.show_image"), card.image.variant(:large), title: card.image.title, target: "_blank" %> <% end %> diff --git a/app/components/attachable/fields_component.html.erb b/app/components/attachable/fields_component.html.erb index ef329a31e..54f91cb2a 100644 --- a/app/components/attachable/fields_component.html.erb +++ b/app/components/attachable/fields_component.html.erb @@ -7,7 +7,7 @@ <%= f.text_field :title, placeholder: t("#{plural_name}.form.title_placeholder") %> - <% if attachable.attachment.exists? && attachable.attachment.styles.keys.include?(:thumb) %> + <% if attachable.storage_attachment.attached? && attachable.storage_attachment.image? %> <%= render_image(attachable, :thumb, false) %> <% end %> diff --git a/app/components/attachable/fields_component.rb b/app/components/attachable/fields_component.rb index ae217456a..fac93f7be 100644 --- a/app/components/attachable/fields_component.rb +++ b/app/components/attachable/fields_component.rb @@ -24,7 +24,7 @@ class Attachable::FieldsComponent < ApplicationComponent end def file_name - attachable.attachment_file_name + attachable.storage_attachment.filename if attachable.storage_attachment.attached? end def destroy_link diff --git a/app/components/budgets/budget_component.html.erb b/app/components/budgets/budget_component.html.erb index 7ba34034a..232d5da75 100644 --- a/app/components/budgets/budget_component.html.erb +++ b/app/components/budgets/budget_component.html.erb @@ -1,6 +1,6 @@ <% if budget.image.present? %>
+ style="background-image: url(<%= polymorphic_path(budget.image.variant(:large)) %>);"> <% else %>
<% end %> diff --git a/app/components/budgets/investment_component.html.erb b/app/components/budgets/investment_component.html.erb index 4ca171959..1b05e2c9b 100644 --- a/app/components/budgets/investment_component.html.erb +++ b/app/components/budgets/investment_component.html.erb @@ -1,6 +1,6 @@
<% if investment.image.present? %> - <%= image_tag investment.image_url(:large), alt: investment.image.title.unicode_normalize %> + <%= image_tag investment.image.variant(:large), alt: investment.image.title.unicode_normalize %> <% else %> <%= image_tag "budget_investment_no_image.jpg", alt: investment.title %> <% end %> diff --git a/app/components/budgets/phases_component.html.erb b/app/components/budgets/phases_component.html.erb index 8c881a4f1..b7921f712 100644 --- a/app/components/budgets/phases_component.html.erb +++ b/app/components/budgets/phases_component.html.erb @@ -55,7 +55,7 @@ <% if phase.image.present? %>
- <%= image_tag phase.image.attachment.url(:large), alt: "" %> + <%= image_tag phase.image.variant(:large), alt: "" %>
<% end %>
diff --git a/app/components/widget/feeds/proposal_component.html.erb b/app/components/widget/feeds/proposal_component.html.erb index 8f683776a..b9bbc83c8 100644 --- a/app/components/widget/feeds/proposal_component.html.erb +++ b/app/components/widget/feeds/proposal_component.html.erb @@ -9,7 +9,7 @@ <% if proposal.image.present? %>
- <%= image_tag proposal.image_url(:thumb), + <%= image_tag proposal.image.variant(:thumb), alt: proposal.image.title.unicode_normalize %>
diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index 3ff564a03..742a88acf 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -3,7 +3,7 @@ module DocumentsHelper info_text = "#{document.humanized_content_type} | #{number_to_human_size(document.attachment_file_size)}" link_to safe_join([document.title, tag.small("(#{info_text})")], " "), - document.attachment.url, + document.storage_attachment, target: "_blank", title: t("shared.target_blank") end diff --git a/app/helpers/images_helper.rb b/app/helpers/images_helper.rb index 0f64a9bc2..06d63e9f8 100644 --- a/app/helpers/images_helper.rb +++ b/app/helpers/images_helper.rb @@ -2,11 +2,7 @@ module ImagesHelper def image_absolute_url(image, version) return "" unless image - if Paperclip::Attachment.default_options[:storage] == :filesystem - URI(request.url) + image.attachment.url(version) - else - image.attachment.url(version) - end + polymorphic_url(image.variant(version)) end def image_class(image) @@ -14,7 +10,8 @@ module ImagesHelper end def render_image(image, version, show_caption = true) - version = image.persisted? ? version : :original - render "images/image", image: image, version: version, show_caption: show_caption + render "images/image", image: image, + version: (version if image.persisted?), + show_caption: show_caption end end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 5962ff682..0f26b3a73 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -24,8 +24,9 @@ module WelcomeHelper end def calculate_image_path(recommended, image_default) - if recommended.respond_to?(:image) && recommended.image.present? && recommended.image.attachment.exists? - recommended.image.attachment.send("url", :medium) + if recommended.respond_to?(:image) && recommended.image.present? && + recommended.image.storage_attachment.attached? + recommended.image.variant(:medium) elsif image_default.present? image_default end diff --git a/app/models/concerns/imageable.rb b/app/models/concerns/imageable.rb index fffc871de..ad4630a6c 100644 --- a/app/models/concerns/imageable.rb +++ b/app/models/concerns/imageable.rb @@ -4,9 +4,5 @@ module Imageable included do has_one :image, as: :imageable, inverse_of: :imageable, dependent: :destroy accepts_nested_attributes_for :image, allow_destroy: true, update_only: true - - def image_url(style) - image&.attachment&.url(style) || "" - end end end diff --git a/app/models/image.rb b/app/models/image.rb index de1405f2b..a86091648 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -11,6 +11,14 @@ class Image < ApplicationRecord use_timestamp: false, hash_secret: Rails.application.secrets.secret_key_base + def self.styles + { + large: { resize: "x#{Setting["uploads.images.min_height"]}" }, + medium: { combine_options: { gravity: "center", resize: "300x300^", crop: "300x300+0+0" }}, + thumb: { combine_options: { gravity: "center", resize: "140x245^", crop: "140x245+0+0" }} + } + end + belongs_to :user belongs_to :imageable, polymorphic: true, touch: true @@ -41,6 +49,14 @@ class Image < ApplicationRecord self.class.accepted_content_types end + def variant(style) + if style + storage_attachment.variant(self.class.styles[style]) + else + storage_attachment + end + end + private def association_name diff --git a/app/views/admin/milestones/_milestones.html.erb b/app/views/admin/milestones/_milestones.html.erb index 14e99f1b2..ac4d599a8 100644 --- a/app/views/admin/milestones/_milestones.html.erb +++ b/app/views/admin/milestones/_milestones.html.erb @@ -40,14 +40,14 @@ <%= link_to t("admin.milestones.index.show_image"), - milestone.image_url(:large), + milestone.image.variant(:large), target: :_blank if milestone.image.present? %> <% if milestone.documents.present? %> <% milestone.documents.each do |document| %> <%= link_to document.title, - document.attachment.url, + document.storage_attachment, target: "_blank", rel: "nofollow" %>
<% end %> diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 53d78996a..c322bcdaa 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -33,7 +33,7 @@ <% @answer.documents.each do |document| %> - <%= link_to document.title, document.attachment.url %> + <%= link_to document.title, document.storage_attachment %> <%= render Admin::TableActionsComponent.new(document, @@ -42,7 +42,7 @@ ) do |actions| %> <%= actions.action(:download, text: t("documents.buttons.download_document"), - path: document.attachment.url, + path: document.storage_attachment, target: "_blank", rel: "nofollow") %> diff --git a/app/views/admin/site_customization/documents/index.html.erb b/app/views/admin/site_customization/documents/index.html.erb index 491d9e069..f7a8e6409 100644 --- a/app/views/admin/site_customization/documents/index.html.erb +++ b/app/views/admin/site_customization/documents/index.html.erb @@ -21,9 +21,9 @@ <% @documents.each do |document| %> <%= document.title %> - <%= document.attachment.content_type %> - <%= number_to_human_size(document.attachment.size) %> - <%= link_to document.title, document.attachment.url, target: :blank %> + <%= document.storage_attachment.content_type %> + <%= number_to_human_size(document.storage_attachment.byte_size) %> + <%= link_to document.title, document.storage_attachment, target: :blank %>
<%= render Admin::TableActionsComponent.new( diff --git a/app/views/budgets/executions/_image.html.erb b/app/views/budgets/executions/_image.html.erb index 639761875..ebe933504 100644 --- a/app/views/budgets/executions/_image.html.erb +++ b/app/views/budgets/executions/_image.html.erb @@ -1,9 +1,9 @@ <% milestone = first_milestone_with_image(investment) %> <% if milestone&.image.present? %> - <%= image_tag milestone.image_url(:large), alt: milestone.image.title %> + <%= image_tag milestone.image.variant(:large), alt: milestone.image.title %> <% elsif investment.image.present? %> - <%= image_tag investment.image_url(:large), alt: investment.image.title %> + <%= image_tag investment.image.variant(:large), alt: investment.image.title %> <% else %> <%= image_tag "budget_execution_no_image.jpg", alt: investment.title %> <% end %> diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index fea6b4241..1a4009952 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -5,7 +5,7 @@
- <%= image_tag investment.image_url(:thumb), alt: investment.image.title.unicode_normalize %> + <%= image_tag investment.image.variant(:thumb), alt: investment.image.title.unicode_normalize %>
diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 2b31e476f..d7a46cf51 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -3,8 +3,8 @@ social_url: budget_investments_path(investment), social_title: investment.title, social_description: investment.description, - twitter_image_url: (investment.image.present? ? investment.image_url(:thumb) : nil), - og_image_url: (investment.image.present? ? investment.image_url(:thumb) : nil) %> + twitter_image_url: (investment.image.present? ? polymorphic_path(investment.image.variant(:thumb)) : nil), + og_image_url: (investment.image.present? ? polymorphic_path(investment.image.variant(:thumb)) : nil) %> <% end %> <% cache [locale_and_user_status(investment), diff --git a/app/views/dashboard/_document.html.erb b/app/views/dashboard/_document.html.erb index 0b61002a2..e91efb98b 100644 --- a/app/views/dashboard/_document.html.erb +++ b/app/views/dashboard/_document.html.erb @@ -1,5 +1,5 @@

- <%= link_to document.attachment.url, target: "_blank" do %> + <%= link_to document.storage_attachment, target: "_blank" do %> <%= document.title %> (<%= document.humanized_content_type %>  |  diff --git a/app/views/dashboard/mailer/forward.html.erb b/app/views/dashboard/mailer/forward.html.erb index f3f25fe12..95cea001c 100644 --- a/app/views/dashboard/mailer/forward.html.erb +++ b/app/views/dashboard/mailer/forward.html.erb @@ -15,7 +15,7 @@ <% if @proposal.image.present? %> - <%= image_tag @proposal.image.attachment.url(:large), style: "width: 100%; box-shadow: -16px 61px 49px -19px rgba(0,0,0,0.1);" %> + <%= image_tag @proposal.image.variant(:large), style: "width: 100%; box-shadow: -16px 61px 49px -19px rgba(0,0,0,0.1);" %> <% else %> <%= image_tag "default_mailing.jpg", style: "width: 100%; box-shadow: -16px 61px 49px -19px rgba(0,0,0,0.1);" %> <% end %> diff --git a/app/views/dashboard/mailing/index.html.erb b/app/views/dashboard/mailing/index.html.erb index 1886d07c8..bf1f01fb9 100644 --- a/app/views/dashboard/mailing/index.html.erb +++ b/app/views/dashboard/mailing/index.html.erb @@ -9,7 +9,7 @@

- <%= image_tag(proposal.image_url(:large).presence || "default_mailing.jpg") %> + <%= image_tag(proposal.image&.variant(:large).presence || "default_mailing.jpg") %>
diff --git a/app/views/dashboard/poster/index.html.erb b/app/views/dashboard/poster/index.html.erb index 7cdfb2faa..e1cddb5d4 100644 --- a/app/views/dashboard/poster/index.html.erb +++ b/app/views/dashboard/poster/index.html.erb @@ -18,7 +18,7 @@

<% if proposal.image.present? %> -
+
<% else %>
);">
<% end %> diff --git a/app/views/dashboard/poster/index.pdf.erb b/app/views/dashboard/poster/index.pdf.erb index c1ba4ea78..c762156d2 100644 --- a/app/views/dashboard/poster/index.pdf.erb +++ b/app/views/dashboard/poster/index.pdf.erb @@ -23,7 +23,7 @@

<% if proposal.image.present? %> -
+
<% else %>
');">
<% end %> diff --git a/app/views/documents/_document.html.erb b/app/views/documents/_document.html.erb index 07d31e026..67c61216b 100644 --- a/app/views/documents/_document.html.erb +++ b/app/views/documents/_document.html.erb @@ -1,6 +1,6 @@
  • <%= link_to t("documents.buttons.download_document"), - document.attachment.url, target: "_blank", + document.storage_attachment, target: "_blank", rel: "nofollow", class: "button hollow medium float-right" %> <%= document.title %> diff --git a/app/views/images/_image.html.erb b/app/views/images/_image.html.erb index 65ef9324e..7cb5feb68 100644 --- a/app/views/images/_image.html.erb +++ b/app/views/images/_image.html.erb @@ -1,6 +1,6 @@
    - <%= image_tag image.attachment.url(version), + <%= image_tag image.variant(version), class: image_class(image), alt: image.title.unicode_normalize, title: image.title.unicode_normalize %> diff --git a/app/views/legislation/processes/_header.html.erb b/app/views/legislation/processes/_header.html.erb index 8917176e5..eb05108a5 100644 --- a/app/views/legislation/processes/_header.html.erb +++ b/app/views/legislation/processes/_header.html.erb @@ -45,7 +45,7 @@ <% if @process.image.present? %>
    - <%= image_tag(@process.image_url(:large), alt: @process.title, id: "image") %> + <%= image_tag(@process.image.variant(:large), alt: @process.title, id: "image") %> <% end %> <% if process.draft_publication.enabled? %> diff --git a/app/views/legislation/proposals/_proposal.html.erb b/app/views/legislation/proposals/_proposal.html.erb index ad3770683..0142be99c 100644 --- a/app/views/legislation/proposals/_proposal.html.erb +++ b/app/views/legislation/proposals/_proposal.html.erb @@ -7,7 +7,7 @@ <% if proposal.image.present? %>
    - <%= image_tag proposal.image_url(:thumb), + <%= image_tag proposal.image.variant(:thumb), alt: proposal.image.title.unicode_normalize %>
    diff --git a/app/views/milestones/_milestone.html.erb b/app/views/milestones/_milestone.html.erb index 6de305b85..ce8ea12bc 100644 --- a/app/views/milestones/_milestone.html.erb +++ b/app/views/milestones/_milestone.html.erb @@ -22,7 +22,7 @@

    <% end %> - <%= image_tag(milestone.image_url(:large), { id: "image_#{milestone.id}", alt: milestone.image.title, class: "margin" }) if milestone.image.present? %> + <%= image_tag(milestone.image.variant(:large), { id: "image_#{milestone.id}", alt: milestone.image.title, class: "margin" }) if milestone.image.present? %>

    <%= sanitize_and_auto_link milestone.description %> @@ -37,7 +37,7 @@ <% milestone.documents.each do |document| %> <%= link_to document.title, - document.attachment.url, + document.storage_attachment, target: "_blank", rel: "nofollow" %>
    diff --git a/app/views/polls/_gallery.html.erb b/app/views/polls/_gallery.html.erb index f62f28831..e62827908 100644 --- a/app/views/polls/_gallery.html.erb +++ b/app/views/polls/_gallery.html.erb @@ -18,8 +18,8 @@ <% answer.images.reverse.each_with_index do |image, index| %>

  • - <%= link_to image.attachment.url(:original), target: "_blank" do %> - <%= image_tag image.attachment.url(:original), + <%= link_to image.storage_attachment, target: "_blank" do %> + <%= image_tag image.storage_attachment, class: "orbit-image", alt: image.title.unicode_normalize %> <% end %> diff --git a/app/views/polls/_poll_group.html.erb b/app/views/polls/_poll_group.html.erb index 3a4d66296..58268e21b 100644 --- a/app/views/polls/_poll_group.html.erb +++ b/app/views/polls/_poll_group.html.erb @@ -23,7 +23,7 @@
    <% if poll.image.present? %> - <%= image_tag poll.image_url(:large), alt: poll.image.title.unicode_normalize %> + <%= image_tag poll.image.variant(:large), alt: poll.image.title.unicode_normalize %> <% end %>
    diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index ebc55daa7..69272441a 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -86,7 +86,7 @@ <% answer.documents.each do |document| %> <%= link_to document.title, - document.attachment.url, + document.storage_attachment, target: "_blank", rel: "nofollow" %>
    <% end %> diff --git a/app/views/proposals/_proposal.html.erb b/app/views/proposals/_proposal.html.erb index 733e3adf2..0b3c8ec33 100644 --- a/app/views/proposals/_proposal.html.erb +++ b/app/views/proposals/_proposal.html.erb @@ -8,7 +8,7 @@ <% if proposal.image.present? %>
    - <%= image_tag proposal.image_url(:thumb), + <%= image_tag proposal.image.variant(:thumb), alt: proposal.image.title.unicode_normalize %>
    diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 15f52d8c7..02dc1c38c 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -6,8 +6,8 @@ social_url: proposal_url(@proposal), social_title: @proposal.title, social_description: @proposal.summary, - twitter_image_url: (@proposal.image.present? ? @proposal.image_url(:thumb) : nil), - og_image_url: (@proposal.image.present? ? @proposal.image_url(:thumb) : nil) %> + twitter_image_url: (@proposal.image.present? ? polymorphic_path(@proposal.image.variant(:thumb)) : nil), + og_image_url: (@proposal.image.present? ? polymorphic_path(@proposal.image.variant(:thumb)) : nil) %> <% end %> <% content_for :canonical do %> <%= render "shared/canonical", href: proposal_url(@proposal) %> diff --git a/app/views/shared/_card.html.erb b/app/views/shared/_card.html.erb index 4e6c1e459..8a591d4f4 100644 --- a/app/views/shared/_card.html.erb +++ b/app/views/shared/_card.html.erb @@ -4,7 +4,7 @@
    <% if card.image.present? %> - <%= image_tag(card.image_url(:large), alt: card.image.title) %> + <%= image_tag(card.image.variant(:large), alt: card.image.title) %> <% end %>
    <% if card.label.present? %> diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index 06e0fbc54..9eec4fc3f 100644 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -16,7 +16,7 @@ <% if header.image.present? %>
    - <%= image_tag(header.image_url(:large), + <%= image_tag(header.image.variant(:large), class: "margin", alt: header.image.title) %>
    diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb index cb3d0d6bb..da0a72b0a 100644 --- a/spec/shared/system/nested_documentable.rb +++ b/spec/shared/system/nested_documentable.rb @@ -279,6 +279,26 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na expect(page).not_to have_css ".document" end + + scenario "Same attachment URL after editing the title" do + do_login_for user_to_login + + visit send(path, arguments) + documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) + within_fieldset("Documents") { fill_in "Title", with: "Original" } + click_button submit_button + + expect(page).to have_content documentable_success_notice + + original_url = find_link("Download file")[:href] + + visit send(path, arguments) + within_fieldset("Documents") { fill_in "Title", with: "Updated" } + click_button submit_button + + expect(page).to have_content documentable_success_notice + expect(find_link("Download file")[:href]).to eq original_url + end end describe "When allow attached documents setting is disabled" do diff --git a/spec/system/admin/site_customization/documents_spec.rb b/spec/system/admin/site_customization/documents_spec.rb index f0ff988d9..fe2fe332a 100644 --- a/spec/system/admin/site_customization/documents_spec.rb +++ b/spec/system/admin/site_customization/documents_spec.rb @@ -18,12 +18,12 @@ describe "Documents", :admin do 1.times { create(:document) } document = Document.first - attachment = document.attachment + url = polymorphic_path(document.storage_attachment) visit admin_site_customization_documents_path expect(page).to have_content "There are 3 documents" - expect(page).to have_link document.title, href: attachment.url + expect(page).to have_link document.title, href: url end scenario "Index (empty)" do