Add dynamic texts to investment image button.

This commit is contained in:
Senén Rodero Rodríguez
2017-06-22 12:03:28 +02:00
parent 3d13896c9a
commit 0925d33c5b
5 changed files with 39 additions and 14 deletions

View File

@@ -5,13 +5,16 @@
<div class="small-12 column">
<span class="note-marked">
<%= t("budgets.investments.edit_image.note", title: @investment.title) %></p>
<% note_key = @investment.image.exists? ? "edit_note" : "add_note" %>
<%= t("budgets.investments.edit_image.#{note_key}", title: @investment.title) %></p>
</span>
</div>
<% if @investment.image.exists? %>
<div class="small-12 column">
<%= image_tag @investment.image.url(:large) %>
</div>
<% end %>
<div class="small-12 column">
<%= f.file_field :image, accept: 'image/jpeg' %>

View File

@@ -11,7 +11,8 @@
<% end %>
<% if author_of?(investment, current_user) || (current_user && current_user.administrator?) %>
<%= link_to t("budgets.investments.show.edit_image"),
<% button_text = investment.image.exists? ? t("budgets.investments.show.edit_image") : t("budgets.investments.show.add_image") %>
<%= link_to button_text,
edit_image_budget_investment_path(investment.budget, investment),
class: 'button hollow float-right' %>
<% end %>
@@ -45,7 +46,7 @@
<!-- TODO: ROCK&ROR: Markup rework accordingly to mockup definition -->
<% if investment.image.exists? %>
<%= image_tag investment.image.url(:medium),
<%= image_tag investment.image.url(:large),
title: investment.image_title,
alt: investment.image_title %>
<% end %>

View File

@@ -109,9 +109,11 @@ en:
no_milestones: Don't have defined milestones
milestone_publish_date: "Published %{publish_date}"
edit_image: Edit image
add_image: Add image
edit_image:
title: Change your project image
note: 'You are changing investment project image of: %{title}'
add_note: 'Add an image to your investment project: %{title}'
edit_note: 'You are changing investment project image of: %{title}'
form:
image_title: Image title
submit_button: Save image

View File

@@ -109,9 +109,11 @@ es:
no_milestones: No hay hitos definidos
milestone_publish_date: "Publicado el %{publish_date}"
edit_image: Editar imagen
add_image: Añadir imagen
edit_image:
title: Cambia la imagen de tu proyecto
note: 'Estas cambiando la imagen del proyecto de inversión: %{title}'
add_note: 'Añade una imagen al proyecto de inversión: %{title}'
edit_note: 'Estas cambiando la imagen del proyecto de inversión: %{title}'
form:
image_title: 'Título de la imagen'
submit_button: Guardar imagen

View File

@@ -387,7 +387,24 @@ feature 'Budget Investments' do
expect(page).to have_link "Go back", href: budget_investments_path(budget, heading_id: investment.heading)
end
context "Show edit image button" do
context "Show investment image button" do
scenario "should show add text when investment has not image" do
investment = create(:budget_investment, heading: heading, author: author)
login_as(author)
visit budget_investment_path(budget, investment)
expect(page).to have_link "Add image"
end
scenario "should show edit text when investment has already an image" do
investment = create(:budget_investment, :with_descriptive_image, heading: heading, author: author)
login_as(author)
visit budget_investment_path(budget, investment)
expect(page).to have_link "Edit image"
end
scenario "should not be shown for anonymous users" do
investment = create(:budget_investment, heading: heading)
visit budget_investment_path(budget, investment)
@@ -407,7 +424,7 @@ feature 'Budget Investments' do
login_as(author)
visit budget_investment_path(budget, investment)
expect(page).to have_link "Edit image", href: edit_image_budget_investment_path(budget, investment)
expect(page).to have_link "Add image", href: edit_image_budget_investment_path(budget, investment)
end
scenario "should be shown when current user is administrator" do
@@ -416,7 +433,7 @@ feature 'Budget Investments' do
login_as(administrator)
visit budget_investment_path(budget, investment)
expect(page).to have_link "Edit image", href: edit_image_budget_investment_path(budget, investment)
expect(page).to have_link "Add image", href: edit_image_budget_investment_path(budget, investment)
end
end
@@ -592,12 +609,12 @@ feature 'Budget Investments' do
context "Destroy" do
scenario "Admin cannot destroy budget investments" do
administrator = create(:administrator).user
admin = create(:administrator)
user = create(:user, :level_two)
investment = create(:budget_investment, heading: heading, author: user)
login_as(administrator)
visit user_path(administrator)
login_as(admin.user)
visit user_path(user)
within("#budget_investment_#{investment.id}") do
expect(page).to_not have_link "Delete"