fixes conflicts

This commit is contained in:
rgarcia
2015-08-06 13:42:57 +02:00
35 changed files with 442 additions and 191 deletions

1
.coveralls.yml Normal file
View File

@@ -0,0 +1 @@
service_name: travis-ci

2
.gitignore vendored
View File

@@ -19,3 +19,5 @@
/spec/examples.txt /spec/examples.txt
/config/database.yml /config/database.yml
/config/secrets.yml /config/secrets.yml
/coverage

View File

@@ -56,5 +56,6 @@ end
group :test do group :test do
gem 'database_cleaner' gem 'database_cleaner'
gem 'poltergeist' gem 'poltergeist'
gem 'coveralls', require: false
end end

View File

@@ -75,6 +75,12 @@ GEM
execjs execjs
coffee-script-source (1.9.1.1) coffee-script-source (1.9.1.1)
columnize (0.9.0) columnize (0.9.0)
coveralls (0.8.2)
json (~> 1.8)
rest-client (>= 1.6.8, < 2)
simplecov (~> 0.10.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
database_cleaner (1.4.1) database_cleaner (1.4.1)
debug_inspector (0.0.2) debug_inspector (0.0.2)
devise (3.5.1) devise (3.5.1)
@@ -85,6 +91,9 @@ GEM
thread_safe (~> 0.1) thread_safe (~> 0.1)
warden (~> 1.2.3) warden (~> 1.2.3)
diff-lcs (1.2.5) diff-lcs (1.2.5)
docile (1.1.5)
domain_name (0.5.24)
unf (>= 0.0.5, < 1.0.0)
erubis (2.7.0) erubis (2.7.0)
execjs (2.5.2) execjs (2.5.2)
factory_girl (4.5.0) factory_girl (4.5.0)
@@ -97,6 +106,8 @@ GEM
sass (>= 3.3.0, < 3.5) sass (>= 3.3.0, < 3.5)
globalid (0.3.5) globalid (0.3.5)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.7.0) i18n (0.7.0)
jbuilder (2.3.1) jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
@@ -121,6 +132,7 @@ GEM
mini_portile (0.6.2) mini_portile (0.6.2)
minitest (5.7.0) minitest (5.7.0)
multi_json (1.11.2) multi_json (1.11.2)
netrc (0.10.3)
nokogiri (1.6.6.2) nokogiri (1.6.6.2)
mini_portile (~> 0.6.0) mini_portile (~> 0.6.0)
orm_adapter (0.5.0) orm_adapter (0.5.0)
@@ -164,6 +176,10 @@ GEM
recaptcha (0.4.0) recaptcha (0.4.0)
responders (2.1.0) responders (2.1.0)
railties (>= 4.2.0, < 5) railties (>= 4.2.0, < 5)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec-core (3.3.1) rspec-core (3.3.1)
rspec-support (~> 3.3.0) rspec-support (~> 3.3.0)
rspec-expectations (3.3.0) rspec-expectations (3.3.0)
@@ -191,6 +207,11 @@ GEM
sdoc (0.4.1) sdoc (0.4.1)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0) rdoc (~> 4.0)
simplecov (0.10.0)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
spring (1.3.6) spring (1.3.6)
sprockets (3.2.0) sprockets (3.2.0)
rack (~> 1.0) rack (~> 1.0)
@@ -198,9 +219,12 @@ GEM
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
term-ansicolor (1.3.2)
tins (~> 1.0)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (1.4.1) tilt (1.4.1)
tins (1.5.4)
turbolinks (2.5.3) turbolinks (2.5.3)
coffee-rails coffee-rails
tzinfo (1.2.2) tzinfo (1.2.2)
@@ -208,6 +232,9 @@ GEM
uglifier (2.7.1) uglifier (2.7.1)
execjs (>= 0.3.0) execjs (>= 0.3.0)
json (>= 1.8.0) json (>= 1.8.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)
warden (1.2.3) warden (1.2.3)
rack (>= 1.0) rack (>= 1.0)
web-console (2.2.1) web-console (2.2.1)
@@ -232,6 +259,7 @@ DEPENDENCIES
capybara capybara
ckeditor ckeditor
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
coveralls
database_cleaner database_cleaner
devise devise
factory_girl_rails factory_girl_rails

