Skip to content

Commit

Permalink
Merge branch 'voting-proposals' of github.com:consul/consul into voti…
Browse files Browse the repository at this point in the history
…ng-proposals
  • Loading branch information
decabeza committed Sep 12, 2016
2 parents 77077b2 + e330b70 commit 6fac3c6
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def show

def index_customization
load_retired
load_featured
load_proposal_ballots
load_featured if @proposal_ballots.blank?
end

def vote
Expand Down
1 change: 0 additions & 1 deletion app/models/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Proposal < ActiveRecord::Base
scope :sort_by_random, -> { reorder("RANDOM()") }
scope :sort_by_relevance, -> { all }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :archived, -> { where("proposals.created_at <= ?", 1.year.ago)}
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
scope :retired, -> { where.not(retired_at: nil) }
scope :not_retired, -> { where(retired_at: nil) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div id="<%= dom_id(proposal) %>" class="proposal-sucessfull">
<div id="<%= dom_id(proposal) %>_next_voting" class="proposal-sucessfull">
<h3><%= link_to proposal.title, proposal_ballots_path %></h3>
</div>
2 changes: 1 addition & 1 deletion app/views/proposals/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<% end %>

<% if @proposal_ballots.present? %>
<div class="row featured-proposals-ballot-banner margin-bottom">
<div id="next-voting" class="row featured-proposals-ballot-banner margin-bottom">
<div class="small-12 column padding">
<div class="icon-successfull"></div>
<h2>
Expand Down
20 changes: 10 additions & 10 deletions app/views/proposals/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@
<aside class="small-12 medium-3 column">
<div class="sidebar-divider"></div>
<h3><%= t("votes.supports") %></h3>
<% if @proposal.successfull? %>
<p>
<%= t("proposal_ballots.successfull",
voting: link_to(t("proposal_ballots.voting"), proposal_ballots_path)).html_safe %>
</p>
<% else %>
<div class="text-center">
<div id="<%= dom_id(@proposal) %>_votes">
<div id="<%= dom_id(@proposal) %>_votes">
<% if @proposal.successfull? %>
<p>
<%= t("proposal_ballots.successfull",
voting: link_to(t("proposal_ballots.voting"), proposal_ballots_path)).html_safe %>
</p>
<% else %>
<div class="text-center">
<%= render 'votes',
{ proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: 'yes') } %>
</div>
</div>
<% end %>
<% end %>
</div>

<div id="social-share" class="sidebar-divider"></div>
<h3><%= t("proposals.show.share") %></h3>
Expand Down
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ en:
hot_score: most active
most_commented: most commented
relevance: relevance
archived: Archived
retired_proposals: Retired proposals
retired_proposals_link: "Proposals retired by the author"
retired_links:
Expand Down
1 change: 0 additions & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ es:
hot_score: Más activas hoy
most_commented: Más comentadas
relevance: Más relevantes
archived: Archivadas
retired_proposals: Propuestas retiradas
retired_proposals_link: "Propuestas retiradas por sus autores"
retired_links:
Expand Down
4 changes: 2 additions & 2 deletions db/dev_seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def create_user(email, username = Faker::Name.name)
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
proposal = Proposal.create!(author: author,
title: Faker::Lorem.sentence(3).truncate(60),
question: Faker::Lorem.sentence(3),
question: Faker::Lorem.sentence(3) + "?",
summary: Faker::Lorem.sentence(3),
responsible_name: Faker::Name.name,
external_url: Faker::Internet.url,
Expand All @@ -168,7 +168,7 @@ def create_user(email, username = Faker::Name.name)
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
proposal = Proposal.create!(author: author,
title: Faker::Lorem.sentence(3).truncate(60),
question: Faker::Lorem.sentence(3),
question: Faker::Lorem.sentence(3) + "?",
summary: Faker::Lorem.sentence(3),
responsible_name: Faker::Name.name,
external_url: Faker::Internet.url,
Expand Down
58 changes: 58 additions & 0 deletions spec/features/proposal_ballots_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# coding: utf-8
require 'rails_helper'

feature 'Proposal ballots' do

scenario 'Banner shows in proposal index' do
create_featured_proposals

visit proposals_path
expect(page).to_not have_css("#next-voting")
expect(page).to have_css("#featured-proposals")

create_successfull_proposals

visit proposals_path

expect(page).to have_css("#next-voting")
expect(page).to_not have_css("#featured-proposals")
end

scenario 'Successfull proposals do not show support buttons in index' do
successfull_proposals = create_successfull_proposals

visit proposals_path

successfull_proposals.each do |proposal|
within("#proposal_#{proposal.id}_votes") do
expect(page).to_not have_css(".supports")
expect(page).to have_content "This proposal has reached the required supports"
end
end
end

scenario 'Successfull proposals do not show support buttons in show' do
successfull_proposals = create_successfull_proposals

successfull_proposals.each do |proposal|
visit proposal_path(proposal)
within("#proposal_#{proposal.id}_votes") do
expect(page).to_not have_css(".supports")
expect(page).to have_content "This proposal has reached the required supports"
end
end
end

scenario 'Successfull proposals are listed in the proposal ballots index' do
successfull_proposals = create_successfull_proposals

visit proposal_ballots_path

successfull_proposals.each do |proposal|
expect(page).to have_content(proposal.title)
expect(page).to have_content(proposal.question)
end
end

end

5 changes: 5 additions & 0 deletions spec/support/common_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ def create_featured_debates
create(:debate, :with_confidence_score, cached_votes_up: 80)]
end

def create_successfull_proposals
[create(:proposal, title: "Winter is coming", question: "Do you speak it?", cached_votes_up: Proposal.votes_needed_for_success + 100),
create(:proposal, title: "Fire and blood", question: "You talking to me?", cached_votes_up: Proposal.votes_needed_for_success + 1)]
end

def tag_names(tag_cloud)
tag_cloud.tags.map(&:name)
end
Expand Down

0 comments on commit 6fac3c6

Please sign in to comment.