Merge pull request #4763 from consul/refactor_votes

Refactor code showing in favor and against votes
This commit is contained in:
Javi Martín
2022-02-23 17:43:49 +01:00
committed by GitHub
66 changed files with 687 additions and 770 deletions

View File

@@ -1,15 +0,0 @@
(function() {
"use strict";
App.AllowParticipation = {
initialize: function() {
$(document).on({
"mouseenter focus": function() {
$(this).find(".js-participation-not-allowed").show();
},
mouseleave: function() {
$(this).find(".js-participation-not-allowed").hide();
}
}, ".js-participation");
}
};
}).call(this);

View File

@@ -66,7 +66,6 @@
//= require tags
//= require users
//= require votes
//= require allow_participation
//= require advanced_search
//= require registration_form
//= require suggest
@@ -124,7 +123,6 @@ var initialize_modules = function() {
App.Comments.initialize();
App.Users.initialize();
App.Votes.initialize();
App.AllowParticipation.initialize();
App.Tags.initialize();
App.FoundationExtras.initialize();
App.LocationChanger.initialize();

View File

@@ -5,11 +5,9 @@
$(document).on({
"mouseenter focus": function() {
$("div.participation-not-allowed", this).show();
$("div.participation-allowed", this).hide();
},
mouseleave: function() {
$("div.participation-not-allowed", this).hide();
$("div.participation-allowed", this).show();
}
}, votes);
},

View File

@@ -27,6 +27,7 @@
@import "milestones";
@import "pages";
@import "dashboard";
@import "in_favor_against";
@import "legislation";
@import "legislation_process";
@import "legislation_process_form";

View File

@@ -0,0 +1,97 @@
.in-favor-against {
display: inline-block;
.icon-like,
.icon-unlike {
background: #fff;
border: 2px solid;
border-radius: rem-calc(3);
color: $text-light;
display: inline-block;
font-size: rem-calc(30);
line-height: rem-calc(30);
padding: rem-calc(3) rem-calc(6);
position: relative;
&:hover,
&:active {
color: #fff;
cursor: pointer;
opacity: 1 !important;
}
}
.icon-like {
&:hover,
&:active {
background: $like;
border: 2px solid $like;
}
}
.icon-unlike {
&:hover,
&:active {
background: $unlike;
border: 2px solid $unlike;
}
}
.like,
.unlike {
line-height: rem-calc(48);
vertical-align: super;
text-decoration: none;
.percentage {
color: $text;
display: inline-block;
font-size: $small-font-size;
line-height: $line-height * 2;
padding-right: $line-height / 2;
vertical-align: top;
@include breakpoint(medium) {
display: block;
line-height: $line-height;
padding-right: 0;
}
}
}
.voted {
.icon-like,
.icon-unlike {
color: #fff;
}
.icon-like {
background: $like;
border: 2px solid $like;
}
.icon-unlike {
background: $unlike;
border: 2px solid $unlike;
}
}
.no-voted {
.icon-like,
.icon-unlike {
opacity: 0.3;
}
}
.against {
margin-left: $line-height / 4;
}
.divider {
margin: 0 rem-calc(6);
}
}

View File

