Merge pull request #4699 from consul/render_attachments

Remove unused attachments code
This commit is contained in:
Javi Martín
2021-09-24 17:48:09 +02:00
committed by GitHub
10 changed files with 17 additions and 64 deletions

View File

@@ -4,9 +4,5 @@ module Galleryable
included do included do
has_many :images, as: :imageable, inverse_of: :imageable, dependent: :destroy has_many :images, as: :imageable, inverse_of: :imageable, dependent: :destroy
accepts_nested_attributes_for :images, allow_destroy: true, update_only: true accepts_nested_attributes_for :images, allow_destroy: true, update_only: true
def image_url(style)
image&.attachment&.url(style) || ""
end
end end
end end

View File

@@ -9,11 +9,7 @@
</div> </div>
<div class="margin-bottom"> <div class="margin-bottom">
<% if proposal.image.present? %> <%= image_tag(proposal.image_url(:large).presence || "default_mailing.jpg") %>
<%= image_tag proposal.image.attachment.url(:large) %>
<% else %>
<%= image_tag "default_mailing.jpg" %>
<% end %>
</div> </div>
<div class="mail-body"> <div class="mail-body">

View File

@@ -58,12 +58,4 @@ shared_examples "acts as imageable" do |imageable_factory|
expect(image).not_to be_valid expect(image).not_to be_valid
end end
end end
it "image destroy should remove image from file storage" do
image.save!
image_url = image.attachment.url
new_url = "/attachments/original/missing.png"
expect { image.attachment.destroy }.to change { image.attachment.url }.from(image_url).to(new_url)
end
end end

View File

@@ -47,10 +47,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
do_login_for user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
imageable_factory_name,
Rails.root.join("spec/fixtures/files/clippy.jpg")
)
expect_image_has_title("clippy.jpg") expect_image_has_title("clippy.jpg")
end end
@@ -75,10 +72,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
do_login_for user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
imageable_factory_name,
Rails.root.join("spec/fixtures/files/clippy.jpg")
)
expect(page).to have_selector ".loading-bar.complete" expect(page).to have_selector ".loading-bar.complete"
end end
@@ -87,11 +81,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
do_login_for user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(Rails.root.join("spec/fixtures/files/logo_header.png"), false)
imageable_factory_name,
Rails.root.join("spec/fixtures/files/logo_header.png"),
false
)
expect(page).to have_selector ".loading-bar.errors" expect(page).to have_selector ".loading-bar.errors"
end end
@@ -100,10 +90,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
do_login_for user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
imageable_factory_name,
Rails.root.join("spec/fixtures/files/clippy.jpg")
)
expect_image_has_cached_attachment(".jpg") expect_image_has_cached_attachment(".jpg")
end end
@@ -112,11 +99,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
do_login_for user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(Rails.root.join("spec/fixtures/files/logo_header.png"), false)
imageable_factory_name,
Rails.root.join("spec/fixtures/files/logo_header.png"),
false
)
expect_image_has_cached_attachment("") expect_image_has_cached_attachment("")
end end
@@ -141,10 +124,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
do_login_for user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
imageable_factory_name,
Rails.root.join("spec/fixtures/files/clippy.jpg")
)
within "#nested-image .image" do within "#nested-image .image" do
click_link "Remove image" click_link "Remove image"
@@ -171,10 +151,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
imageable_attach_new_file( imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
imageable_factory_name,
Rails.root.join("spec/fixtures/files/clippy.jpg")
)
expect(page).to have_selector ".loading-bar.complete" expect(page).to have_selector ".loading-bar.complete"
@@ -188,10 +165,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
imageable_attach_new_file( imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
imageable_factory_name,
Rails.root.join("spec/fixtures/files/clippy.jpg")
)
expect(page).to have_selector ".loading-bar.complete" expect(page).to have_selector ".loading-bar.complete"
@@ -255,7 +229,7 @@ def imageable_redirected_to_resource_show_or_navigate_to
end end
end end
def imageable_attach_new_file(_imageable_factory_name, path, success = true) def imageable_attach_new_file(path, success = true)
click_link "Add image" click_link "Add image"
within "#nested-image" do within "#nested-image" do
image = find(".image") image = find(".image")

