Adds recommendations on debates index

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

View File

@@ -6,6 +6,7 @@ class DebatesController < ApplicationController
before_action :parse_tag_filter, only: :index before_action :parse_tag_filter, only: :index
before_action :authenticate_user!, except: [:index, :show, :map] before_action :authenticate_user!, except: [:index, :show, :map]
before_action :set_view, only: :index before_action :set_view, only: :index
before_action :debates_recommendations, only: :index, if: :current_user
feature_flag :debates feature_flag :debates
@@ -57,4 +58,7 @@ class DebatesController < ApplicationController
@view = (params[:view] == "minimal") ? "minimal" : "default" @view = (params[:view] == "minimal") ? "minimal" : "default"
end end
def debates_recommendations
@recommended_debates = Debate.recommendations(current_user).sort_by_random.limit(3)
end
end end

View File

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

View File

@@ -43,6 +43,7 @@ en:
user: user:
recommendations: Recommendations recommendations: Recommendations
skip_verification: Skip user verification skip_verification: Skip user verification
recommendations_on_debates: Recommendeds on debates
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

@@ -43,6 +43,7 @@ es:
user: user:
recommendations: Recomendaciones recommendations: Recomendaciones
skip_verification: Omitir verificación de usuarios skip_verification: Omitir verificación de usuarios
recommendations_on_debates: Recomendaciones en debates
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

@@ -82,6 +82,7 @@ Setting['feature.budgets'] = true
Setting['feature.signature_sheets'] = true 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.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

@@ -403,10 +403,12 @@ feature 'Debates' do
background do background do
Setting['feature.user.recommendations'] = true Setting['feature.user.recommendations'] = true
Setting['feature.user.recommendations_on_debates'] = true
end end
after do after do
Setting['feature.user.recommendations'] = nil Setting['feature.user.recommendations'] = nil
Setting['feature.user.recommendations_on_debates'] = nil
end end
scenario 'Debates can not ordered by recommendations when there is not an user logged', :js do scenario 'Debates can not ordered by recommendations when there is not an user logged', :js do
@@ -415,6 +417,21 @@ feature 'Debates' do
expect(page).not_to have_selector('a', text: 'recommendations') expect(page).not_to have_selector('a', text: 'recommendations')
end end
scenario 'Show recommended debates on index header' do
proposal = create(:proposal, tag_list: "Sport")
user = create(:user)
create(:follow, followable: proposal, user: user)
login_as(user)
visit debates_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")