From 673fc66011707af06e801c05a190e810551befd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 15 Jun 2017 09:42:45 +0200 Subject: [PATCH] Add budget investements images specs --- .../budgets/investments_controller.rb | 8 +++--- app/models/budget/investment.rb | 1 + app/views/budgets/investments/_form.html.erb | 8 ++++-- .../budgets/investments/_investment.html.erb | 19 ++++++++------ .../investments/_investment_show.html.erb | 5 +++- config/locales/en/activerecord.yml | 2 ++ config/locales/es/activerecord.yml | 2 ++ db/schema.rb | 4 +-- spec/features/budgets/investments_spec.rb | 25 +++++++++++++++++++ 9 files changed, 58 insertions(+), 16 deletions(-) diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index fd5feccc2..b3ed6022a 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -105,9 +105,11 @@ 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, - documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id]) + 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 def load_ballot diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 459317497..29e09a55d 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -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' diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index bbc7f7c84..2d0fa488a 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -53,8 +53,12 @@ data: {js_url: suggest_tags_path} %> -
- <%= f.file_field :image %> +
+ <%= f.file_field :image, accept: 'image/jpeg' %> +
+ +
+ <%= f.text_field :image_description %>
<% unless current_user.manager? %> diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index efdfa6d64..2290b1d81 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -2,7 +2,18 @@
-
+ +
+ <% if investment.image.exists? %> + <%= image_tag investment.image.url(:thumb), + title: investment.image_description, + alt: investment.image_description, class: "th" %> + <% else %> + + <% end %> +
+ +
<% cache [locale_and_user_status(investment), 'index', investment, investment.author] do %> @@ -43,12 +54,6 @@ <% unless investment.unfeasible? %> - <% if investment.image.exists? %> -
- <%= image_tag investment.image.url(:medium) %> -
- <% end %> - <% if investment.should_show_votes? %>
diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 7bda0e8f4..ee7532afd 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -37,8 +37,11 @@

<% end %> + <% 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 %> diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 79982150c..87864229e 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -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" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index d409d1c5e..4bff6f5a9 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -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" diff --git a/db/schema.rb b/db/schema.rb index a44bf62aa..816648ac9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index afc564496..2cd4bd4ff 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -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)