@@ -2004,7 +2004,9 @@ table {
.comment-votes {
a {
a,
.icon-like,
.icon-unlike {
color: $text-light;
display: inline-block;
vertical-align: top;

View File

@@ -14,120 +14,6 @@
// 01. Votes and supports
// ----------------------
@mixin votes {
border-top: 1px solid $border;
margin-top: $line-height;
padding: $line-height / 2 0;
position: relative;
@include breakpoint(medium) {
border-left: 1px solid $border;
border-top: 0;
margin-top: 0;
}
.icon-like,
.icon-unlike {
background: #fff;
border: 2px solid;
border-radius: rem-calc(3);
color: $text-light;
display: inline-block;
font-size: rem-calc(30);
line-height: rem-calc(30);
padding: rem-calc(3) rem-calc(6);
position: relative;
&:hover,
&:active {
color: #fff;
cursor: pointer;
opacity: 1 !important;
}
}
.icon-like {
&:hover,
&:active {
background: $like;
border: 2px solid $like;
}
}
.icon-unlike {
&:hover,
&:active {
background: $unlike;
border: 2px solid $unlike;
}
}
.like,
.unlike {
line-height: rem-calc(48);
vertical-align: super;
text-decoration: none;
.percentage {
color: $text;
display: inline-block;
font-size: $small-font-size;
line-height: $line-height * 2;
padding-right: $line-height / 2;
vertical-align: top;
@include breakpoint(medium) {
display: block;
line-height: $line-height;
padding-right: 0;
}
}
}
.voted {
.icon-like,
.icon-unlike {
color: #fff;
}
.icon-like {
background: $like;
border: 2px solid $like;
}
.icon-unlike {
background: $unlike;
border: 2px solid $unlike;
}
}
.no-voted {
.icon-like,
.icon-unlike {
opacity: 0.3;
}
}
.total-votes {
font-weight: bold;
float: right;
line-height: $line-height * 2;
@include breakpoint(medium) {
display: block;
float: none;
}
}
.divider {
margin: 0 rem-calc(6);
}
}
@mixin supports {
padding: $line-height 0;
position: relative;
@@ -713,14 +599,27 @@
.legislation-proposals {
.votes {
@include votes;
border-top: 1px solid $border;
margin-top: $line-height;
padding: $line-height / 2 0;
position: relative;
@include breakpoint(medium) {
border-left: 1px solid $border;
border-top: 0;
margin-top: 0;
text-align: center;
}
.against {
margin-left: $line-height / 4;
.total-votes {
font-weight: bold;
float: right;
line-height: $line-height * 2;
@include breakpoint(medium) {
display: block;
float: none;
}
}
}
}
@@ -1038,6 +937,7 @@
content: none;
}
.progress,
.total-supports {
display: none;
}
@@ -1070,7 +970,11 @@
}
.supported {
background: none;
border: 0;
margin-bottom: 0;
margin-top: 0;
padding: 0;
font-size: $small-font-size;
}
}

View File

@@ -0,0 +1,51 @@
<div class="supports ballot">
<% if voted? %>
<div class="remove supported">
<span class="icon-check-circle"
title="<%= t("budgets.investments.investment.already_added") %>">
</span>
<p class="investment-project-amount">
<%= investment.formatted_price %>
</p>
<% if investment.should_show_ballots? %>
<%= link_to t("budgets.ballots.show.remove"),
budget_ballot_line_path(id: investment.id,
budget_id: investment.budget_id,
investments_ids: investment_ids),
class: "button button-remove-support expanded",
method: :delete,
remote: true %>
<% end %>
</div>
<% else %>
<div class="add in-favor">
<p class="investment-project-amount">
<%= investment.formatted_price %>
</p>
<% if investment.should_show_ballots? %>
<%= link_to t("budgets.investments.investment.add"),
budget_ballot_lines_path(investment_id: investment.id,
budget_id: investment.budget_id,
investments_ids: investment_ids),
class: "button button-support expanded",
title: t("budgets.investments.investment.support_title"),
method: :post,
remote: true %>
<% end %>
</div>
<% end %>
<% if reason.present? && !voted? %>
<div class="participation-not-allowed" style="display:none">
<p>
<small>
<%= sanitize(t("budgets.ballots.reasons_for_not_balloting.#{reason}",
verify_account: link_to_verify_account, signin: link_to_signin,
signup: link_to_signup, my_heading: link_to_my_heading,
change_ballot: link_to_change_ballot,
heading_link: heading_link(assigned_heading, budget))) %>
</small>
</p>
</div>
<% end %>
</div>

View File

@@ -0,0 +1,37 @@
class Budgets::Investments::BallotComponent < ApplicationComponent
attr_reader :investment, :investment_ids, :ballot, :assigned_heading
delegate :current_user, :heading_link, :link_to_signin, :link_to_signup,
:link_to_verify_account, to: :helpers
def initialize(investment:, investment_ids:, ballot:, assigned_heading:)
@investment = investment
@investment_ids = investment_ids
@ballot = ballot
@assigned_heading = assigned_heading
end
private
def budget
ballot.budget
end
def voted?
ballot.has_investment?(investment)
end
def reason
@reason ||= investment.reason_for_not_being_ballotable_by(current_user, ballot)
end
def link_to_my_heading
link_to(investment.heading.name,
budget_investments_path(budget_id: investment.budget_id,
heading_id: investment.heading_id))
end
def link_to_change_ballot
link_to(t("budgets.ballots.reasons_for_not_balloting.change_ballot"),
budget_ballot_path(budget))
end
end

View File

@@ -1,4 +1,4 @@
<div class="supports js-participation">
<div class="supports">
<span class="total-supports <%= "no-button" unless voting_allowed? || user_voted_for? %>">
<%= t("budgets.investments.investment.supports", count: investment.total_votes) %>
@@ -36,7 +36,7 @@
<% if reason.present? && !user_voted_for? %>
<div tabindex="0">
<div class="js-participation-not-allowed participation-not-allowed" style="display:none" aria-hidden="false">
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<small>
<%= sanitize(t("votes.budget_investments.#{reason}",

View File

@@ -1,6 +1,6 @@
class Budgets::Investments::VotesComponent < ApplicationComponent
attr_reader :investment
delegate :namespace, :current_user, :voted_for?, :image_absolute_url,
delegate :namespace, :current_user, :image_absolute_url,
:link_to_verify_account, :link_to_signin, :link_to_signup, to: :helpers
def initialize(investment)

View File

@@ -0,0 +1,44 @@
<div class="votes">
<%= t("comments.comment.votes", count: comment.total_votes) %>
&nbsp;|&nbsp;
<span class="in_favor">
<% if can?(:vote, comment) %>
<%= link_to vote_comment_path(comment, value: "yes"),
method: "post", remote: true, title: t("votes.agree") do %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<% end %>
<% else %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<% end %>
<%= comment.total_likes %>
</span>
<span class="against">
<% if can?(:vote, comment) %>
<%= link_to vote_comment_path(comment, value: "no"),
method: "post", remote: true, title: t("votes.disagree") do %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<% end %>
<% else %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<% end %>
<%= comment.total_dislikes %>
</span>
<% unless current_user %>
<div tabindex="0">
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<%= sanitize(t("votes.comment_unauthenticated", signin: link_to_signin, signup: link_to_signup)) %>
</div>
</div>
<% end %>
</div>

View File

@@ -0,0 +1,8 @@
class Comments::VotesComponent < ApplicationComponent
attr_reader :comment
delegate :current_user, :can?, :link_to_signin, :link_to_signup, to: :helpers
def initialize(comment)
@comment = comment
end
end

View File

@@ -0,0 +1,25 @@
<div class="votes">
<%= render Shared::InFavorAgainstComponent.new(debate) %>
<span class="total-votes">
<%= t("debates.debate.votes", count: debate.votes_score) %>
</span>
<% if !current_user %>
<div tabindex="0">
<%= render "shared/login_to_vote" %>
</div>
<% elsif organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif !can_vote? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("votes.anonymous", verify_account: link_to_verify_account)) %>
</p>
</div>
<% end %>
</div>

View File

@@ -0,0 +1,18 @@
class Debates::VotesComponent < ApplicationComponent
attr_reader :debate
delegate :current_user, :link_to_verify_account, to: :helpers
def initialize(debate)
@debate = debate
end
private
def can_vote?
debate.votable_by?(current_user)
end
def organization?
current_user&.organization?
end
end

View File

@@ -0,0 +1,38 @@
<div class="votes">
<% if proposal.process.proposals_phase.open? %>
<%= render Shared::InFavorAgainstComponent.new(proposal) %>
<% end %>
<span class="total-votes">
<%= t("proposals.proposal.votes", count: proposal.votes_score) %>
</span>
<% if !current_user %>
<div tabindex="0">
<%= render "shared/login_to_vote" %>
</div>
<% elsif organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif !can_vote? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("legislation.proposals.not_verified",
verify_account: link_to_verify_account)) %>
</p>
</div>
<% end %>
<% if current_user&.voted_as_when_voted_for(proposal) && setting["twitter_handle"] %>
<div class="share-supported">
<%= render "shared/social_share",
title: proposal.title,
url: proposal_url(proposal),
description: proposal.summary,
mobile: proposal.title %>
</div>
<% end %>
</div>

View File

@@ -0,0 +1,18 @@
class Legislation::Proposals::VotesComponent < ApplicationComponent
attr_reader :proposal
delegate :current_user, :link_to_verify_account, to: :helpers
def initialize(proposal)
@proposal = proposal
end
private
def can_vote?
proposal.votable_by?(current_user)
end
def organization?
current_user&.organization?
end
end

View File

@@ -0,0 +1,47 @@
<div class="supports text-center">
<%= render "proposals/supports", proposal: proposal %>
<div class="in-favor">
<% if voted? %>
<div class="supported callout success">
<%= t("proposals.proposal.already_supported") %>
</div>
<% elsif can_vote? %>
<%= link_to t("proposals.proposal.support"), vote_url,
class: "button button-support small expanded",
title: t("proposals.proposal.support_title"),
method: "post",
remote: true %>
<% else %>
<div class="button button-support small expanded">
<%= t("proposals.proposal.support") %>
</div>
<% end %>
</div>
<% if !current_user %>
<div tabindex="0">
<%= render "shared/login_to_vote" %>
</div>
<% elsif organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif !can_vote? %>
<div tabindex="0">
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("votes.verified_only", verify_account: link_to_verify_account)) %>
</p>
</div>
</div>
<% end %>
<% if voted? && setting["twitter_handle"] %>
<div class="share-supported">
<%= render "proposals/social_share", proposal: proposal, share_title: false %>
</div>
<% end %>
</div>

View File

@@ -0,0 +1,27 @@
class Proposals::VotesComponent < ApplicationComponent
attr_reader :proposal
delegate :current_user, :link_to_verify_account, to: :helpers
def initialize(proposal, vote_url: nil)
@proposal = proposal
@vote_url = vote_url
end
def vote_url
@vote_url || vote_proposal_path(proposal, value: "yes")
end
private
def voted?
current_user&.voted_for?(proposal)
end
def can_vote?
proposal.votable_by?(current_user)
end
def organization?
current_user&.organization?
end
end

View File

@@ -0,0 +1,40 @@
<div class="in-favor-against">
<div class="in-favor inline-block">
<% if current_user %>
<%= link_to polymorphic_path(votable, action: :vote, value: "yes"),
class: "like #{voted_classes[:in_favor]}", title: t("votes.agree"), method: "post", remote: true do %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<span class="percentage"><%= votes_percentage("likes", votable) %></span>
<% end %>
<% else %>
<div class="like">
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<span class="percentage"><%= votes_percentage("likes", votable) %></span>
</div>
<% end %>
</div>
<span class="divider"></span>
<div class="against inline-block">
<% if current_user %>
<%= link_to polymorphic_path(votable, action: :vote, value: "no"), class: "unlike #{voted_classes[:against]}", title: t("votes.disagree"), method: "post", remote: true do %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<span class="percentage"><%= votes_percentage("dislikes", votable) %></span>
<% end %>
<% else %>
<div class="unlike">
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<span class="percentage"><%= votes_percentage("dislikes", votable) %></span>
</div>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,25 @@
class Shared::InFavorAgainstComponent < ApplicationComponent
attr_reader :votable
delegate :current_user, :votes_percentage, to: :helpers
def initialize(votable)
@votable = votable
end
private
def voted_classes
@voted_classes ||= css_classes_for_vote
end
def css_classes_for_vote
case current_user&.voted_as_when_voted_for(votable)
when true
{ in_favor: "voted", against: "no-voted" }
when false
{ in_favor: "no-voted", against: "voted" }
else
{ in_favor: "", against: "" }
end
end
end

View File

@@ -68,14 +68,6 @@ class ApplicationController < ActionController::Base
end
end
def set_debate_votes(debates)
@debate_votes = current_user ? current_user.debate_votes(debates) : {}
end
def set_proposal_votes(proposals)
@proposal_votes = current_user ? current_user.proposal_votes(proposals) : {}
end
def set_comment_flags(comments)
@comment_flags = current_user ? current_user.comment_flags(comments) : {}
end

View File

@@ -17,14 +17,11 @@ module CommentableActions
@tag_cloud = tag_cloud
set_resource_votes(@resources)
set_resources_instance
@remote_translations = detect_remote_translations(@resources, featured_proposals)
end
def show
set_resource_votes(resource)
@commentable = resource
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
set_comment_flags(@comment_tree.comments)
@@ -99,10 +96,6 @@ module CommentableActions
@categories = Tag.category.order(:name)
end
def set_resource_votes(instance)
send("set_#{resource_name}_votes", instance)
end
def index_customization
nil
end

View File

@@ -30,7 +30,6 @@ class DebatesController < ApplicationController
def vote
@debate.register_vote(current_user, params[:value])
set_debate_votes(@debate)
end
def unmark_featured

View File

@@ -2,8 +2,4 @@ class Legislation::BaseController < ApplicationController
include FeatureFlags
feature_flag :legislation
def legislation_proposal_votes(proposals)
@legislation_proposal_votes = current_user ? current_user.legislation_proposal_votes(proposals) : {}
end
end

View File

@@ -124,7 +124,6 @@ class Legislation::ProcessesController < Legislation::BaseController
end
if @process.proposals_phase.started? || current_user&.administrator?
legislation_proposal_votes(@proposals)
render :proposals
else
render :phase_not_open

View File

@@ -3,16 +3,15 @@ class Legislation::ProposalsController < Legislation::BaseController
include FlagActions
include ImageAttributes
before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary]
before_action :load_categories, only: [:new, :create, :edit, :map, :summary]
before_action :load_geozones, only: [:edit, :map, :summary]
before_action :authenticate_user!, except: [:index, :show, :map, :summary]
before_action :authenticate_user!, except: [:show, :map, :summary]
load_and_authorize_resource :process, class: "Legislation::Process"
load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process
invisible_captcha only: [:create, :update], honeypot: :subtitle
has_orders %w[confidence_score created_at], only: :index
has_orders %w[most_voted newest oldest], only: :show
helper_method :resource_model, :resource_name
@@ -20,7 +19,6 @@ class Legislation::ProposalsController < Legislation::BaseController
def show
super
legislation_proposal_votes(@process.proposals)
@document = Document.new(documentable: @proposal)
if request.path != legislation_process_proposal_path(params[:process_id], @proposal)
redirect_to legislation_process_proposal_path(params[:process_id], @proposal),
@@ -38,14 +36,8 @@ class Legislation::ProposalsController < Legislation::BaseController
end
end
def index_customization
load_successful_proposals
load_featured unless @proposal_successful_exists
end
def vote
@proposal.register_vote(current_user, params[:value])
legislation_proposal_votes(@proposal)
end
private
@@ -65,8 +57,4 @@ class Legislation::ProposalsController < Legislation::BaseController
def resource_name
"proposal"
end
def load_successful_proposals
@proposal_successful_exists = Legislation::Proposal.successful.exists?
end
end

View File

@@ -37,12 +37,10 @@ class Management::ProposalsController < Management::BaseController
def vote
@follow = Follow.find_or_create_by!(user: current_user, followable: @proposal)
@proposal.register_vote(managed_user, "yes")
set_proposal_votes(@proposal)
end
def print
@proposals = Proposal.send("sort_by_#{@current_order}").for_render.limit(5)
set_proposal_votes(@proposal)
end
private
@@ -66,10 +64,6 @@ class Management::ProposalsController < Management::BaseController
check_verified_user t("management.proposals.alert.unverified_user")
end
def set_proposal_votes(proposals)
@proposal_votes = managed_user ? managed_user.proposal_votes(proposals) : {}
end
def set_comment_flags(comments)
@comment_flags = managed_user ? managed_user.comment_flags(comments) : {}
end

View File

@@ -58,7 +58,6 @@ class ProposalsController < ApplicationController
def vote
@follow = Follow.find_or_create_by!(user: current_user, followable: @proposal)
@proposal.register_vote(current_user, "yes")
set_proposal_votes(@proposal)
end
def retire
@@ -72,12 +71,6 @@ class ProposalsController < ApplicationController
def retire_form
end
def vote_featured
@follow = Follow.find_or_create_by!(user: current_user, followable: @proposal)
@proposal.register_vote(current_user, "yes")
set_featured_proposal_votes(@proposal)
end
def summary
@proposals = Proposal.for_summary
@tag_cloud = tag_cloud
@@ -118,10 +111,6 @@ class ProposalsController < ApplicationController
Proposal
end
def set_featured_proposal_votes(proposals)
@featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {}
end
def discard_draft
@resources = @resources.published
end
@@ -156,7 +145,6 @@ class ProposalsController < ApplicationController
@featured_proposals = Proposal.not_archived.unsuccessful
.sort_by_confidence_score.limit(Setting["featured_proposals_number"])
if @featured_proposals.present?
set_featured_proposal_votes(@featured_proposals)
@resources = @resources.where.not(id: @featured_proposals)
end
end

View File

@@ -12,19 +12,4 @@ module VotesHelper
"#{100 - debate_percentage_of_likes(debate)}%"
end
end
def css_classes_for_vote(votes, votable)
case votes[votable.id]
when true
{ in_favor: "voted", against: "no-voted" }
when false
{ in_favor: "no-voted", against: "voted" }
else
{ in_favor: "", against: "" }
end
end
def voted_for?(votes, votable)
votes[votable.id]
end
end

View File

@@ -85,10 +85,8 @@ module Abilities
if user.level_two_or_three_verified?
can :vote, Proposal, &:published?
can :vote_featured, Proposal
can :vote, Legislation::Proposal
can :vote_featured, Legislation::Proposal
can :create, Legislation::Answer
can :create, Budget::Investment, budget: { phase: "accepting" }

View File

@@ -147,21 +147,6 @@ class User < ApplicationRecord
organization? ? organization.name : username
end
def debate_votes(debates)
voted = votes.for_debates(Array(debates).map(&:id))
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
end
def proposal_votes(proposals)
voted = votes.for_proposals(Array(proposals).map(&:id))
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
end
def legislation_proposal_votes(proposals)
voted = votes.for_legislation_proposals(proposals)
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
end
def comment_flags(comments)
comment_flags = flags.for_comments(comments)
comment_flags.each_with_object({}) { |f, h| h[f.flaggable_id] = true }

View File

@@ -1,64 +1,6 @@
<% reason = investment.reason_for_not_being_ballotable_by(current_user, ballot) %>
<div class="js-participation supports ballot">
<% if ballot.has_investment?(investment) %>
<div class="remove supported">
<span class="icon-check-circle"
title="<%= t("budgets.investments.investment.already_added") %>">
</span>
<p class="investment-project-amount">
<%= investment.formatted_price %>
</p>
<% if investment.should_show_ballots? %>
<%= link_to t("budgets.ballots.show.remove"),
budget_ballot_line_path(id: investment.id,
budget_id: investment.budget_id,
investments_ids: investment_ids),
class: "button button-remove-support expanded",
method: :delete,
remote: true %>
<% end %>
</div>
<% else %>
<div class="add in-favor">
<p class="investment-project-amount">
<%= investment.formatted_price %>
</p>
<% if investment.should_show_ballots? %>
<%= link_to t("budgets.investments.investment.add"),
budget_ballot_lines_path(investment_id: investment.id,
budget_id: investment.budget_id,
investments_ids: investment_ids),
class: "button button-support expanded",
title: t("budgets.investments.investment.support_title"),
method: :post,
remote: true %>
<% end %>
</div>
<% end %>
<% if reason.present? && !ballot.has_investment?(investment) %>
<div class="js-participation-not-allowed participation-not-allowed" style="display:none">
<% my_heading = link_to(investment.heading.name,
budget_investments_path(budget_id: investment.budget_id,
heading_id: investment.heading_id)) %>
<% change_ballot = link_to(t("budgets.ballots.reasons_for_not_balloting.change_ballot"),
budget_ballot_path(@budget)) %>
<p>
<small>
<%= sanitize(t("budgets.ballots.reasons_for_not_balloting.#{reason}",
verify_account: link_to_verify_account, signin: link_to_signin,
signup: link_to_signup, my_heading: my_heading,
change_ballot: change_ballot,
heading_link: heading_link(@assigned_heading, @budget))) %>
</small>
</p>
</div>
<% end %>
</div>
<%= render Budgets::Investments::BallotComponent.new(
investment: investment,
investment_ids: investment_ids,
ballot: ballot,
assigned_heading: @assigned_heading
) %>

View File

@@ -39,7 +39,7 @@
<% elsif investment.should_show_vote_count? %>
<div id="<%= dom_id(investment) %>_votes"
class="small-12 medium-3 column text-center">
<div class="supports js-participation">
<div class="supports">
<span class="total-supports no-button">
<%= t("budgets.investments.investment.supports",
count: investment.total_votes) %>

View File

@@ -1,87 +1 @@
<div class="votes">
<% if user_signed_in? %>
<%= t("comments.comment.votes", count: comment.total_votes) %>
&nbsp;|&nbsp;
<span class="in_favor">
<% if can?(:vote, comment) %>
<%= link_to vote_comment_path(comment, value: "yes"),
method: "post", remote: true, title: t("votes.agree") do %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<% end %>
<% else %>
<%= link_to new_user_session_path do %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<% end %>
<% end %>
<%= comment.total_likes %>
</span>
<span class="against">
<% if can?(:vote, comment) %>
<%= link_to vote_comment_path(comment, value: "no"),
method: "post", remote: true, title: t("votes.disagree") do %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<% end %>
<% else %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<% end %>
<%= comment.total_dislikes %>
</span>
<% elsif !user_signed_in? %>
<div class="participation-allowed">
<%= t("comments.comment.votes", count: comment.total_votes) %>
&nbsp;|&nbsp;
<span class="in_favor">
<% if can?(:vote, comment) %>
<%= link_to vote_comment_path(comment, value: "yes"),
method: "post", remote: true, title: t("votes.agree") do %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<% end %>
<% else %>
<%= link_to new_user_session_path do %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<% end %>
<% end %>
<%= comment.total_likes %>
</span>
<span class="against">
<% if can?(:vote, comment) %>
<%= link_to vote_comment_path(comment, value: "no"),
method: "post", remote: true, title: t("votes.disagree") do %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<% end %>
<% else %>
<%= link_to new_user_session_path do %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<% end %>
<% end %>
<%= comment.total_dislikes %>
</span>
</div>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<%= sanitize(t("votes.comment_unauthenticated", signin: link_to_signin, signup: link_to_signup)) %>
</div>
<% end %>
</div>
<%= render Comments::VotesComponent.new(comment) %>

View File

@@ -1,4 +1,4 @@
<% cache [locale_and_user_status, debate, @debate_votes[debate.id]] do %>
<% cache [locale_and_user_status, debate, current_user&.voted_as_when_voted_for(debate)] do %>
<div id="<%= dom_id(debate) %>" class="debate clear" data-type="debate">
<div class="panel">
<div class="row">

View File

@@ -4,7 +4,7 @@
<div class="small-12 column">
<div class="debate-content">
<% cache [locale_and_user_status,
"index_minimal", debate, @debate_votes[debate.id]] do %>
"index_minimal", debate, current_user&.voted_as_when_voted_for(debate)] do %>
<h3><%= link_to debate.title, debate %></h3>
<% end %>
</div>