View File

@@ -1,5 +1,10 @@
# Aplicación de Participación Ciudadana del Ayuntamiento de Madrid # Aplicación de Participación Ciudadana del Ayuntamiento de Madrid
[![Build Status](https://travis-ci.org/AyuntamientoMadrid/participacion.svg?branch=master)](https://travis-ci.org/AyuntamientoMadrid/participacion)
[![Code Climate](https://codeclimate.com/github/AyuntamientoMadrid/participacion/badges/gpa.svg)](https://codeclimate.com/github/AyuntamientoMadrid/participacion)
[![Dependency Status](https://gemnasium.com/AyuntamientoMadrid/participacion.svg)](https://gemnasium.com/AyuntamientoMadrid/participacion)
[![Coverage Status](https://coveralls.io/repos/AyuntamientoMadrid/participacion/badge.svg?branch=master&service=github)](https://coveralls.io/github/AyuntamientoMadrid/participacion?branch=master)
Este es el repositorio de código abierto de la Aplicación de Participación Ciudadana del Ayuntamiento de Madrid. Este es el repositorio de código abierto de la Aplicación de Participación Ciudadana del Ayuntamiento de Madrid.
## Estado del proyecto ## Estado del proyecto
@@ -22,8 +27,8 @@ cd participacion
bundle install bundle install
cp config/database.yml.example config/database.yml cp config/database.yml.example config/database.yml
cp config/secrets.yml.example config/secrets.yml cp config/secrets.yml.example config/secrets.yml
bundle exec bin/rake db:create db:schema_load bundle exec bin/rake db:create db:schema:load
RAILS_ENV=test bundle exec rake db:create db:schema_load RAILS_ENV=test bundle exec rake db:create db:schema:load
``` ```
Para ejecutar la aplicación en local: Para ejecutar la aplicación en local:

View File

@@ -247,7 +247,7 @@ header {
// 05.1. Debates Index // 05.1. Debates Index
// - - - - - - - - - - - - // - - - - - - - - - - - -
.debates-featured { .debate-featured {
margin-bottom: rem-calc(34); margin-bottom: rem-calc(34);
margin-top: rem-calc(23); margin-top: rem-calc(23);
@@ -345,8 +345,8 @@ header {
margin-bottom: $line-height*2; margin-bottom: $line-height*2;
} }
.debates-index { .debate {
@extend .debates-featured; @extend .debate-featured;
margin-bottom: 0; margin-bottom: 0;
margin-top: 0; margin-top: 0;

View File

@@ -4,7 +4,26 @@ class ApplicationController < ActionController::Base
self.responder = ApplicationResponder self.responder = ApplicationResponder
respond_to :html respond_to :html
before_action :set_locale
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
private
def set_locale
if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
session[:locale] = params[:locale]
end
session[:locale] ||= I18n.default_locale
I18n.locale = session[:locale]
end
def verify_captcha?(resource)
return true unless recaptcha_keys?
verify_recaptcha(model: resource)
end
end end

View File

@@ -1,6 +1,6 @@
class CommentsController < ApplicationController class CommentsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_debate, :set_parent before_action :set_debate, :set_parent, only: :create
respond_to :html, :js respond_to :html, :js
def create def create
@@ -10,6 +10,12 @@ class CommentsController < ApplicationController
respond_with @comment respond_with @comment
end end
def vote
@comment = Comment.find(params[:id])
@comment.vote_by(voter: current_user, vote: params[:value])
respond_with @comment
end
private private
def comment_params def comment_params
params.require(:comments).permit(:commentable_type, :commentable_id, :body) params.require(:comments).permit(:commentable_type, :commentable_id, :body)

View File

@@ -1,7 +1,7 @@
class DebatesController < ApplicationController class DebatesController < ApplicationController
include RecaptchaHelper include RecaptchaHelper
before_action :set_debate, only: [:show, :edit, :update] before_action :set_debate, only: [:show, :edit, :update, :vote]
before_action :authenticate_user!, except: [:show, :index] before_action :authenticate_user!, except: [:index, :show]
before_action :validate_ownership, only: [:edit, :update] before_action :validate_ownership, only: [:edit, :update]
def index def index
@@ -9,8 +9,8 @@ class DebatesController < ApplicationController
@debates = Debate.tagged_with(params[:tag]).order("created_at DESC") @debates = Debate.tagged_with(params[:tag]).order("created_at DESC")
else else
@debates = Debate.all.order("created_at DESC") @debates = Debate.all.order("created_at DESC")
@featured_debates = @debates.to_a.shift(3)
end end
@featured_debates = @debates.to_a.shift(3)
end end
def show def show
@@ -26,7 +26,7 @@ class DebatesController < ApplicationController
def create def create
@debate = Debate.new(debate_params) @debate = Debate.new(debate_params)
@debate.author = current_user @debate.author = current_user
if verify_captcha? and @debate.save if verify_captcha?(@debate) and @debate.save
redirect_to @debate, notice: t('flash.actions.create.notice', resource_name: 'Debate') redirect_to @debate, notice: t('flash.actions.create.notice', resource_name: 'Debate')
else else
render :new render :new
@@ -38,6 +38,10 @@ class DebatesController < ApplicationController
respond_with @debate respond_with @debate
end end
def vote
@debate.vote_by(voter: current_user, vote: params[:value])
end
private private
def set_debate def set_debate
@@ -51,10 +55,4 @@ class DebatesController < ApplicationController
def validate_ownership def validate_ownership
raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user) raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user)
end end
def verify_captcha?
return true unless recaptcha_keys?
verify_recaptcha(model: @debate)
end
end end

View File

@@ -1,7 +1,8 @@
class RegistrationsController < Devise::RegistrationsController class RegistrationsController < Devise::RegistrationsController
include RecaptchaHelper
def create def create
if verify_recaptcha if verify_captcha?(resource)
super super
else else
build_resource(sign_up_params) build_resource(sign_up_params)

View File

@@ -1,21 +0,0 @@
class VotesController < ApplicationController
before_action :set_debate
before_action :authenticate_user!
respond_to :html, :js
def create
register_vote
notice = @debate.vote_registered? ? I18n.t("votes.notice_thanks") : I18n.t("votes.notice_already_registered")
respond_with @debate
end
private
def set_debate
@debate = Debate.find(params[:debate_id])
end
def register_vote
@debate.vote_by voter: current_user, vote: params[:value]
end
end

View File

@@ -5,15 +5,21 @@ module ApplicationHelper
end end
def percentage(vote, debate) def percentage(vote, debate)
return if debate.total_votes == 0 return "0%" if debate.total_votes == 0
debate.send(vote).percent_of(debate.total_votes).to_s + "%" debate.send(vote).percent_of(debate.total_votes).to_s + "%"
end end
def home_page? def home_page?
request.fullpath == '/' # Using path because fullpath yields false negatives since it contains
# parameters too
request.path == '/'
end end
def header_css def header_css
home_page? ? '' : 'results' home_page? ? '' : 'results'
end end
def available_locales_to_switch
I18n.available_locales - [I18n.locale]
end
end end

View File

@@ -1,5 +1,6 @@
class Comment < ActiveRecord::Base class Comment < ActiveRecord::Base
acts_as_nested_set scope: [:commentable_id, :commentable_type] acts_as_nested_set scope: [:commentable_id, :commentable_type]
acts_as_votable
validates :body, presence: true validates :body, presence: true
validates :user, presence: true validates :user, presence: true

View File

@@ -7,12 +7,19 @@
<span class="comment-info"> <span class="comment-info">
<%= comment.user.name %>&nbsp;&bullet;&nbsp;<%= time_ago_in_words(comment.created_at) %> <%= comment.user.name %>&nbsp;&bullet;&nbsp;<%= time_ago_in_words(comment.created_at) %>
</span> </span>
<p><%= comment.body %></p> <p><%= comment.body %></p>
<p class="reply"><%= render 'comments/form', parent: comment %></p>
</div>
<div class="comment-children"> <span id="<%= dom_id(comment) %>_votes">
<%= render comment.children %> <%= render 'comments/votes', comment: comment %>
</div> </span>
<% if user_signed_in? %>
<p class="reply"><%= render 'comments/form', {parent: comment, toggeable: true} %></p>
<% end %>
</div>
<div class="comment-children">
<%= render comment.children %>
</div>
</div> </div>
</div> </div>

View File

@@ -1,6 +1,6 @@
<%= link_to comment_link_text(parent), "", class: "js-add-comment-link", data: {'id': dom_id(parent)} %> <%= link_to(comment_link_text(parent), "", class: "js-add-comment-link", data: {'id': dom_id(parent)}) if toggeable %>
<div id="js-comment-form-<%= dom_id(parent) %>" style="display:none"> <div id="js-comment-form-<%= dom_id(parent) %>" <%= "style='display:none'".html_safe if toggeable %>>
<%= form_for [@debate, Comment.new], remote: true do |f| %> <%= form_for [@debate, Comment.new], remote: true do |f| %>
<%= f.text_area :body %> <%= f.text_area :body %>
<%= f.hidden_field :commentable_type, value: parent.class %> <%= f.hidden_field :commentable_type, value: parent.class %>

View File

@@ -0,0 +1,11 @@
<span class="in_favor">
<%= link_to "up", vote_comment_path(comment, value: 'yes'),
method: "post", remote: true %>
<%= comment.get_likes.size %>
</span>
<span class="against">
<%= link_to "down", vote_comment_path(comment, value: 'no'),
method: "post", remote: true %>
<%= comment.get_dislikes.size %>
</span>

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@comment) %>_votes").html('<%= j render("comments/votes", comment: @comment) %>');

View File

@@ -1,13 +1,16 @@
<div id="debate-<%= debate.id %>" class="debates-index"> <div id="debate-<%= debate.id %>" class="debate">
<div class="panel"> <div class="panel">
<div class="row"> <div class="row">
<div class="small-12 medium-9 column"> <div class="small-12 medium-9 column">
<div class="debate-content"> <div class="debate-content">
<span class="label left"><%= t("debates.debate.debate") %></span> <span class="label left"><%= t("debates.debate.debate") %></span>
<i class="icon-comment-quotes"></i> <i class="icon-comment-quotes"></i>
<h3><%= link_to debate.title, debate %></h3> <h3><%= link_to debate.title, debate %></h3>
<p class="debate-info"> <p class="debate-info">
<i class="icon-chat-bubble-two"></i>&nbsp;<%= pluralize(debate.comment_threads.count, t("debates.debate.comment"), t("debates.debate.comments")) %> <i class="icon-chat-bubble-two"></i>&nbsp;
<%= pluralize(debate.comment_threads.count,
t("debates.debate.comment"), t("debates.debate.comments")) %>
</p> </p>
<div class="debate-description"> <div class="debate-description">
<%= debate.description %> <%= debate.description %>
@@ -16,29 +19,11 @@
<%= render "shared/tags", debate: debate %> <%= render "shared/tags", debate: debate %>
</div> </div>
</div> </div>
<div class="small-12 medium-3 column text-center">
<div class="votes">
<div class="inline-block in-favor">
<%= link_to debate_votes_path(debate, value: 'yes'), class: "like inline-block", title: t('votes.agree'), method: "post" do %>
<i class="icon-like"></i>
<span><%= percentage('likes', debate) %></span>
<% end %>
</div>
<span class="divider"></span> <div id="<%= dom_id(debate) %>_votes" class="small-12 medium-3 column text-center">
<%= render 'debates/votes', debate: debate %>
<div class="inline-block against">
<%= link_to debate_votes_path(debate, value: 'no'), class: "unlike inline-block", title: t('votes.disagree'), method: "post" do %>
<i class="icon-unlike"></i>
<span><%= percentage('dislikes', debate) %></span>
<% end %>
</div>
<span class="total-votes">
<%= pluralize(debate.total_votes, t("debates.debate.vote"), t("debates.debate.votes")) %>
</span>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,12 +1,15 @@
<div class="small-12 medium-4 column"> <div class="small-12 medium-4 column">
<div id="debate-<%= featured_debate.id %>" class="debates-featured"> <div id="debate-<%= featured_debate.id %>" class="debate-featured">
<div class="panel"> <div class="panel">
<div class="debate-content"> <div class="debate-content">
<span class="label left"><%= t("debates.debate.debate") %></span> <span class="label left"><%= t("debates.debate.debate") %></span>
<i class="icon-comment-quotes right"></i> <i class="icon-comment-quotes right"></i>
<h3><%= link_to featured_debate.title, featured_debate %></h3> <h3><%= link_to featured_debate.title, featured_debate %></h3>
<p class="debate-info"> <p class="debate-info">
<i class="icon-chat-bubble-two"></i>&nbsp;<%= pluralize(featured_debate.comment_threads.count, t("debates.show.comment"), t("debates.show.comments")) %> <i class="icon-chat-bubble-two"></i>&nbsp;
<%= pluralize(featured_debate.comment_threads.count,
t("debates.show.comment"), t("debates.show.comments")) %>
</p> </p>
<div class="debate-description"> <div class="debate-description">
<%= featured_debate.description %> <%= featured_debate.description %>
@@ -15,27 +18,12 @@
<%= render "shared/tags", debate: featured_debate %> <%= render "shared/tags", debate: featured_debate %>
</div> </div>
<div class="votes"> <div class="row">
<div class="inline-block in-favor"> <div id="<%= dom_id(featured_debate) %>_votes" class="small-12 column">
<%= link_to debate_votes_path(featured_debate, value: "yes"), class: "like", title: t('votes.agree'), method: "post" do %> <%= render 'debates/votes', debate: featured_debate %>
<i class="icon-like"></i>
<span><%= percentage('likes', featured_debate) %></span>
<% end %>
</div> </div>
<span class="divider"></span>
<div class="inline-block against">
<%= link_to debate_votes_path(featured_debate, value: "no"), class: "unlike", title: t('votes.disagree'), method: "post" do %>
<i class="icon-unlike"></i>
<span><%= percentage('dislikes', featured_debate) %></span>
<% end %>
</div>
<span class="total-votes">
<%= pluralize(featured_debate.total_votes, t("debates.debate.vote"), t("debates.debate.votes")) %>
</span>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,22 @@
<div class="votes">
<div class="in-favor inline-block">
<%= link_to vote_debate_path(debate, value: 'yes'),
class: "like", title: t('votes.agree'), method: "post", remote: true do %>
<i class="icon-like"></i>
<span><%= percentage('likes', debate) %></span>
<% end %>
</div>
<span class="divider"></span>
<div class="against inline-block">
<%= link_to vote_debate_path(debate, value: 'no'), class: "unlike", title: t('votes.disagree'), method: "post", remote: true do %>
<i class="icon-unlike"></i>
<span><%= percentage('dislikes', debate) %></span>
<% end %>
</div>
<span class="total-votes">
<%= pluralize(debate.total_votes, t("debates.debate.vote"), t("debates.debate.votes")) %>
</span>
</div>

View File

@@ -10,13 +10,19 @@
<%= @debate.description %> <%= @debate.description %>
<p><%= render 'shared/tags', debate: @debate %></p> <p><%= render 'shared/tags', debate: @debate %></p>
</div> </div>
<div id="votes" class="small-12 medium-3 column">
<div id="<%= dom_id(@debate) %>_votes" class="small-12 medium-3 column">
<h3><%= t("votes.supports") %></h3> <h3><%= t("votes.supports") %></h3>
<div class="text-center"> <div class="text-center">
<%= render 'votes/votes' %> <%= render 'debates/votes', debate: @debate %>
<%= link_to t("debates.show.leave_comment"), "#comments", class: "leave-comment" %> <% if user_signed_in? %>
<%= link_to t("debates.show.leave_comment"), "#comments", class: "leave-comment" %>
<% else %>
<%= link_to t("debates.show.login_to_comment"), new_user_session_path, class: "leave-comment" %>
<% end %>
</div> </div>
</div> </div>
</div> </div>
</section> </section>
@@ -24,10 +30,12 @@
<div class="row"> <div class="row">
<div id="comments" class="small-12 column"> <div id="comments" class="small-12 column">
<h2><%= t("debates.show.comments") %></h2> <h2><%= t("debates.show.comments") %></h2>
<% if user_signed_in? %>
<div> <div>
<%= t("debates.show.leave_comment") %> <%= t("debates.show.leave_comment") %>
<%= render 'comments/form', parent: @debate %> <%= render 'comments/form', {parent: @debate, toggeable: false} %>
</div> </div>
<% end %>
<%= render @debate.root_comments %> <%= render @debate.root_comments %>
</div> </div>
<% if current_user && @debate.editable_by?(current_user) %> <% if current_user && @debate.editable_by?(current_user) %>

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@debate) %>_votes").html('<%= j render("debates/votes", debate: @debate) %>');

View File

@@ -4,6 +4,14 @@
<div class="small-12 column"> <div class="small-12 column">
<div class="right"> <div class="right">
<a href="#"><%= t("layouts.header.external_link_transparency") %></a> | <a href="#"><%= t("layouts.header.external_link_opendata") %></a> <a href="#"><%= t("layouts.header.external_link_transparency") %></a> | <a href="#"><%= t("layouts.header.external_link_opendata") %></a>
|
<span id="locale-switcher">
[
<% available_locales_to_switch.each do |locale| %>
<%= link_to(locale, params.merge(locale: locale), id: "locale-link-#{locale}") %>
<% end %>
]
</span>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,21 +0,0 @@
<div class="votes">
<div class="inline-block in-favor">
<%= link_to debate_votes_path(@debate, value: 'yes'), class: "like", title: t('votes.agree'), method: "post", remote: true do %>
<i class="icon-like"></i>
<span><%= percentage('likes', @debate) %></span>
<% end %>
</div>
<span class="divider"></span>
<div class="inline-block against">
<%= link_to debate_votes_path(@debate, value: 'no'), class: "unlike", title: t('votes.disagree'), method: "post", remote: true do %>
<i class="icon-unlike"></i>
<span><%= percentage('dislikes', @debate) %></span>
<% end %>
</div>
<span class="total-votes">
<%= pluralize(@debate.total_votes, t("debates.debate.vote"), t("debates.debate.votes")) %>
</span>
</div>

View File

@@ -1 +0,0 @@
$("#votes").html("<%= j render('votes') %>");

View File

@@ -0,0 +1,6 @@
I18n.available_locales = [:en, :es]
I18n.default_locale = :es
# Add the new directories to the locales load path
I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

View File

@@ -38,6 +38,7 @@ en:
comment: Comment comment: Comment
comments: Comments comments: Comments
leave_comment: Write a comment leave_comment: Write a comment
login_to_comment: Log in to participate
edit_debate_link: Edit edit_debate_link: Edit
edit: edit:
editing: Edit debate editing: Edit debate

View File

@@ -37,6 +37,7 @@ es:
comment: Comentario comment: Comentario
comments: Comentarios comments: Comentarios
leave_comment: Deja tu comentario leave_comment: Deja tu comentario
login_to_comment: Entra para participar
edit_debate_link: Editar edit_debate_link: Editar
edit: edit:
editing: Editar debate editing: Editar debate

View File

@@ -6,9 +6,18 @@ Rails.application.routes.draw do
# You can have the root of your site routed with "root" # You can have the root of your site routed with "root"
root 'debates#index' root 'debates#index'
resources :debates do resources :debates do
resources :votes, only: :create member do
resources :comments, only: :create post :vote
end
resources :comments, only: :create, shallow: true do
member do
post :vote
end
end
end end
resource :account, controller: "account", only: [:show, :update] resource :account, controller: "account", only: [:show, :update]

View File

@@ -19,6 +19,21 @@ feature 'Comments' do
end end
end end
feature 'Not logged user' do
scenario 'can not see comments forms' do
debate = create(:debate)
create(:comment, commentable: debate)
visit debate_path(debate)
expect(page).to have_content 'Log in to participate'
within ('#comments') do
expect(page).to_not have_content 'Write a comment'
expect(page).to_not have_content 'Reply'
expect(page).to_not have_css('form')
end
end
end
scenario 'Create', :js do scenario 'Create', :js do
user = create(:user) user = create(:user)
debate = create(:debate) debate = create(:debate)
@@ -26,8 +41,6 @@ feature 'Comments' do
login_as(user) login_as(user)
visit debate_path(debate) visit debate_path(debate)
click_on 'Comment'
fill_in 'comment_body', with: '¿Has pensado en esto...?' fill_in 'comment_body', with: '¿Has pensado en esto...?'
click_button 'Publish comment' click_button 'Publish comment'

View File

@@ -8,7 +8,7 @@ feature 'Debates' do
visit debates_path visit debates_path
expect(page).to have_selector('#featured-debates .debate', count: 3) expect(page).to have_selector('#featured-debates .debate-featured', count: 3)
featured_debates.each do |debate| featured_debates.each do |debate|
within('#featured-debates') do within('#featured-debates') do
expect(page).to have_content debate.title expect(page).to have_content debate.title

View File

@@ -0,0 +1,27 @@
require 'rails_helper'
feature 'Localization' do
scenario 'Wrong locale' do
visit root_path(locale: :es)
visit root_path(locale: :klingon)
expect(page).to have_text('Estamos abriendo Madrid')
end
scenario 'Changing locale' do
visit root_path(locale: :es)
locale_switcher = find('#locale-switcher')
expect(page).to have_text('Estamos abriendo Madrid')
expect(locale_switcher).to have_text('en')
expect(locale_switcher).to_not have_text('es')
find('#locale-link-en').click
locale_switcher = find('#locale-switcher')
expect(page).to have_text('We are opening Madrid')
expect(locale_switcher).to have_text('es')
expect(locale_switcher).to_not have_text('en')
end
end

View File

@@ -26,11 +26,13 @@ feature 'Tags' do
visit debates_path visit debates_path
first(:link, "Salud").click first(:link, "Salud").click
expect(page).to have_css('.debate', count: 2) within("#debates") do
expect(page).to have_content(debate1.title) expect(page).to have_css('.debate', count: 2)
expect(page).to have_content(debate2.title) expect(page).to have_content(debate1.title)
expect(page).to_not have_content(debate3.title) expect(page).to have_content(debate2.title)
expect(page).to_not have_content(debate4.title) expect(page).to_not have_content(debate3.title)
expect(page).to_not have_content(debate4.title)
end
end end
scenario 'Show' do scenario 'Show' do

View File

@@ -2,74 +2,208 @@ require 'rails_helper'
feature 'Votes' do feature 'Votes' do
background do feature 'Debates' do
@manuela = create(:user)
@pablo = create(:user) background do
@debate = create(:debate) @manuela = create(:user)
@pablo = create(:user)
@debate = create(:debate)
login_as(@manuela)
visit debate_path(@debate)
end
scenario 'Show no votes' do
visit debate_path(@debate)
expect(page).to have_content "0 votes"
within('.in-favor') do
expect(page).to have_content "0%"
end
within('.against') do
expect(page).to have_content "0%"
end
end
scenario 'Show' do
vote = create(:vote, voter: @manuela, votable: @debate, vote_flag: true)
vote = create(:vote, voter: @pablo, votable: @debate, vote_flag: false)
visit debate_path(@debate)
expect(page).to have_content "2 votes"
within('.in-favor') do
expect(page).to have_content "50%"
end
within('.against') do
expect(page).to have_content "50%"
end
end
scenario 'Create from debate show', :js do
find('.in-favor a').click
within('.in-favor') do
expect(page).to have_content "100%"
end
within('.against') do
expect(page).to have_content "0%"
end
expect(page).to have_content "1 vote"
end
scenario 'Create from debate featured', :js do
visit debates_path
within("#featured-debates") do
find('.in-favor a').click
within('.in-favor') do
expect(page).to have_content "100%"
end
within('.against') do
expect(page).to have_content "0%"
end
expect(page).to have_content "1 vote"
end
expect(URI.parse(current_url).path).to eq(debates_path)
end
scenario 'Create from debate index', :js do
3.times { create(:debate) }
visit debates_path
within("#debates") do
expect(page).to have_css(".debate", count: 1)
find('.in-favor a').click
within('.in-favor') do
expect(page).to have_content "100%"
end
within('.against') do
expect(page).to have_content "0%"
end
expect(page).to have_content "1 vote"
end
expect(URI.parse(current_url).path).to eq(debates_path)
end
scenario 'Update', :js do
find('.in-favor a').click
find('.against a').click
within('.in-favor') do
expect(page).to have_content "0%"
end
within('.against') do
expect(page).to have_content "100%"
end
expect(page).to have_content "1 vote"
end
scenario 'Trying to vote multiple times', :js do
find('.in-favor a').click
find('.in-favor a').click
within('.in-favor') do
expect(page).to have_content "100%"
end
within('.against') do
expect(page).to have_content "0%"
end
expect(page).to have_content "1 vote"
end
login_as(@manuela)
visit debate_path(@debate)
end end
scenario 'Show' do
vote = create(:vote, voter: @manuela, votable: @debate, vote_flag: true)
vote = create(:vote, voter: @pablo, votable: @debate, vote_flag: false)
visit debate_path(@debate) feature 'Comments' do
expect(page).to have_content "2 votes" background do
@manuela = create(:user)
@pablo = create(:user)
@debate = create(:debate)
@comment = create(:comment, commentable: @debate)
within('#in_favor') do login_as(@manuela)
expect(page).to have_content "50%" visit debate_path(@debate)
end end
within('#against') do scenario 'Show' do
expect(page).to have_content "50%" vote = create(:vote, voter: @manuela, votable: @comment, vote_flag: true)
vote = create(:vote, voter: @pablo, votable: @comment, vote_flag: false)
visit debate_path(@debate)
within("#comment_#{@comment.id}_votes") do
within(".in_favor") do
expect(page).to have_content "1"
end
within(".against") do
expect(page).to have_content "1"
end
end
end end
scenario 'Create', :js do
within("#comment_#{@comment.id}_votes") do
find(".in_favor a").click
within(".in_favor") do
expect(page).to have_content "1"
end
within(".against") do
expect(page).to have_content "0"
end
end
end
scenario 'Update', :js do
within("#comment_#{@comment.id}_votes") do
find('.in_favor a').click
find('.against a').click
within('.in_favor') do
expect(page).to have_content "0"
end
within('.against') do
expect(page).to have_content "1"
end
end
end
scenario 'Trying to vote multiple times', :js do
within("#comment_#{@comment.id}_votes") do
find('.in_favor a').click
find('.in_favor a').click
within('.in_favor') do
expect(page).to have_content "1"
end
within('.against') do
expect(page).to have_content "0"
end
end
end
end end
scenario 'Create', :js do
find('#in_favor a').click
within('#in_favor') do
expect(page).to have_content "100%"
end
within('#against') do
expect(page).to have_content "0%"
end
expect(page).to have_content "1 vote"
end
scenario 'Update', :js do
find('#in_favor a').click
find('#against a').click
within('#in_favor') do
expect(page).to have_content "0%"
end
within('#against') do
expect(page).to have_content "100%"
end
expect(page).to have_content "1 vote"
end
scenario 'Trying to vote multiple times', :js do
find('#in_favor a').click
find('#in_favor a').click
within('#in_favor') do
expect(page).to have_content "100%"
end
within('#against') do
expect(page).to have_content "0%"
end
expect(page).to have_content "1 vote"
end
end end

View File

@@ -1,3 +1,5 @@
require 'coveralls'
Coveralls.wear!('rails')
ENV['RAILS_ENV'] ||= 'test' ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production? abort("The Rails environment is running in production mode!") if Rails.env.production?