Add budget investements images specs

This commit is contained in:
Senén Rodero Rodríguez
2017-06-15 09:42:45 +02:00
parent c399692109
commit 673fc66011
9 changed files with 58 additions and 16 deletions

View File

@@ -105,8 +105,10 @@ module Budgets
end
def investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list,
:organization_name, :location, :terms_of_service, :image,
params.require(:budget_investment)
.permit(:title, :description, :external_url, :heading_id,
:tag_list, :organization_name, :location, :terms_of_service,
:image, :image_description,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
end

View File

@@ -17,6 +17,7 @@ class Budget
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
# TODO: ROCK&ROR: Set image versions sizes acordingly to enhance page load
has_attached_file :image, styles: { large: "600x600>", medium: "300x300>", thumb: "100x100>" }
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'

View File

@@ -53,8 +53,12 @@
data: {js_url: suggest_tags_path} %>
</div>
<div class="budget_investment_image">
<%= f.file_field :image %>
<div class="small-12 column">
<%= f.file_field :image, accept: 'image/jpeg' %>
</div>
<div class="small-12 column">
<%= f.text_field :image_description %>
</div>
<% unless current_user.manager? %>

View File

@@ -2,7 +2,18 @@
<div class="panel">
<div class="row">
<div class="small-12 medium-9 column">
<!-- TODO: ROCK&ROR: Temporal markup. Place it as needed to reflect mockup -->
<div class="small-2 medium-2 large-2 column">
<% if investment.image.exists? %>
<%= image_tag investment.image.url(:thumb),
title: investment.image_description,
alt: investment.image_description, class: "th" %>
<% else %>
<!-- TODO: ROCK&ROR: Create colored placeholder or default image -->
<% end %>
</div>
<div class="small-10 medium-7 large-10 column">
<div class="budget-investment-content">
<% cache [locale_and_user_status(investment), 'index', investment, investment.author] do %>
@@ -43,12 +54,6 @@
<% unless investment.unfeasible? %>
<% if investment.image.exists? %>
<div class="small-12 medium-3 column">
<%= image_tag investment.image.url(:medium) %>
</div>
<% end %>
<% if investment.should_show_votes? %>
<div id="<%= dom_id(investment) %>_votes"
class="small-12 medium-3 column text-center">

View File

@@ -37,8 +37,11 @@
</p>
<% end %>
<!-- TODO: ROCK&ROR: Markup rework accordingly to mockup definition -->
<% if investment.image.exists? %>
<%= image_tag investment.image.url(:large) %>
<%= image_tag investment.image.url(:medium),
title: investment.image_description,
alt: investment.image_description %>
<% end %>
<%= render 'shared/tags', taggable: investment %>

View File

@@ -104,6 +104,8 @@ en:
title: "Title"
location: "Location"
organization_name: "If you are proposing in the name of a collective/organization, write its name"
image: "Proposal descriptive image"
image_description: "Image description"
budget/investment/milestone:
title: "Title"
description: "Description"

View File

@@ -99,6 +99,8 @@ es:
title: "Título"
location: "Ubicación"
organization_name: "Si estás proponiendo en nombre de una organización o colectivo, escribe su nombre"
image: "Imagen descriptiva de la propueta"
image_description: "Texto descriptivo de la imagen"
comment:
body: "Comentario"
user: "Usuario"

View File

@@ -257,10 +257,10 @@ ActiveRecord::Schema.define(version: 20170918231410) do
t.string "visit_id"
t.datetime "hidden_at"
t.integer "flags_count", default: 0
t.datetime "ignored_flag_at"
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
t.datetime "ignored_flag_at"
t.integer "comments_count", default: 0
t.datetime "confirmed_hide_at"
t.integer "cached_anonymous_votes_total", default: 0
@@ -279,7 +279,6 @@ ActiveRecord::Schema.define(version: 20170918231410) do
add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree
add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree
add_index "debates", ["confidence_score"], name: "index_debates_on_confidence_score", using: :btree
add_index "debates", ["description"], name: "index_debates_on_description", using: :btree
add_index "debates", ["geozone_id"], name: "index_debates_on_geozone_id", using: :btree
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree
@@ -786,7 +785,6 @@ ActiveRecord::Schema.define(version: 20170918231410) do
add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree
add_index "proposals", ["community_id"], name: "index_proposals_on_community_id", using: :btree
add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree
add_index "proposals", ["description"], name: "index_proposals_on_description", using: :btree
add_index "proposals", ["geozone_id"], name: "index_proposals_on_geozone_id", using: :btree
add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree
add_index "proposals", ["hot_score"], name: "index_proposals_on_hot_score", using: :btree

View File

@@ -28,6 +28,21 @@ feature 'Budget Investments' do
end
end
scenario 'Index should show investment descriptive image only when is defined' do
investment = create(:budget_investment, heading: heading)
investment_with_image = create(:budget_investment, :with_descriptive_image, heading: heading)
visit budget_investments_path(budget, heading_id: heading.id)
within("#budget_investment_#{investment.id}") do
expect(page).not_to have_css("img.th")
end
within("#budget_investment_#{investment_with_image.id}") do
expect(page).to have_css("img.th[alt='#{investment_with_image.image_description}'][title='#{investment_with_image.image_description}']")
end
end
context("Search") do
scenario 'Search by text' do
@@ -355,6 +370,16 @@ feature 'Budget Investments' do
expect(page).not_to have_selector ".js-follow"
end
scenario "Show descriptive image when exists" do
user = create(:user)
login_as(user)
investment_with_image = create(:budget_investment, :with_descriptive_image, heading: heading)
visit budget_investment_path(budget_id: budget.id, id: investment_with_image.id)
expect(page).to have_css("img[alt='#{investment_with_image.image_description}'][title='#{investment_with_image.image_description}']")
end
scenario "Show back link contains heading id" do
investment = create(:budget_investment, heading: heading)
visit budget_investment_path(budget, investment)