View File

@@ -1,63 +1 @@
<% voted_classes = css_classes_for_vote(@debate_votes, debate) %>
<div class="votes">
<div class="in-favor inline-block">
<% if user_signed_in? %>
<%= link_to vote_debate_path(debate, value: "yes"),
class: "like #{voted_classes[:in_favor]}", title: t("votes.agree"), method: "post", remote: true do %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<span class="percentage"><%= votes_percentage("likes", debate) %></span>
<% end %>
<% else %>
<div class="like">
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<span class="percentage"><%= votes_percentage("likes", debate) %></span>
</div>
<% end %>
</div>
<span class="divider"></span>
<div class="against inline-block">
<% if user_signed_in? %>
<%= link_to vote_debate_path(debate, value: "no"), class: "unlike #{voted_classes[:against]}", title: t("votes.disagree"), method: "post", remote: true do %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<span class="percentage"><%= votes_percentage("dislikes", debate) %></span>
<% end %>
<% else %>
<div class="unlike">
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<span class="percentage"><%= votes_percentage("dislikes", debate) %></span>
</div>
<% end %>
</div>
<span class="total-votes">
<%= t("debates.debate.votes", count: debate.votes_score) %>
</span>
<% if user_signed_in? && current_user.organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !debate.votable_by?(current_user) %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("votes.anonymous", verify_account: link_to_verify_account)) %>
</p>
</div>
<% elsif !user_signed_in? %>
<div tabindex="0">
<%= render "shared/login_to_vote" %>
</div>
<% end %>
</div>
<%= render Debates::VotesComponent.new(debate) %>

