diff --git a/app/views/images/_image.html.erb b/app/views/images/_image.html.erb index 7133e298c..da1f66295 100644 --- a/app/views/images/_image.html.erb +++ b/app/views/images/_image.html.erb @@ -10,7 +10,7 @@ <% end %> - + <% if show_caption %>
<% end %> diff --git a/app/views/images/_nested_fields.html.erb b/app/views/images/_nested_fields.html.erb index aaa703bda..9c86beaf7 100644 --- a/app/views/images/_nested_fields.html.erb +++ b/app/views/images/_nested_fields.html.erb @@ -15,6 +15,7 @@ <%= label_tag :title, t("activerecord.attributes.image.title") %> <%= text_field_tag :title, image.title, + placeholder: t("images.new.form.title_placeholder"), name: image_nested_field_name(image, :title), id: image_nested_field_id(image, :title), class: "image-title" %> diff --git a/app/views/images/_plain_fields.html.erb b/app/views/images/_plain_fields.html.erb index fcfb75566..c18ec0b4d 100644 --- a/app/views/images/_plain_fields.html.erb +++ b/app/views/images/_plain_fields.html.erb @@ -2,13 +2,15 @@
<%= label_tag :image_title, t("activerecord.attributes.image.title") %> - <%= text_field_tag :image_title, image.title, name: "image[title]", class: "image-title" %> + <%= text_field_tag :image_title, image.title, placeholder: t("images.new.form.title_placeholder"), name: "image[title]", class: "image-title" %> <% if image.errors.has_key?(:title) %> <%= image.errors[:title].join(", ") %> <% end %>
+ <%= render_image(image, :thumb, false) if image.attachment.exists? %> + <%= hidden_field_tag :cached_attachment, image.cached_attachment, name: "image[cached_attachment]" %> <%= file_field_tag :attachment, accept: imageable_accepted_content_types_extensions, diff --git a/config/locales/en/images.yml b/config/locales/en/images.yml index c5ce6c974..b026d544d 100644 --- a/config/locales/en/images.yml +++ b/config/locales/en/images.yml @@ -18,6 +18,8 @@ en: note: 'Add an image to your investment project: %{title}' proposal: note: 'Add an image to your proposal: %{title}' + form: + title_placeholder: Add a descriptive title for the image recommendations_title: File upload tips proposal: diff --git a/config/locales/es/images.yml b/config/locales/es/images.yml index 698a0ab00..652630a29 100644 --- a/config/locales/es/images.yml +++ b/config/locales/es/images.yml @@ -15,9 +15,11 @@ es: new: title: Subir una imagen budget_investment: - note: 'Añade un título a la propuesta de inversión: %{title}.' + note: 'Añade una imagen la propuesta de inversión: %{title}.' proposal: - note: 'Añade un título a la propuesta: %{title}.' + note: 'Añade una imagen a la propuesta: %{title}.' + form: + title_placeholder: Añade un título descriptivo para la imagen recommendations_title: Consejos para subir imágenes proposal: diff --git a/spec/shared/features/imageable.rb b/spec/shared/features/imageable.rb index 106da9c4e..e004b193b 100644 --- a/spec/shared/features/imageable.rb +++ b/spec/shared/features/imageable.rb @@ -112,7 +112,17 @@ shared_examples "imageable" do |imageable_factory_name, imageable_path, imageabl expect(page).to have_selector("h1", text: "Upload image") end - scenario "Should display file name after file selection", :js do + scenario "Should display file name after image selection", :js do + login_as imageable.author + visit new_image_path(imageable_type: imageable.class.name, + imageable_id: imageable.id) + + attach_file :image_attachment, "spec/fixtures/files/empty.pdf", make_visible: true + + expect(page).to have_content "empty.pdf" + end + + scenario "Should not display file name after invalid image upload", :js do login_as imageable.author visit new_image_path(imageable_type: imageable.class.name, imageable_id: imageable.id) @@ -120,10 +130,10 @@ shared_examples "imageable" do |imageable_factory_name, imageable_path, imageabl attach_file :image_attachment, "spec/fixtures/files/empty.pdf", make_visible: true sleep 1 - expect(page).to have_content "empty.pdf" + expect(page).not_to have_content "empty.pdf" end - scenario "Should not display file name after file selection", :js do + scenario "Should display attachment validation errors after invalid image upload", :js do login_as imageable.author visit new_image_path(imageable_type: imageable.class.name, imageable_id: imageable.id) @@ -131,7 +141,19 @@ shared_examples "imageable" do |imageable_factory_name, imageable_path, imageabl attach_file :image_attachment, "spec/fixtures/files/logo_header.png", make_visible: true sleep 1 - expect(page).not_to have_content "logo_header.jpg" + expect(page).to have_selector "small.error" + end + + scenario "Should display cached image without caption after valid image upload", :js do + login_as imageable.author + visit new_image_path(imageable_type: imageable.class.name, + imageable_id: imageable.id) + + attach_file :image_attachment, "spec/fixtures/files/clippy.jpg", make_visible: true + sleep 1 + + expect(page).to have_css("figure img") + expect(page).not_to have_css("figure figcaption") end scenario "Should update loading bar style after valid file upload", :js do