<%= f.submit(class: "button expanded", value: t("shared.save")) %>
@@ -36,7 +34,7 @@
<% documents.each do |document| %>
|
- <%= link_to document.title, document.attachment %>
+ <%= document.title %>
|
<%= render Admin::Poll::Questions::Answers::Documents::TableActionsComponent.new(document) %>
diff --git a/app/components/admin/poll/questions/answers/documents/table_actions_component.html.erb b/app/components/admin/poll/questions/answers/documents/table_actions_component.html.erb
index 19e8e3ac2..37f978cdf 100644
--- a/app/components/admin/poll/questions/answers/documents/table_actions_component.html.erb
+++ b/app/components/admin/poll/questions/answers/documents/table_actions_component.html.erb
@@ -3,6 +3,5 @@
<%= actions.action(:download,
text: t("documents.buttons.download_document"),
path: document.attachment,
- target: "_blank",
rel: "nofollow") %>
<% end %>
diff --git a/app/components/attachable/fields_component.html.erb b/app/components/attachable/fields_component.html.erb
index e5e9854a6..d51997e53 100644
--- a/app/components/attachable/fields_component.html.erb
+++ b/app/components/attachable/fields_component.html.erb
@@ -1,4 +1,4 @@
-
+
<%= f.hidden_field :id %>
<%= f.hidden_field :user_id, value: current_user.id %>
<%= f.hidden_field :cached_attachment %>
diff --git a/app/components/budgets/investments/form_component.html.erb b/app/components/budgets/investments/form_component.html.erb
index daa0aec4a..228aec322 100644
--- a/app/components/budgets/investments/form_component.html.erb
+++ b/app/components/budgets/investments/form_component.html.erb
@@ -37,15 +37,11 @@
<% if feature?(:allow_images) %>
-
- <%= render "images/nested_image", f: f %>
-
+ <%= render Images::NestedComponent.new(f) %>
<% end %>
<% if feature?(:allow_attached_documents) %>
-
- <%= render "documents/nested_documents", f: f %>
-
+ <%= render Documents::NestedComponent.new(f) %>
<% end %>
<% if feature?(:map) %>
diff --git a/app/components/documents/document_component.html.erb b/app/components/documents/document_component.html.erb
new file mode 100644
index 000000000..1de910081
--- /dev/null
+++ b/app/components/documents/document_component.html.erb
@@ -0,0 +1,17 @@
+
+ <%= link_to document.attachment, rel: "nofollow" do %>
+ <%= document.title %>
+
+ <%= document.humanized_content_type %>
+ <%= number_to_human_size(document.attachment_file_size, precision: 2) %>
+
+ <% end %>
+
+ <% if show_destroy_link? && can?(:destroy, document) %>
+ <%= link_to t("documents.buttons.destroy_document"),
+ document,
+ method: :delete,
+ data: { confirm: t("documents.actions.destroy.confirm") },
+ class: "delete" %>
+ <% end %>
+
diff --git a/app/components/documents/document_component.rb b/app/components/documents/document_component.rb
new file mode 100644
index 000000000..8f5c7f68a
--- /dev/null
+++ b/app/components/documents/document_component.rb
@@ -0,0 +1,10 @@
+class Documents::DocumentComponent < ApplicationComponent
+ attr_reader :document, :show_destroy_link
+ alias_method :show_destroy_link?, :show_destroy_link
+ delegate :can?, to: :helpers
+
+ def initialize(document, show_destroy_link: false)
+ @document = document
+ @show_destroy_link = show_destroy_link
+ end
+end
diff --git a/app/components/documents/documents_component.html.erb b/app/components/documents/documents_component.html.erb
new file mode 100644
index 000000000..ae30e464c
--- /dev/null
+++ b/app/components/documents/documents_component.html.erb
@@ -0,0 +1,11 @@
+
+ <%= t("documents.title") %> (<%= documents.count %>)
+
+
+ <% documents.each do |document| %>
+ -
+ <%= render Documents::DocumentComponent.new(document, show_destroy_link: true) %>
+
+ <% end %>
+
+
diff --git a/app/components/documents/documents_component.rb b/app/components/documents/documents_component.rb
new file mode 100644
index 000000000..5dfae9ecf
--- /dev/null
+++ b/app/components/documents/documents_component.rb
@@ -0,0 +1,11 @@
+class Documents::DocumentsComponent < ApplicationComponent
+ attr_reader :documents
+
+ def initialize(documents)
+ @documents = documents
+ end
+
+ def render?
+ documents.any?
+ end
+end
diff --git a/app/components/documents/nested_component.html.erb b/app/components/documents/nested_component.html.erb
index 743cd7be3..8d3bc2c63 100644
--- a/app/components/documents/nested_component.html.erb
+++ b/app/components/documents/nested_component.html.erb
@@ -1,4 +1,4 @@
-
<% if feature?(:allow_images) %>
-
- <%= render "images/nested_image", f: f %>
-
+ <%= render Images::NestedComponent.new(f) %>
<% end %>
<% if feature?(:allow_attached_documents) %>
-
- <%= render "documents/nested_documents", f: f %>
-
+ <%= render Documents::NestedComponent.new(f) %>
<% end %>
<% if Geozone.any? %>
diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb
deleted file mode 100644
index 9110e45b8..000000000
--- a/app/helpers/documents_helper.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-module DocumentsHelper
- def document_item_link(document)
- 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,
- target: "_blank",
- title: t("shared.target_blank")
- end
-end
diff --git a/app/views/admin/dashboard/actions/_form.html.erb b/app/views/admin/dashboard/actions/_form.html.erb
index d98bd9501..3dd147172 100644
--- a/app/views/admin/dashboard/actions/_form.html.erb
+++ b/app/views/admin/dashboard/actions/_form.html.erb
@@ -64,16 +64,13 @@
<% if feature?(:allow_attached_documents) %>
-
-
- <%= render "documents/nested_documents", f: f %>
-
+
+ <%= render Documents::NestedComponent.new(f) %>
<% end %>
<%= render "links/nested_links", linkable: dashboard_action, f: f %>
-
diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb
index 3094d4ccd..0f461bfd7 100644
--- a/app/views/admin/legislation/processes/_form.html.erb
+++ b/app/views/admin/legislation/processes/_form.html.erb
@@ -109,20 +109,12 @@
-
- <%= render "documents/nested_documents", f: f %>
+
+ <%= render Documents::NestedComponent.new(f) %>
-
-
-
-
- <%= render "images/nested_image", f: f %>
-
-
-
-
+ <%= render Images::NestedComponent.new(f) %>
@@ -154,10 +146,6 @@
-
-
-
-
diff --git a/app/views/admin/milestones/_form.html.erb b/app/views/admin/milestones/_form.html.erb
index 7198f1c93..2d7d6b2a1 100644
--- a/app/views/admin/milestones/_form.html.erb
+++ b/app/views/admin/milestones/_form.html.erb
@@ -27,11 +27,8 @@
<%= f.date_field :publication_date %>
- <%= render "images/nested_image", f: f %>
-
-
- <%= render "documents/nested_documents", f: f %>
-
+ <%= render Images::NestedComponent.new(f) %>
+ <%= render Documents::NestedComponent.new(f) %>
<%= f.submit nil, class: "button success" %>
diff --git a/app/views/admin/milestones/_milestones.html.erb b/app/views/admin/milestones/_milestones.html.erb
index 46940ab88..2a02ea6d8 100644
--- a/app/views/admin/milestones/_milestones.html.erb
+++ b/app/views/admin/milestones/_milestones.html.erb
@@ -48,7 +48,6 @@
<% milestone.documents.each do |document| %>
<%= link_to document.title,
document.attachment,
- target: "_blank",
rel: "nofollow" %>
<% end %>
<% end %>
diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb
index dd0b59292..332011a20 100644
--- a/app/views/admin/poll/polls/_form.html.erb
+++ b/app/views/admin/poll/polls/_form.html.erb
@@ -32,8 +32,8 @@
-
- <%= render "images/nested_image", f: f %>
+
+ <%= render Images::NestedComponent.new(f) %>
diff --git a/app/views/admin/poll/questions/answers/images/new.html.erb b/app/views/admin/poll/questions/answers/images/new.html.erb
index e4ddaa769..3c85c0b57 100644
--- a/app/views/admin/poll/questions/answers/images/new.html.erb
+++ b/app/views/admin/poll/questions/answers/images/new.html.erb
@@ -2,9 +2,7 @@
<%= form_for(@answer, url: admin_answer_images_path(@answer), method: :post) do |f| %>
<%= render "shared/errors", resource: @answer %>
-
- <%= render Images::NestedComponent.new(f, image_fields: :images) %>
-
+ <%= render Images::NestedComponent.new(f, image_fields: :images) %>
<%= f.submit t("admin.questions.answers.images.save_image"), class: "button success" %>
<% end %>
diff --git a/app/views/admin/site_customization/documents/index.html.erb b/app/views/admin/site_customization/documents/index.html.erb
index 4f3f93497..b3f4ca635 100644
--- a/app/views/admin/site_customization/documents/index.html.erb
+++ b/app/views/admin/site_customization/documents/index.html.erb
@@ -13,25 +13,26 @@
<%= t("admin.shared.title") %> |
<%= t("admin.documents.index.format") %> |
<%= t("admin.documents.index.size") %> |
- <%= t("admin.documents.index.url") %> |
<%= t("admin.shared.actions") %> |
|
<% @documents.each do |document| %>
-
+
| <%= document.title %> |
<%= document.attachment.content_type %> |
<%= number_to_human_size(document.attachment.byte_size) %> |
- <%= link_to document.title, document.attachment, target: :blank %> |
-
- <%= render Admin::TableActionsComponent.new(
- document,
- actions: [:destroy],
- destroy_path: admin_site_customization_document_path(document)
- ) %>
-
+ <%= render Admin::TableActionsComponent.new(
+ document,
+ actions: [:destroy],
+ destroy_path: admin_site_customization_document_path(document)
+ ) do |actions| %>
+ <%= actions.action(:download,
+ text: t("documents.buttons.download_document"),
+ path: document.attachment,
+ rel: "nofollow") %>
+ <% end %>
|
<% end %>
diff --git a/app/views/admin/widget/cards/_form.html.erb b/app/views/admin/widget/cards/_form.html.erb
index 606697f4d..d01dc0cc1 100644
--- a/app/views/admin/widget/cards/_form.html.erb
+++ b/app/views/admin/widget/cards/_form.html.erb
@@ -45,7 +45,7 @@
diff --git a/app/views/budgets/investments/_investment_detail.html.erb b/app/views/budgets/investments/_investment_detail.html.erb
index 626cabf8f..d8c8fff8f 100644
--- a/app/views/budgets/investments/_investment_detail.html.erb
+++ b/app/views/budgets/investments/_investment_detail.html.erb
@@ -45,15 +45,13 @@
<% end %>
<% if feature?(:allow_attached_documents) %>
- <%= render "documents/documents",
- documents: investment.documents,
- max_documents_allowed: Budget::Investment.max_documents_allowed %>
+ <%= render Documents::DocumentsComponent.new(investment.documents) %>
<% end %>
<%= render "shared/tags", taggable: investment %>
<% if investment.external_url.present? %>
-
+
<%= sanitize_and_auto_link investment.external_url %>
<% end %>
diff --git a/app/views/dashboard/_document.html.erb b/app/views/dashboard/_document.html.erb
deleted file mode 100644
index d59177a30..000000000
--- a/app/views/dashboard/_document.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-
- <%= link_to document.attachment, target: "_blank" do %>
- <%= document.title %>
- (<%= document.humanized_content_type %>
- |
- <%= number_to_human_size(document.attachment_file_size, precision: 2) %>)
- <% end %>
-
diff --git a/app/views/dashboard/_proposed_action.html.erb b/app/views/dashboard/_proposed_action.html.erb
index 12fa5b451..a19a047e1 100644
--- a/app/views/dashboard/_proposed_action.html.erb
+++ b/app/views/dashboard/_proposed_action.html.erb
@@ -49,7 +49,9 @@
<%= link_to link.label, link.url, target: "_blank" %>
<% end %>
- <%= render partial: "document", collection: proposed_action.documents %>
+ <% proposed_action.documents.each do |document| %>
+ <%= render Documents::DocumentComponent.new(document) %>
+ <% end %>
diff --git a/app/views/dashboard/actions/new_request.html.erb b/app/views/dashboard/actions/new_request.html.erb
index 4359f17c8..93549ec36 100644
--- a/app/views/dashboard/actions/new_request.html.erb
+++ b/app/views/dashboard/actions/new_request.html.erb
@@ -7,7 +7,7 @@
- <%= render "documents/documents", documents: dashboard_action.documents %>
+ <%= render Documents::DocumentsComponent.new(dashboard_action.documents) %>
<% if dashboard_action.links.any? %>
diff --git a/app/views/dashboard/poster/_poster_options.html.erb b/app/views/dashboard/poster/_poster_options.html.erb
index 27e1cc1eb..f807d5954 100644
--- a/app/views/dashboard/poster/_poster_options.html.erb
+++ b/app/views/dashboard/poster/_poster_options.html.erb
@@ -7,6 +7,5 @@
<%= link_to t("dashboard.poster.options.download"),
proposal_dashboard_poster_index_path(proposal, format: :pdf),
- target: "_blank",
class: "button expanded" %>
diff --git a/app/views/documents/_additional_document.html.erb b/app/views/documents/_additional_document.html.erb
deleted file mode 100644
index 8c079590e..000000000
--- a/app/views/documents/_additional_document.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
-<%= document_item_link(document) %>
-
diff --git a/app/views/documents/_additional_documents.html.erb b/app/views/documents/_additional_documents.html.erb
index b4b23a1a0..225147f4b 100644
--- a/app/views/documents/_additional_documents.html.erb
+++ b/app/views/documents/_additional_documents.html.erb
@@ -6,7 +6,9 @@
<%= t("documents.additional") %>
- <%= render partial: "documents/additional_document", collection: documents, as: :document %>
+ <% documents.each do |document| %>
+ <%= render Documents::DocumentComponent.new(document) %>
+ <% end %>
diff --git a/app/views/documents/_document.html.erb b/app/views/documents/_document.html.erb
deleted file mode 100644
index a2a244933..000000000
--- a/app/views/documents/_document.html.erb
+++ /dev/null
@@ -1,23 +0,0 @@
-
- <%= link_to t("documents.buttons.download_document"),
- document.attachment,
- target: "_blank",
- rel: "nofollow",
- class: "button hollow medium float-right" %>
-
- <%= document.title %>
-
-
- <%= document.humanized_content_type %> |
- <%= number_to_human_size(document.attachment_file_size, precision: 2) %>
-
-
- <% if can?(:destroy, document) %>
-
- <%= link_to t("documents.buttons.destroy_document"),
- document,
- method: :delete,
- data: { confirm: t("documents.actions.destroy.confirm") },
- class: "delete" %>
- <% end %>
-
diff --git a/app/views/documents/_documents.html.erb b/app/views/documents/_documents.html.erb
deleted file mode 100644
index a828ccc90..000000000
--- a/app/views/documents/_documents.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% if documents.any? %>
-
-
<%= t("documents.title") %> (<%= documents.count %>)
-
-
- <%= render partial: "documents/document", collection: documents %>
-
-
-<% end %>
diff --git a/app/views/documents/_nested_documents.html.erb b/app/views/documents/_nested_documents.html.erb
deleted file mode 100644
index 229840e83..000000000
--- a/app/views/documents/_nested_documents.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= render Documents::NestedComponent.new(f) %>
diff --git a/app/views/images/_nested_image.html.erb b/app/views/images/_nested_image.html.erb
deleted file mode 100644
index c55ccaa56..000000000
--- a/app/views/images/_nested_image.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= render Images::NestedComponent.new(f) %>
diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb
index 7fa3d3a4b..b1cf5d8b4 100644
--- a/app/views/legislation/proposals/_form.html.erb
+++ b/app/views/legislation/proposals/_form.html.erb
@@ -27,13 +27,13 @@
<% if feature?(:allow_images) %>
-
- <%= render "images/nested_image", f: f %>
+
+ <%= render Images::NestedComponent.new(f) %>
<% end %>
-
- <%= render "documents/nested_documents", f: f %>
+
+ <%= render Documents::NestedComponent.new(f) %>
<% if Geozone.any? %>
diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb
index 406e8fa36..7f9123bd4 100644
--- a/app/views/legislation/proposals/show.html.erb
+++ b/app/views/legislation/proposals/show.html.erb
@@ -87,9 +87,7 @@
<% end %>
<% if feature?(:allow_attached_documents) %>
- <%= render "documents/documents",
- documents: @proposal.documents,
- max_documents_allowed: Proposal.max_documents_allowed %>
+ <%= render Documents::DocumentsComponent.new(@proposal.documents) %>
<% end %>
<%= render "shared/tags", taggable: @proposal %>
diff --git a/app/views/milestones/_milestone.html.erb b/app/views/milestones/_milestone.html.erb
index 79b5fdf99..54371534a 100644
--- a/app/views/milestones/_milestone.html.erb
+++ b/app/views/milestones/_milestone.html.erb
@@ -36,15 +36,7 @@
<% milestone.documents.each do |document| %>
- <%= link_to document.title,
- document.attachment,
- target: "_blank",
- rel: "nofollow" %>
-
- <%= document.humanized_content_type %> |
- <%= number_to_human_size(document.attachment_file_size, precision: 2) %>
-
-
+ <%= render Documents::DocumentComponent.new(document) %>
<% end %>
diff --git a/app/views/proposals/_info.html.erb b/app/views/proposals/_info.html.erb
index ec5d2b866..23def8f68 100644
--- a/app/views/proposals/_info.html.erb
+++ b/app/views/proposals/_info.html.erb
@@ -67,9 +67,7 @@
<% end %>
<% if feature?(:allow_attached_documents) %>
- <%= render "documents/documents",
- documents: @proposal.documents,
- max_documents_allowed: Proposal.max_documents_allowed %>
+ <%= render Documents::DocumentsComponent.new(@proposal.documents) %>
<% end %>
<%= render "shared/tags", taggable: @proposal %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index c5589ba63..c111aa6af 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -539,7 +539,6 @@ en:
title: "Documents"
format: "Format"
size: "Size"
- url: "URL"
create:
success_notice: "Document uploaded successfully"
unable_notice: "Invalid document"
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 783f2c3ef..4bdd562f5 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -539,7 +539,6 @@ es:
title: "Documentos"
format: "Formato"
size: "Tamaño"
- url: "URL"
create:
success_notice: "Documento creado correctamente"
unable_notice: "Documento inválido"
diff --git a/db/migrate/20231012141318_remove_paperclip_columns.rb b/db/migrate/20231012141318_remove_paperclip_columns.rb
new file mode 100644
index 000000000..cd1daab4b
--- /dev/null
+++ b/db/migrate/20231012141318_remove_paperclip_columns.rb
@@ -0,0 +1,17 @@
+class RemovePaperclipColumns < ActiveRecord::Migration[6.1]
+ def change
+ change_table :images do |t|
+ t.remove :attachment_file_name, type: :string
+ t.remove :attachment_content_type, type: :string
+ t.remove :attachment_file_size, type: :bigint
+ t.remove :attachment_updated_at, type: :datetime
+ end
+
+ change_table :documents do |t|
+ t.remove :attachment_file_name, type: :string
+ t.remove :attachment_content_type, type: :string
+ t.remove :attachment_file_size, type: :bigint
+ t.remove :attachment_updated_at, type: :datetime
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 11ebacaa9..603deabd5 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2023_05_23_090028) do
+ActiveRecord::Schema.define(version: 2023_10_12_141318) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@@ -585,10 +585,6 @@ ActiveRecord::Schema.define(version: 2023_05_23_090028) do
create_table "documents", id: :serial, force: :cascade do |t|
t.string "title"
- t.string "attachment_file_name"
- t.string "attachment_content_type"
- t.bigint "attachment_file_size"
- t.datetime "attachment_updated_at"
t.integer "user_id"
t.string "documentable_type"
t.integer "documentable_id"
@@ -684,10 +680,6 @@ ActiveRecord::Schema.define(version: 2023_05_23_090028) do
t.string "title", limit: 80
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.string "attachment_file_name"
- t.string "attachment_content_type"
- t.bigint "attachment_file_size"
- t.datetime "attachment_updated_at"
t.integer "user_id"
t.index ["imageable_type", "imageable_id"], name: "index_images_on_imageable_type_and_imageable_id"
t.index ["user_id"], name: "index_images_on_user_id"
diff --git a/spec/components/polls/questions/read_more_component_spec.rb b/spec/components/polls/questions/read_more_component_spec.rb
index 053bc5097..26c9899ca 100644
--- a/spec/components/polls/questions/read_more_component_spec.rb
+++ b/spec/components/polls/questions/read_more_component_spec.rb
@@ -52,6 +52,6 @@ describe Polls::Questions::ReadMoreComponent do
render_inline Polls::Questions::ReadMoreComponent.new(question: question)
- expect(page).to have_link("The yes movement")
+ expect(page).to have_link text: "The yes movement"
end
end
diff --git a/spec/shared/system/documentable.rb b/spec/shared/system/documentable.rb
index 296da2bda..6723c55a2 100644
--- a/spec/shared/system/documentable.rb
+++ b/spec/shared/system/documentable.rb
@@ -11,22 +11,14 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
end
context "Show documents" do
- scenario "Download action should be able to anyone" do
+ scenario "Download action should be availabe to anyone and open in the same tab" do
visit send(documentable_path, arguments)
- expect(page).to have_link("Download file")
- end
-
- scenario "Download file link should have blank target attribute" do
- visit send(documentable_path, arguments)
-
- expect(page).to have_selector("a[target=_blank]", text: "Download file")
- end
-
- scenario "Download file links should have rel attribute setted to no follow" do
- visit send(documentable_path, arguments)
-
- expect(page).to have_selector("a[rel=nofollow]", text: "Download file")
+ within "#documents" do
+ expect(page).to have_link text: document.title
+ expect(page).to have_selector "a[rel=nofollow]", text: document.title
+ expect(page).not_to have_selector "a[target=_blank]"
+ end
end
describe "Destroy action" do
diff --git a/spec/shared/system/milestoneable.rb b/spec/shared/system/milestoneable.rb
index 7fc8f653f..13569e63f 100644
--- a/spec/shared/system/milestoneable.rb
+++ b/spec/shared/system/milestoneable.rb
@@ -29,7 +29,7 @@ shared_examples "milestoneable" do |factory_name|
expect(page).to have_content(Date.yesterday)
expect(page).not_to have_content(Date.current)
expect(page.find("#image_#{first_milestone.id}")["alt"]).to have_content(image.title)
- expect(page).to have_link(document.title)
+ expect(page).to have_link text: document.title
expect(page).to have_link("https://consul.dev")
expect(page).to have_content(first_milestone.status.name)
end
diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb
index d21c380ef..441330b57 100644
--- a/spec/shared/system/nested_documentable.rb
+++ b/spec/shared/system/nested_documentable.rb
@@ -163,7 +163,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
click_link "Add new document"
click_on submit_button
- within "#nested-documents .document" do
+ within "#nested-documents .document-fields" do
expect(page).to have_content("can't be blank", count: 2)
end
end
@@ -175,7 +175,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
documentable_attach_new_file(file_fixture("empty.pdf"))
click_link "Remove document"
- expect(page).not_to have_css("#nested-documents .document")
+ expect(page).not_to have_css("#nested-documents .document-fields")
end
scenario "Should show successful notice when
@@ -248,7 +248,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
do_login_for user_to_login, management: management
visit send(path, arguments)
- expect(page).to have_css ".document", count: 1
+ expect(page).to have_css ".document-fields", count: 1
end
scenario "Should not show add document button when
@@ -264,7 +264,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
do_login_for user_to_login, management: management
visit send(path, arguments)
- last_document = all("#nested-documents .document").last
+ last_document = all("#nested-documents .document-fields").last
within last_document do
click_on "Remove document"
end
@@ -278,7 +278,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
visit send(path, arguments)
click_on "Remove document"
- expect(page).not_to have_css ".document"
+ expect(page).not_to have_css ".document-fields"
end
scenario "Same attachment URL after editing the title" do
@@ -291,14 +291,14 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
expect(page).to have_content documentable_success_notice
- original_url = find_link("Download file")[:href]
+ original_url = find_link(text: "Original")[: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
+ expect(find_link(text: "Updated")[:href]).to eq original_url
end
end
diff --git a/spec/shared/system/nested_imageable.rb b/spec/shared/system/nested_imageable.rb
index ca49a42d7..f055e055c 100644
--- a/spec/shared/system/nested_imageable.rb
+++ b/spec/shared/system/nested_imageable.rb
@@ -57,7 +57,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments)
click_link "Add image"
- input_title = find(".image input[name$='[title]']")
+ input_title = find(".image-fields input[name$='[title]']")
fill_in input_title[:id], with: "Title"
attach_file "Choose image", file_fixture("clippy.jpg")
@@ -119,7 +119,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
click_link "Add image"
click_on submit_button
- within "#nested-image .image" do
+ within "#nested-image .image-fields" do
expect(page).to have_content("can't be blank", count: 2)
end
end
@@ -143,11 +143,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
imageable_attach_new_file(file_fixture("clippy.jpg"))
- within "#nested-image .image" do
+ within "#nested-image .image-fields" do
click_link "Remove image"
end
- expect(page).not_to have_selector("#nested-image .image")
+ expect(page).not_to have_selector("#nested-image .image-fields")
end
scenario "Should show successful notice when resource filled correctly without any nested images",
@@ -216,7 +216,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments)
- expect(page).to have_css ".image", count: 1
+ expect(page).to have_css ".image-fields", count: 1
expect(page).not_to have_css "a#new_image_link"
end
@@ -227,7 +227,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments)
click_link "Remove image"
- expect(page).not_to have_css ".image"
+ expect(page).not_to have_css ".image-fields"
expect(page).to have_link id: "new_image_link"
end
@@ -239,7 +239,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
click_link "Remove image"
click_link "Add image"
- expect(page).to have_css ".image", count: 1, visible: :all
+ expect(page).to have_css ".image-fields", count: 1, visible: :all
end
end
end
diff --git a/spec/support/common_actions/documents.rb b/spec/support/common_actions/documents.rb
index c6b8e0b44..e7752ad84 100644
--- a/spec/support/common_actions/documents.rb
+++ b/spec/support/common_actions/documents.rb
@@ -9,7 +9,7 @@ module Documents
def documentable_attach_new_file(path, success = true)
click_link "Add new document"
- document = all(".document").last
+ document = all(".document-fields").last
attach_file "Choose document", path
within document do
@@ -22,7 +22,7 @@ module Documents
end
def expect_document_has_title(index, title)
- document = all(".document")[index]
+ document = all(".document-fields")[index]
within document do
expect(find("input[name$='[title]']").value).to eq title
diff --git a/spec/support/common_actions/images.rb b/spec/support/common_actions/images.rb
index 8f372be43..1c7a248e1 100644
--- a/spec/support/common_actions/images.rb
+++ b/spec/support/common_actions/images.rb
@@ -11,7 +11,7 @@ module Images
def imageable_attach_new_file(path, success = true)
click_link "Add image"
within "#nested-image" do
- image = find(".image")
+ image = find(".image-fields")
attach_file "Choose image", path
within image do
if success
@@ -40,7 +40,7 @@ module Images
end
def expect_image_has_title(title)
- image = find(".image")
+ image = find(".image-fields")
within image do
expect(find("input[name$='[title]']").value).to eq title
diff --git a/spec/system/admin/budget_investments_spec.rb b/spec/system/admin/budget_investments_spec.rb
index ac7408eee..506562d17 100644
--- a/spec/system/admin/budget_investments_spec.rb
+++ b/spec/system/admin/budget_investments_spec.rb
@@ -981,8 +981,7 @@ describe "Admin budget investments", :admin do
expect(page).to have_content("Investment preview")
expect(page).to have_content(budget_investment.image.title)
expect(page).to have_content("Documents (1)")
- expect(page).to have_content(document.title)
- expect(page).to have_content("Download file")
+ expect(page).to have_link text: document.title
expect(page).to have_content("1234")
expect(page).to have_content("1000")
expect(page).to have_content("Unfeasible")
diff --git a/spec/system/admin/poll/questions/answers/documents/documents_spec.rb b/spec/system/admin/poll/questions/answers/documents/documents_spec.rb
index cc6f55bc9..9a65fc182 100644
--- a/spec/system/admin/poll/questions/answers/documents/documents_spec.rb
+++ b/spec/system/admin/poll/questions/answers/documents/documents_spec.rb
@@ -30,11 +30,16 @@ describe "Documents", :admin do
visit admin_answer_documents_path(answer)
+ expect(page).not_to have_link "Download file"
+
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.pdf"))
click_button "Save"
expect(page).to have_content "Document uploaded successfully"
- expect(page).to have_link "clippy.pdf"
+
+ within("tr", text: "clippy.pdf") do
+ expect(page).to have_link "Download file"
+ end
end
scenario "with invalid data" do
diff --git a/spec/system/admin/site_customization/documents_spec.rb b/spec/system/admin/site_customization/documents_spec.rb
index 5c284c525..ae65fe484 100644
--- a/spec/system/admin/site_customization/documents_spec.rb
+++ b/spec/system/admin/site_customization/documents_spec.rb
@@ -23,7 +23,7 @@ describe "Documents", :admin do
visit admin_site_customization_documents_path
expect(page).to have_content "There are 3 documents"
- expect(page).to have_link document.title, href: url
+ expect(page).to have_link "Download file", href: url
end
scenario "Index (empty)" do
@@ -39,7 +39,7 @@ describe "Documents", :admin do
visit admin_site_customization_documents_path
- expect(page).to have_selector("#documents .document", count: per_page)
+ expect(page).to have_selector("#documents .document-row", count: per_page)
within("ul.pagination") do
expect(page).to have_content("1")
@@ -48,7 +48,7 @@ describe "Documents", :admin do
click_link "Next", exact: false
end
- expect(page).to have_selector("#documents .document", count: 2)
+ expect(page).to have_selector("#documents .document-row", count: 2)
end
scenario "Create" do
@@ -58,7 +58,8 @@ describe "Documents", :admin do
click_button "Upload"
expect(page).to have_content "Document uploaded successfully"
- expect(page).to have_link "logo.pdf"
+
+ within("tr", text: "logo.pdf") { expect(page).to have_link "Download file" }
end
scenario "Errors on create" do
diff --git a/spec/system/dashboard/poster_spec.rb b/spec/system/dashboard/poster_spec.rb
index ad591a905..bf311d570 100644
--- a/spec/system/dashboard/poster_spec.rb
+++ b/spec/system/dashboard/poster_spec.rb
@@ -31,9 +31,9 @@ describe "Poster" do
end
scenario "PDF contains the proposal details" do
- within_window(window_opened_by { click_link "Download" }) do
- expect(page).to have_content(proposal.title)
- expect(page).to have_content(proposal.code)
- end
+ click_link "Download"
+
+ expect(page).to have_content(proposal.title)
+ expect(page).to have_content(proposal.code)
end
end