View File

@@ -3,7 +3,11 @@
<%= render "shared/canonical", href: debate_url(@debate) %>
<% end %>
<% cache [locale_and_user_status(@debate), @debate, @debate.author, Flag.flagged?(current_user, @debate), @debate_votes] do %>
<% cache [locale_and_user_status(@debate),
@debate,
@debate.author,
Flag.flagged?(current_user, @debate),
current_user&.voted_as_when_voted_for(@debate)] do %>
<div class="debate-show">
<div id="<%= dom_id(@debate) %>" class="row">
<div class="small-12 medium-9 column">

View File

@@ -1,27 +0,0 @@
<div id="<%= dom_id(proposal) %>" class="proposal-featured clear">
<div class="small-12 medium-9 column">
<h3><%= link_to proposal.title, proposal %></h3>
<div class="info">
<% if proposal.author.hidden? || proposal.author.erased? %>
<%= t("proposals.show.author_deleted") %>
<% else %>
<%= proposal.author.name %>
<% end %>
&nbsp;&bull;&nbsp;
<% if proposal.author.display_official_position_badge? %>
<span class="label round level-<%= proposal.author.official_level %>">
<%= proposal.author.official_position %>
</span>
&nbsp;&bull;&nbsp;
<% end %>
<strong><%= t("proposals.proposal.votes", count: proposal.total_votes) %></strong>
</div>
</div>
<div id="<%= dom_id(proposal) %>_votes" class="small-12 medium-3 column">
<%= render "featured_votes", proposal: proposal %>
</div>
</div>

