Minimum required by consul core. Remove comments. Fix texts. Decrease size of methods.

This commit is contained in:
taitus
2017-08-02 00:15:03 +02:00
parent 33e13dbfd0
commit 52e3610876
5 changed files with 24 additions and 24 deletions

View File

@@ -20,12 +20,16 @@ module WelcomeHelper
end
def render_image(recommended, image_field, image_version, image_default)
image_path = if image_field.present? && image_version.present?
image_path = calculate_image_path(recommended, image_field, image_version, image_default)
image_tag(image_path) if image_path.present?
end
def calculate_image_path(recommended, image_field, image_version, image_default)
if image_field.present? && image_version.present?
recommended.send("#{image_field}", image_version)
elsif image_default.present?
image_default
end
image_tag(image_path) if image_path.present?
end
def calculate_carousel_size(debates, proposals, apply_offset)

View File

@@ -49,7 +49,6 @@ class Debate < ActiveRecord::Base
def self.recommendations(user)
debates_list = where("author_id != ?", user.id)
# same as tagged_with(user.interests, any: true)
debates_list_with_tagged = debates_list.joins(:tags).where('taggings.taggable_type = ?', self.name).where('tags.name IN (?)', user.interests)
if debates_list_with_tagged.any?
debates_list = debates_list_with_tagged

View File

@@ -59,17 +59,25 @@ class Proposal < ActiveRecord::Base
def self.recommendations(user)
proposals_list = where("author_id != ?", user.id)
# same as tagged_with(user.interests, any: true)
proposals_list_with_tagged = proposals_list.joins(:tags).where('taggings.taggable_type = ?', self.name)
.where('tags.name IN (?)', user.interests)
proposals_list_with_tagged = proposals_with_tagged(user, proposals_list)
if proposals_list_with_tagged.any?
followed_proposals_ids = Proposal.followed_by_user(user).pluck(:id)
proposals_list = proposals_list_with_tagged.where("proposals.id NOT IN (?)", followed_proposals_ids)
proposals_list = proposals_not_followed_by_user(user, proposals_list_with_tagged)
end
proposals_list
end
def proposals_with_tagged(user, proposals_list)
proposals_list.joins(:tags).where('taggings.taggable_type = ?', self.name)
.where('tags.name IN (?)', user.interests)
end
def proposals_not_followed_by_user(user, proposals_list_with_tagged)
followed_proposals_ids = Proposal.followed_by_user(user).pluck(:id)
proposals_list_with_tagged.where("proposals.id NOT IN (?)", followed_proposals_ids)
end
def to_param
"#{id}-#{title}".parameterize
end

View File

@@ -371,7 +371,7 @@ feature 'Debates' do
expect(page).not_to have_selector('a', text: 'recommendations')
end
scenario 'Debates are ordered by recommendations when there is an user logged', :js do
scenario 'Debates are ordered by recommendations when there is a user logged', :js do
user = create(:user)
login_as(user)

View File

@@ -38,17 +38,13 @@ feature "Home" do
scenario 'Display recommended section' do
debate = create(:debate)
visit root_path
expect(page).to have_content "Recommendations that may interest you"
end
scenario 'Display recommended section when feature flag recommended is active' do
debate = create(:debate)
visit root_path
expect(page).to have_content "Recommendations that may interest you"
end
@@ -72,9 +68,7 @@ feature "Home" do
scenario 'Display all recommended debates link' do
debate = create(:debate)
visit root_path
expect(page).to have_link("All recommended debates", href: debates_path(order: "recommendations"))
end
@@ -89,9 +83,7 @@ feature "Home" do
scenario 'Display all recommended proposals link' do
debate = create(:proposal)
visit root_path
expect(page).to have_link("All recommended proposals", href: proposals_path(order: "recommendations"))
end
@@ -116,17 +108,14 @@ feature "Home" do
scenario 'Do not display recommended section when there are not debates and proposals' do
visit root_path
expect(page).not_to have_content "Recommendations that may interest you"
end
feature 'Carousel size' do
scenario 'Display debates centered when there is not proposals' do
scenario 'Display debates centered when there are no proposals' do
debate = create(:debate)
visit root_path
expect(page).to have_selector('.medium-centered.large-centered')
end