Adds recommendations on proposals index

This commit is contained in:
decabeza
2018-03-28 01:40:51 +02:00
committed by Angel Perez
parent 36a5ff39b8
commit bdb3f30e40
6 changed files with 29 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ class ProposalsController < ApplicationController
before_action :authenticate_user!, except: [:index, :show, :map, :summary] before_action :authenticate_user!, except: [:index, :show, :map, :summary]
before_action :destroy_map_location_association, only: :update before_action :destroy_map_location_association, only: :update
before_action :set_view, only: :index before_action :set_view, only: :index
before_action :proposals_recommendations, only: :index, if: :current_user
feature_flag :proposals feature_flag :proposals
@@ -144,4 +145,8 @@ class ProposalsController < ApplicationController
end end
end end
def proposals_recommendations
@recommended_proposals = Proposal.recommendations(current_user).sort_by_random.limit(3)
end
end end

View File

@@ -37,6 +37,10 @@
<%= render "shared/section_header", i18n_namespace: "proposals.index.section_header", image: "proposals" %> <%= render "shared/section_header", i18n_namespace: "proposals.index.section_header", image: "proposals" %>
<% end %> <% end %>
<% if feature?("user.recommendations_on_proposals") && @recommended_proposals.present? %>
<%= render "shared/recommended_index", recommended: @recommended_proposals %>
<% end %>
<div class="row"> <div class="row">
<div id="proposals" class="proposals-list small-12 medium-9 column"> <div id="proposals" class="proposals-list small-12 medium-9 column">

View File

@@ -44,6 +44,7 @@ en:
recommendations: Recommendations recommendations: Recommendations
skip_verification: Skip user verification skip_verification: Skip user verification
recommendations_on_debates: Recommendeds on debates recommendations_on_debates: Recommendeds on debates
recommendations_on_proposals: Recommendeds on proposals
community: Community on proposals and investments community: Community on proposals and investments
map: Proposals and budget investments geolocation map: Proposals and budget investments geolocation
allow_images: Allow upload and show images allow_images: Allow upload and show images

View File

@@ -44,6 +44,7 @@ es:
recommendations: Recomendaciones recommendations: Recomendaciones
skip_verification: Omitir verificación de usuarios skip_verification: Omitir verificación de usuarios
recommendations_on_debates: Recomendaciones en debates recommendations_on_debates: Recomendaciones en debates
recommendations_on_proposals: Recomendaciones en propuestas
community: Comunidad en propuestas y proyectos de gasto community: Comunidad en propuestas y proyectos de gasto
map: Geolocalización de propuestas y proyectos de gasto map: Geolocalización de propuestas y proyectos de gasto
allow_images: Permitir subir y mostrar imágenes allow_images: Permitir subir y mostrar imágenes

View File

@@ -83,6 +83,7 @@ Setting['feature.signature_sheets'] = true
Setting['feature.legislation'] = true Setting['feature.legislation'] = true
Setting['feature.user.recommendations'] = true Setting['feature.user.recommendations'] = true
Setting['feature.user.recommendations_on_debates'] = true Setting['feature.user.recommendations_on_debates'] = true
Setting['feature.user.recommendations_on_proposals'] = true
Setting['feature.community'] = true Setting['feature.community'] = true
Setting['feature.map'] = nil Setting['feature.map'] = nil
Setting['feature.allow_images'] = true Setting['feature.allow_images'] = true

View File

@@ -727,10 +727,12 @@ feature 'Proposals' do
before do before do
Setting['feature.user.recommendations'] = true Setting['feature.user.recommendations'] = true
Setting['feature.user.recommendations_on_proposals'] = true
end end
after do after do
Setting['feature.user.recommendations'] = nil Setting['feature.user.recommendations'] = nil
Setting['feature.user.recommendations_on_proposals'] = nil
end end
scenario 'Proposals can not ordered by recommendations when there is not an user logged', :js do scenario 'Proposals can not ordered by recommendations when there is not an user logged', :js do
@@ -739,6 +741,21 @@ feature 'Proposals' do
expect(page).not_to have_selector('a', text: 'recommendations') expect(page).not_to have_selector('a', text: 'recommendations')
end end
scenario 'Show recommended proposals on index header' do
proposal = create(:proposal, tag_list: "Sport")
user = create(:user)
create(:follow, followable: proposal, user: user)
login_as(user)
visit proposals_path
expect(page).to have_css('.recommendation', count: 3)
expect(page).to have_link "Best"
expect(page).to have_link "Medium"
expect(page).to have_link "Worst"
expect(page).to have_link "See more recommendations"
end
scenario 'Should display text when there are not recommendeds results', :js do scenario 'Should display text when there are not recommendeds results', :js do
user = create(:user) user = create(:user)
proposal = create(:proposal, tag_list: "Distinct_to_sport") proposal = create(:proposal, tag_list: "Distinct_to_sport")