View File

@@ -1,43 +0,0 @@
<div class="supports text-center">
<div class="in-favor">
<% if voted_for?(@featured_proposals_votes, proposal) %>
<div class="supported">
<%= t("proposals.proposal.already_supported") %>
</div>
<% else %>
<%= link_to vote_featured_proposal_path(proposal, value: "yes"),
class: "button button-support small expanded",
title: t("proposals.proposal.support_title"), method: "post", remote: true do %>
<%= t("proposals.proposal.support") %>
<% end %>
<% end %>
</div>
<% if user_signed_in? && current_user.organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !proposal.votable_by?(current_user) %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("votes.verified_only", verify_account: link_to_verify_account)) %>
</p>
</div>
<% elsif !user_signed_in? %>
<%= render "shared/login_to_vote" %>
<% end %>
<% if voted_for?(@featured_proposals_votes, proposal) %>
<% if setting["twitter_handle"] %>
<div class="share-supported">
<%= render "shared/social_share",
title: proposal.title,
url: proposal_url(proposal),
description: proposal.summary,
mobile: proposal.title %>
</div>
<% end %>
<% end %>
</div>

View File

@@ -1,6 +0,0 @@
<div class="sidebar-divider"></div>
<h2 class="sidebar-title"><%= t("shared.tags_cloud.districts") %></h2>
<br>
<%= link_to map_proposals_path, id: "map", title: t("shared.tags_cloud.districts_list") do %>
<%= image_tag(image_path_for("map.jpg", alt: t("shared.tags_cloud.districts_list"))) %>
<% end %>

