Create investments helper. Fix indentation error and some specs names and structure.
This commit is contained in:
15
app/helpers/investments_helper.rb
Normal file
15
app/helpers/investments_helper.rb
Normal file
@@ -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
|
||||
@@ -3,8 +3,7 @@
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<span class="note-marked">
|
||||
<% note_key = @investment.image.exists? ? "edit_note" : "add_note" %>
|
||||
<%= t("budgets.investments.edit_image.#{note_key}", title: @investment.title) %></p>
|
||||
<%= t("budgets.investments.edit_image.#{investment_image_advice_note_key(@investment)}", title: @investment.title) %></p>
|
||||
</span>
|
||||
</div>
|
||||
<% if @investment.image.exists? %>
|
||||
@@ -17,7 +16,7 @@
|
||||
<%= f.file_field :image, accept: 'image/jpeg', label: false, class:'show-for-sr' %>
|
||||
<br>
|
||||
<%= f.label :image, t("images.upload_image"), class:'button' %>
|
||||
<p><%= @investment.image.url.split('/').last.split("?")[0] if @investment.image.exists?%></p>
|
||||
<p><%= investment_image_file_name(@investment) %></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="small-12 column">
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
class: 'button hollow float-right' %>
|
||||
<% end %>
|
||||
|
||||
<% if author_of?(investment, current_user) || (current_user && current_user.administrator?) %>
|
||||
<% button_text = investment.image.exists? ? t("budgets.investments.show.edit_image") : t("budgets.investments.show.add_image") %>
|
||||
<%= link_to button_text,
|
||||
<% if can?(:edit_image, @investment) %>
|
||||
<%= link_to t("budgets.investments.show.#{investment_image_button_text(@investment)}"),
|
||||
edit_image_budget_investment_path(investment.budget, investment),
|
||||
class: 'button hollow float-right' %>
|
||||
<% end %>
|
||||
@@ -26,19 +25,19 @@
|
||||
</div>
|
||||
<br>
|
||||
<% if investment.image.exists? %>
|
||||
<div class="row">
|
||||
<div class="small-12 column text-center">
|
||||
<figure>
|
||||
<%= image_tag investment.image.url(:large),
|
||||
title: investment.image_title,
|
||||
alt: investment.image_title %>
|
||||
<figcaption class="text-right">
|
||||
<em><%= investment.image_title %></em>
|
||||
</figcaption>
|
||||
</figure>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="small-12 column text-center">
|
||||
<figure>
|
||||
<%= image_tag investment.image.url(:large),
|
||||
title: investment.image_title,
|
||||
alt: investment.image_title %>
|
||||
<figcaption class="text-right">
|
||||
<em><%= investment.image_title %></em>
|
||||
</figcaption>
|
||||
</figure>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<p id="investment_code">
|
||||
<%= t("budgets.investments.show.code_html", code: investment.id) %>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user