diff --git a/app/helpers/investments_helper.rb b/app/helpers/investments_helper.rb new file mode 100644 index 000000000..e6767c4c5 --- /dev/null +++ b/app/helpers/investments_helper.rb @@ -0,0 +1,15 @@ +module InvestmentsHelper + + def investment_image_file_name(investment) + investment.image.url.split('/').last.split("?")[0] if investment.image.present? + end + + def investment_image_advice_note_key(investment) + investment.image.exists? ? "edit_note" : "add_note" + end + + def investment_image_button_text(investment) + investment.image.exists? ? "edit_image" : "add_image" + end + +end \ No newline at end of file diff --git a/app/views/budgets/investments/_image_form.html.erb b/app/views/budgets/investments/_image_form.html.erb index db73cfff0..89b2a5bcd 100644 --- a/app/views/budgets/investments/_image_form.html.erb +++ b/app/views/budgets/investments/_image_form.html.erb @@ -3,8 +3,7 @@
<%= @investment.image.url.split('/').last.split("?")[0] if @investment.image.exists?%>
+<%= investment_image_file_name(@investment) %>
<%= t("budgets.investments.show.code_html", code: investment.id) %> diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 7a125909c..fb3061733 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -392,6 +392,7 @@ feature 'Budget Investments' 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" @@ -400,6 +401,7 @@ feature 'Budget Investments' do 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" @@ -407,6 +409,7 @@ feature 'Budget Investments' do scenario "Should not be shown for anonymous users" do investment = create(:budget_investment, heading: heading) + visit budget_investment_path(budget, investment) expect(page).not_to have_link "Edit image", href: edit_image_budget_investment_path(budget, investment) @@ -414,6 +417,7 @@ feature 'Budget Investments' do scenario "Should not be shown when current user is not investment author" do investment = create(:budget_investment, heading: heading) + visit budget_investment_path(budget, investment) expect(page).not_to have_link "Edit image", href: edit_image_budget_investment_path(budget, investment) @@ -422,6 +426,7 @@ feature 'Budget Investments' do scenario "Should be shown when current user is investment author" 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", href: edit_image_budget_investment_path(budget, investment) @@ -431,6 +436,7 @@ feature 'Budget Investments' do administrator = create(:administrator).user investment = create(:budget_investment, heading: heading, author: author) login_as(administrator) + visit budget_investment_path(budget, investment) expect(page).to have_link "Add image", href: edit_image_budget_investment_path(budget, investment) @@ -439,6 +445,7 @@ feature 'Budget Investments' do scenario "Edit image page should not be accesible when there is no logged user" do investment = create(:budget_investment, heading: heading, author: author) + visit edit_image_budget_investment_path(budget, investment) expect(page).to have_content "You must sign in or register to continue" @@ -448,6 +455,7 @@ feature 'Budget Investments' do other_author = create(:user, :level_two, username: 'Manuel') investment = create(:budget_investment, heading: heading, author: author) login_as(other_author) + visit edit_image_budget_investment_path(budget, investment) expect(page).to have_content "You do not have permission to carry out the action 'edit_image' on budget/investment." @@ -456,6 +464,7 @@ feature 'Budget Investments' do scenario "Edit image page should be accesible when author is currently logged" do investment = create(:budget_investment, heading: heading, author: author) login_as(author) + visit edit_image_budget_investment_path(budget, investment) expect(page).to have_content "Change your project image" @@ -465,6 +474,7 @@ feature 'Budget Investments' do administrator = create(:administrator).user investment = create(:budget_investment, heading: heading, author: author) login_as(administrator) + visit edit_image_budget_investment_path(budget, investment) expect(page).to have_content "Change your project image" @@ -473,6 +483,7 @@ feature 'Budget Investments' do scenario "Remove image button should not be present when investment image does not exists" do investment = create(:budget_investment, heading: heading, author: author) login_as(author) + visit edit_image_budget_investment_path(budget, investment) expect(page).not_to have_link "Remove image" @@ -481,6 +492,7 @@ feature 'Budget Investments' do scenario "Remove image button should be present when investment has an image defined" do investment = create(:budget_investment, :with_descriptive_image, heading: heading, author: author) login_as(author) + visit edit_image_budget_investment_path(budget, investment) expect(page).to have_link "Remove image" @@ -490,8 +502,8 @@ feature 'Budget Investments' do administrator = create(:administrator).user investment = create(:budget_investment, :with_descriptive_image, heading: heading, author: author) login_as(administrator) - visit edit_image_budget_investment_path(budget, investment) + visit edit_image_budget_investment_path(budget, investment) click_link "Remove image" expect(page).to have_content "Investment project image removed succesfully." @@ -500,8 +512,8 @@ feature 'Budget Investments' do scenario "Remove image should be possible for investment author" do investment = create(:budget_investment, :with_descriptive_image, heading: heading, author: author) login_as(author) - visit edit_image_budget_investment_path(budget, investment) + visit edit_image_budget_investment_path(budget, investment) click_link "Remove image" expect(page).to have_content "Investment project image removed succesfully." @@ -510,6 +522,7 @@ feature 'Budget Investments' do scenario "Remove image should not be possible for any other logged users (except administrators and author)" do investment = create(:budget_investment, :with_descriptive_image, heading: heading, author: author) login_as(create(:user)) + visit edit_image_budget_investment_path(budget, investment) expect(page).to have_content "You do not have permission to carry out the action 'edit_image' on budget/investment." @@ -521,6 +534,7 @@ feature 'Budget Investments' do login_as(other_author) visit edit_image_budget_investment_path(investment.budget, investment) + expect(current_path).not_to eq(edit_image_budget_investment_path(investment.budget, investment)) expect(page).to have_content 'You do not have permission' end @@ -533,13 +547,14 @@ feature 'Budget Investments' do fill_in :budget_investment_image_title, with: "New image title" attach_file :budget_investment_image, "spec/fixtures/files/logo_header.jpg" click_on "Save image" + within ".budget-investment-show" do expect(page).to have_css("img[src*='logo_header.jpg']") end expect(page).to have_content 'Investment project image updated succesfully. ' end - scenario "Update image should be possible for authors" do + scenario "Update image should be possible for administrators" do administrator = create(:administrator).user investment = create(:budget_investment, heading: heading, author: author) login_as(administrator) @@ -548,6 +563,7 @@ feature 'Budget Investments' do fill_in :budget_investment_image_title, with: "New image title" attach_file :budget_investment_image, "spec/fixtures/files/logo_header.jpg" click_on "Save image" + within ".budget-investment-show" do expect(page).to have_css("img[src*='logo_header.jpg']") end