View File

@@ -1,6 +0,0 @@
<div class="sidebar-divider"></div>
<h2 class="sidebar-title"><%= t("proposals.index.top") %></h2>
<p>
<%= link_to t("proposals.index.top_link_proposals"), summary_proposals_path, class: "small" %><br>
</p>

View File

@@ -1,76 +1 @@
<% voted_classes = css_classes_for_vote(@legislation_proposal_votes, proposal) %>
<div class="votes">
<% if @process.proposals_phase.open? %>
<div class="in-favor inline-block">
<% if user_signed_in? %>
<%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: "yes"),
class: "like #{voted_classes[:in_favor]}", title: t("votes.agree"), method: "post", remote: true do %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<span class="percentage"><%= votes_percentage("likes", proposal) %></span>
<% end %>
<% else %>
<div class="like">
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<span class="percentage"><%= votes_percentage("likes", proposal) %></span>
</div>
<% end %>
</div>
<span class="divider"></span>
<div class="against inline-block">
<% if user_signed_in? %>
<%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: "no"), class: "unlike #{voted_classes[:against]}", title: t("votes.disagree"), method: "post", remote: true do %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<span class="percentage"><%= votes_percentage("dislikes", proposal) %></span>
<% end %>
<% else %>
<div class="unlike">
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<span class="percentage"><%= votes_percentage("dislikes", proposal) %></span>
</div>
<% end %>
</div>
<% end %>
<span class="total-votes">
<%= t("proposals.proposal.votes", count: proposal.votes_score) %>
</span>
<% if user_signed_in? && current_user.organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !proposal.votable_by?(current_user) %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("legislation.proposals.not_verified",
verify_account: link_to_verify_account)) %>
</p>
</div>
<% elsif !user_signed_in? %>
<div tabindex="0">
<%= render "shared/login_to_vote" %>
</div>
<% end %>
<% if voted_for?(@legislation_proposal_votes, proposal) && setting["twitter_handle"] %>
<div class="share-supported">
<%= render "shared/social_share",
title: proposal.title,
url: proposal_url(proposal),
description: proposal.summary,
mobile: proposal.title %>
</div>
<% end %>
</div>
<%= render Legislation::Proposals::VotesComponent.new(proposal) %>

View File

@@ -21,7 +21,11 @@
</div>
</div>
<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @legislation_proposal_votes] do %>
<% cache [locale_and_user_status(@proposal),
@proposal,
@proposal.author,
Flag.flagged?(current_user, @proposal),
current_user&.voted_as_when_voted_for(@proposal)] do %>
<div class="proposal-show legislation-proposal-show">
<div id="<%= dom_id(@proposal) %>" class="row">
<div class="small-12 medium-9 column">

View File

@@ -22,6 +22,6 @@
</div>
<div id="<%= dom_id(proposal) %>_votes" class="small-12 medium-3 column">
<%= render "featured_votes", proposal: proposal %>
<%= render Proposals::VotesComponent.new(proposal) %>
</div>
</div>

View File

