Move and refactor method from follow to user model to get user interests. Add specification to check the discard of duplicate interests.

This commit is contained in:
Senén Rodero Rodríguez
2017-07-07 13:57:07 +02:00
parent a7aef0a9fb
commit 4b2310c135
7 changed files with 33 additions and 29 deletions

View File

@@ -7,7 +7,7 @@ class UsersController < ApplicationController
def show
load_filtered_activity if valid_access?
load_interest if valid_interest_access?
load_interests if valid_interests_access?
end
private
@@ -63,15 +63,15 @@ class UsersController < ApplicationController
@budget_investments = Budget::Investment.where(author_id: @user.id).order(created_at: :desc).page(params[:page])
end
def load_interest
@interests = Follow.interests_by(@user)
def load_interests
@user.interests
end
def valid_access?
@user.public_activity || authorized_current_user?
end
def valid_interest_access?
def valid_interests_access?
@user.public_interests || authorized_current_user?
end

View File

@@ -18,14 +18,4 @@ class Follow < ActiveRecord::Base
!! by_user_and_followable(user, followable).try(:first)
end
def self.interests_by(user)
interests = []
user.follows.each do |follow|
follow.followable.tags.each do |tag|
interests << tag.name
end
end
interests.uniq
end
end

View File

@@ -309,6 +309,10 @@ class User < ActiveRecord::Base
where(conditions.to_hash).where(["username = ?", login]).first
end
def interests
follows.map{|follow| follow.followable.tags.map(&:name)}.flatten.compact.uniq
end
private
def clean_document_number

View File

@@ -49,7 +49,7 @@
<% if @user.public_interests || @authorized_current_user %>
<div id="public_interests" class="public-interests">
<h4><%= t('account.show.public_interests_title_list') %></h4>
<% @interests.in_groups_of(10, false) do |interests_group| %>
<% @user.interests.in_groups_of(10, false) do |interests_group| %>
<div class="small-4 column end">
<ul class="no-bullet">
<% interests_group.each do |interest| %>