View File

@@ -46,10 +46,7 @@ describe "Admin budget phases" do
scenario "shows successful notice when updating the phase with a valid image" do scenario "shows successful notice when updating the phase with a valid image" do
visit edit_admin_budget_budget_phase_path(budget, budget.current_phase) visit edit_admin_budget_budget_phase_path(budget, budget.current_phase)
imageable_attach_new_file( imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
"budget_phase_image",
Rails.root.join("spec/fixtures/files/clippy.jpg")
)
click_on "Save changes" click_on "Save changes"

View File

@@ -175,7 +175,7 @@ describe "Admin collaborative legislation", :admin do
fill_in "End", with: base_date + 5.days fill_in "End", with: base_date + 5.days
end end
imageable_attach_new_file(create(:image), Rails.root.join("spec/fixtures/files/clippy.jpg")) imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
click_button "Create process" click_button "Create process"

View File

@@ -32,14 +32,13 @@ describe "Images", :admin do
scenario "Add image to answer" do scenario "Add image to answer" do
answer = create(:poll_question_answer) answer = create(:poll_question_answer)
image = create(:image)
visit admin_answer_images_path(answer) visit admin_answer_images_path(answer)
expect(page).not_to have_css("img[title='clippy.jpg']") expect(page).not_to have_css("img[title='clippy.jpg']")
expect(page).not_to have_content("clippy.jpg") expect(page).not_to have_content("clippy.jpg")
visit new_admin_answer_image_path(answer) visit new_admin_answer_image_path(answer)
imageable_attach_new_file(image, Rails.root.join("spec/fixtures/files/clippy.jpg")) imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
click_button "Save image" click_button "Save image"
expect(page).to have_css("img[title='clippy.jpg']") expect(page).to have_css("img[title='clippy.jpg']")

View File

@@ -58,7 +58,7 @@ describe "Documents", :admin do
click_button "Upload" click_button "Upload"
expect(page).to have_content "Document uploaded succesfully" expect(page).to have_content "Document uploaded succesfully"
expect(page).to have_link "logo.pdf", href: Document.last.attachment.url expect(page).to have_link "logo.pdf"
end end
scenario "Errors on create" do scenario "Errors on create" do

View File

@@ -40,19 +40,18 @@ describe "Cards", :admin do
end end
scenario "Index" do scenario "Index" do
3.times { create(:widget_card) } cards = Array.new(3) { create(:widget_card) }
visit admin_homepage_path visit admin_homepage_path
expect(page).to have_css(".homepage-card", count: 3) expect(page).to have_css(".homepage-card", count: 3)
cards = Widget::Card.all
cards.each do |card| cards.each do |card|
expect(page).to have_content card.title expect(page).to have_content card.title
expect(page).to have_content card.description expect(page).to have_content card.description
expect(page).to have_content card.link_text expect(page).to have_content card.link_text
expect(page).to have_content card.link_url expect(page).to have_content card.link_url
expect(page).to have_link("Show image", href: card.image_url(:large)) expect(page).to have_link "Show image"
end end
end end

View File

@@ -146,7 +146,7 @@ describe "Legislation Proposals" do
fill_in "Proposal title", with: "Legislation proposal with image" fill_in "Proposal title", with: "Legislation proposal with image"
fill_in "Proposal summary", with: "Including an image on a legislation proposal" fill_in "Proposal summary", with: "Including an image on a legislation proposal"
imageable_attach_new_file(create(:image), Rails.root.join("spec/fixtures/files/clippy.jpg")) imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg"))
check "legislation_proposal_terms_of_service" check "legislation_proposal_terms_of_service"
click_button "Create proposal" click_button "Create proposal"