@@ -1,43 +0,0 @@
<div class="supports text-center">
<div class="in-favor">
<% if voted_for?(@featured_proposals_votes, proposal) %>
<div class="supported">
<%= t("proposals.proposal.already_supported") %>
</div>
<% else %>
<%= link_to vote_featured_proposal_path(proposal, value: "yes"),
class: "button button-support small expanded",
title: t("proposals.proposal.support_title"), method: "post", remote: true do %>
<%= t("proposals.proposal.support") %>
<% end %>
<% end %>
</div>
<% if user_signed_in? && current_user.organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !proposal.votable_by?(current_user) %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("votes.verified_only", verify_account: link_to_verify_account)) %>
</p>
</div>
<% elsif !user_signed_in? %>
<%= render "shared/login_to_vote" %>
<% end %>
<% if voted_for?(@featured_proposals_votes, proposal) %>
<% if setting["twitter_handle"] %>
<div class="share-supported">
<%= render "shared/social_share",
title: proposal.title,
url: proposal_url(proposal),
description: proposal.summary,
mobile: proposal.title %>
</div>
<% end %>
<% end %>
</div>

View File

@@ -77,8 +77,7 @@
<p><%= t("proposals.proposal.archived") %></p>
</div>
<% else %>
<%= render "votes",
{ proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %>
<%= render "votes", proposal: proposal %>
<% end %>
</div>
<% end %>

View File

@@ -32,7 +32,7 @@
<p><%= t("proposals.proposal.archived") %></p>
</div>
<% else %>
<%= render "votes", { proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %>
<%= render "votes", proposal: proposal %>
<% end %>
</div>
</div>

View File

@@ -1,47 +1 @@
<div class="supports text-center">
<%= render "proposals/supports", proposal: proposal %>
<div class="in-favor">
<% if voted_for?(@proposal_votes, proposal) %>
<div class="supported callout success">
<%= t("proposals.proposal.already_supported") %>
</div>
<% elsif user_signed_in? && proposal.votable_by?(current_user) %>
<%= link_to vote_url,
class: "button button-support small expanded",
title: t("proposals.proposal.support_title"), method: "post", remote: true do %>
<%= t("proposals.proposal.support") %>
<% end %>
<% else %>
<div class="button button-support small expanded">
<%= t("proposals.proposal.support") %>
</div>
<% end %>
</div>
<% if user_signed_in? && current_user.organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !proposal.votable_by?(current_user) %>
<div tabindex="0">
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("votes.verified_only", verify_account: link_to_verify_account)) %>
</p>
</div>
</div>
<% elsif !user_signed_in? %>
<div tabindex="0">
<%= render "shared/login_to_vote" %>
</div>
<% end %>
<% if voted_for?(@proposal_votes, proposal) && setting["twitter_handle"] %>
<div class="share-supported">
<%= render "proposals/social_share", proposal: proposal, share_title: false %>
</div>
<% end %>
</div>
<%= render Proposals::VotesComponent.new(proposal, vote_url: local_assigns[:vote_url]) %>

View File

@@ -9,7 +9,11 @@
<%= render "shared/canonical", href: proposal_url(@proposal) %>
<% end %>
<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %>
<% cache [locale_and_user_status(@proposal),
@proposal,
@proposal.author,
Flag.flagged?(current_user, @proposal),
current_user&.voted_for?(@proposal)] do %>
<div id="<%= dom_id(@proposal) %>" class="row">
<div class="small-12 medium-8 column">

View File

@@ -18,7 +18,7 @@
@proposal.author,
Flag.flagged?(current_user, @proposal),
@proposal.followed_by?(current_user),
@proposal_votes] do %>
current_user&.voted_for?(@proposal)] do %>
<div class="proposal-show">
<div id="<%= dom_id(@proposal) %>" class="row">
<div class="small-12 medium-9 column">

View File

@@ -1 +0,0 @@
$("#<%= dom_id(@proposal) %>_votes").html("<%= j render("proposals/featured_votes", proposal: @proposal) %>");

View File

@@ -1,2 +1 @@
<%= render "proposals/votes",
{ proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %>
<%= render "proposals/votes", proposal: proposal %>

View File

@@ -376,7 +376,6 @@ en:
select_order_long: "You are viewing proposals according to:"
start_proposal: Create a proposal
title: Proposals
top: Top weekly
top_link_proposals: The most supported proposals by category
section_header:
icon_alt: Proposals icon

View File

@@ -376,7 +376,6 @@ es:
select_order_long: "Estas viendo las propuestas"
start_proposal: Crea una propuesta
title: Propuestas ciudadanas
top: Top semanal
top_link_proposals: Propuestas más apoyadas por categoría
section_header:
icon_alt: Icono de Propuestas

View File

@@ -14,7 +14,7 @@ namespace :legislation do
resources :answers, only: [:create]
end
resources :proposals do
resources :proposals, except: [:index] do
member do
post :vote
put :flag

View File

@@ -34,7 +34,6 @@ resources :proposals do
member do
post :vote
post :vote_featured
put :flag
put :unflag
get :retire_form

View File

@@ -0,0 +1,29 @@
require "rails_helper"
describe Debates::VotesComponent do
let(:debate) { create(:debate, title: "What about the 2030 agenda?") }
let(:component) { Debates::VotesComponent.new(debate) }
describe "Agree and disagree links" do
it "is shown as plain text to anonymous users" do
render_inline component
expect(page).to have_content "I agree"
expect(page).to have_content "I disagree"
expect(page).to have_content "You must sign in or sign up to continue."
expect(page).not_to have_link "I agree"
expect(page).not_to have_link "I disagree"
end
it "is shown to identified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_link count: 2
expect(page).to have_link "I agree", title: "I agree"
expect(page).to have_link "I disagree", title: "I disagree"
expect(page).not_to have_content "You must sign in or sign up to continue."
end
end
end

View File

@@ -0,0 +1,42 @@
require "rails_helper"
describe Legislation::Proposals::VotesComponent do
let(:proposal) { create(:legislation_proposal, title: "Require wearing masks at home") }
let(:component) { Legislation::Proposals::VotesComponent.new(proposal) }
describe "Agree and disagree links" do
it "is not shown when the proposals phase isn't open" do
proposal.process.update!(
proposals_phase_start_date: 2.days.ago,
proposals_phase_end_date: Date.yesterday
)
sign_in(create(:user))
render_inline component
expect(page).not_to have_content "I agree"
expect(page).not_to have_content "I disagree"
end
it "is shown as plain text to anonymous users" do
render_inline component
expect(page).to have_content "I agree"
expect(page).to have_content "I disagree"
expect(page).to have_content "You must sign in or sign up to continue."
expect(page).not_to have_link "I agree"
expect(page).not_to have_link "I disagree"
end
it "is shown to identified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_link count: 2
expect(page).to have_link "I agree", title: "I agree"
expect(page).to have_link "I disagree", title: "I disagree"
expect(page).not_to have_content "You must sign in or sign up to continue."
end
end
end

View File

@@ -0,0 +1,77 @@
require "rails_helper"
describe Proposals::VotesComponent do
let(:proposal) { create(:proposal, title: "Create a monthly transport ticket") }
let(:component) { Proposals::VotesComponent.new(proposal) }
describe "support proposal link" do
it "is shown as plain text to unverified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_content "Support"
expect(page).not_to have_link "Support"
end
it "is shown to verified users" do
sign_in(create(:user, :level_two))
render_inline component
expect(page).to have_link count: 1
expect(page).to have_link "Support", title: "Support this proposal"
expect(page).not_to have_content "You have already supported this proposal. Share it!"
end
it "is replaced with a success message when the proposal is already supported" do
sign_in(create(:user, :level_two, votables: [proposal]))
render_inline component
expect(page).to have_content "You have already supported this proposal. Share it!"
expect(page).not_to have_link "Support"
end
end
describe "participation not allowed" do
it "asks anonymous users to sign in or sign up" do
render_inline component
expect(page).to have_link "sign in", visible: :hidden
expect(page).to have_link "sign up", visible: :hidden
end
it "says voting is not allowed to organizations" do
sign_in(create(:organization, user: create(:user, :level_two)).user)
render_inline component
expect(page).to have_content "Organizations are not permitted to vote"
expect(page).not_to have_link "sign in", visible: :all
expect(page).not_to have_link "sign up", visible: :all
end
it "says only verified users can vote to unverified users" do
sign_in(create(:user))
render_inline component
expect(page).to have_content "Only verified users can vote on proposals"
expect(page).to have_link "verify your account", visible: :hidden
expect(page).not_to have_link "sign in", visible: :all
expect(page).not_to have_link "sign up", visible: :all
end
it "is not rendered for verified users" do
sign_in(create(:user, :level_two))
render_inline component
expect(page).not_to have_css ".participation-not-allowed"
expect(page).not_to have_link "verify your account", visible: :all
expect(page).not_to have_link "sign in", visible: :all
expect(page).not_to have_link "sign up", visible: :all
end
end
end

View File

@@ -1,22 +1,6 @@
require "rails_helper"
describe VotesHelper do
describe "#voted_for?" do
it "returns true if voted for a proposal" do
proposal = create(:proposal)
votes = { proposal.id => true }
expect(voted_for?(votes, proposal)).to eq(true)
end
it "returns false if not voted for a proposals" do
proposal = create(:proposal)
votes = { proposal.id => nil }
expect(voted_for?(votes, proposal)).to eq(nil)
end
end
describe "#votes_percentage" do
it "alwayses sum 100%" do
debate = create(:debate)

View File

@@ -69,7 +69,6 @@ describe Abilities::Common do
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:vote, Proposal) }
it { should_not be_able_to(:vote_featured, Proposal) }
it { should_not be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_moderator, debate) }
@@ -212,7 +211,6 @@ describe Abilities::Common do
describe "Proposal" do
it { should be_able_to(:vote, Proposal) }
it { should be_able_to(:vote_featured, Proposal) }
end
describe "Direct Message" do
@@ -292,7 +290,6 @@ describe Abilities::Common do
before { user.update(verified_at: Time.current) }
it { should be_able_to(:vote, Proposal) }
it { should be_able_to(:vote_featured, Proposal) }
it { should be_able_to(:new, DirectMessage) }
it { should be_able_to(:create, DirectMessage) }

View File

@@ -33,28 +33,6 @@ describe User do
end
end
describe "#debate_votes" do
let(:user) { create(:user) }
it "returns {} if no debate" do
expect(user.debate_votes([])).to eq({})
end
it "returns a hash of debates ids and votes" do
debate1 = create(:debate)
debate2 = create(:debate)
debate3 = create(:debate)
create(:vote, voter: user, votable: debate1, vote_flag: true)
create(:vote, voter: user, votable: debate3, vote_flag: false)
voted = user.debate_votes([debate1, debate2, debate3])
expect(voted[debate1.id]).to eq(true)
expect(voted[debate2.id]).to eq(nil)
expect(voted[debate3.id]).to eq(false)
end
end
describe "#comment_flags" do
let(:user) { create(:user) }

View File

@@ -8,8 +8,6 @@ module Votes
within(".participation-not-allowed") do
expect(page).to have_content "You must sign in or sign up to vote"
end
expect(page).not_to have_selector(".participation-allowed")
end
def expect_message_to_many_anonymous_votes

View File

@@ -181,28 +181,6 @@ describe "Votes" do
describe "Proposals" do
before { login_as(verified) }
scenario "Index shows user votes on proposals" do
proposal1 = create(:proposal, voters: [verified])
proposal2 = create(:proposal)
proposal3 = create(:proposal)
visit proposals_path
within("#proposals") do
within("#proposal_#{proposal1.id}_votes") do
expect(page).to have_content "You have already supported this proposal. Share it!"
end
within("#proposal_#{proposal2.id}_votes") do
expect(page).not_to have_content "You have already supported this proposal. Share it!"
end
within("#proposal_#{proposal3.id}_votes") do
expect(page).not_to have_content "You have already supported this proposal. Share it!"
end
end
end
describe "Single proposal" do
let!(:proposal) { create(:proposal) }