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
/config/database.yml
/config/secrets.yml
/coverage

View File

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

View File

@@ -75,6 +75,12 @@ GEM
execjs
coffee-script-source (1.9.1.1)
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)
debug_inspector (0.0.2)
devise (3.5.1)
@@ -85,6 +91,9 @@ GEM
thread_safe (~> 0.1)
warden (~> 1.2.3)
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)
execjs (2.5.2)
factory_girl (4.5.0)
@@ -97,6 +106,8 @@ GEM
sass (>= 3.3.0, < 3.5)
globalid (0.3.5)
activesupport (>= 4.1.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.7.0)
jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5)
@@ -121,6 +132,7 @@ GEM
mini_portile (0.6.2)
minitest (5.7.0)
multi_json (1.11.2)
netrc (0.10.3)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
@@ -164,6 +176,10 @@ GEM
recaptcha (0.4.0)
responders (2.1.0)
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-support (~> 3.3.0)
rspec-expectations (3.3.0)
@@ -191,6 +207,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
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)
sprockets (3.2.0)
rack (~> 1.0)
@@ -198,9 +219,12 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
term-ansicolor (1.3.2)
tins (~> 1.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
tins (1.5.4)
turbolinks (2.5.3)
coffee-rails
tzinfo (1.2.2)
@@ -208,6 +232,9 @@ GEM
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)
warden (1.2.3)
rack (>= 1.0)
web-console (2.2.1)
@@ -232,6 +259,7 @@ DEPENDENCIES
capybara
ckeditor
coffee-rails (~> 4.1.0)
coveralls
database_cleaner
devise
factory_girl_rails

View File

@@ -1,5 +1,10 @@
# 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.
## Estado del proyecto
@@ -22,8 +27,8 @@ cd participacion
bundle install
cp config/database.yml.example config/database.yml
cp config/secrets.yml.example config/secrets.yml
bundle exec bin/rake db:create db:schema_load
RAILS_ENV=test bundle exec 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
```
Para ejecutar la aplicación en local:

View File

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

View File

@@ -4,7 +4,26 @@ class ApplicationController < ActionController::Base
self.responder = ApplicationResponder
respond_to :html
before_action :set_locale
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
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

View File

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

View File

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

View File

@@ -1,7 +1,8 @@
class RegistrationsController < Devise::RegistrationsController
include RecaptchaHelper
def create
if verify_recaptcha
if verify_captcha?(resource)
super
else
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
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 + "%"
end
def home_page?
request.fullpath == '/'
# Using path because fullpath yields false negatives since it contains
# parameters too
request.path == '/'
end
def header_css
home_page? ? '' : 'results'
end
def available_locales_to_switch
I18n.available_locales - [I18n.locale]
end
end

View File

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

View File

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

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| %>
<%= f.text_area :body %>
<%= 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="row">
<div class="small-12 medium-9 column">
<div class="debate-content">
<span class="label left"><%= t("debates.debate.debate") %></span>
<i class="icon-comment-quotes"></i>
<h3><%= link_to debate.title, debate %></h3>
<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>
<div class="debate-description">
<%= debate.description %>
@@ -16,29 +19,11 @@
<%= render "shared/tags", debate: debate %>
</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 id="<%= dom_id(debate) %>_votes" class="small-12 medium-3 column text-center">
<%= render 'debates/votes', debate: debate %>
</div>
<span class="divider"></span>
<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>

View File

@@ -1,12 +1,15 @@
<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="debate-content">
<span class="label left"><%= t("debates.debate.debate") %></span>
<i class="icon-comment-quotes right"></i>
<h3><%= link_to featured_debate.title, featured_debate %></h3>
<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>
<div class="debate-description">
<%= featured_debate.description %>
@@ -15,27 +18,12 @@
<%= render "shared/tags", debate: featured_debate %>
</div>
<div class="votes">
<div class="inline-block in-favor">
<%= link_to debate_votes_path(featured_debate, value: "yes"), class: "like", title: t('votes.agree'), method: "post" do %>
<i class="icon-like"></i>
<span><%= percentage('likes', featured_debate) %></span>
<% end %>
<div class="row">
<div id="<%= dom_id(featured_debate) %>_votes" class="small-12 column">
<%= render 'debates/votes', debate: featured_debate %>
</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>

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 %>
<p><%= render 'shared/tags', debate: @debate %></p>
</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>
<div class="text-center">
<%= render 'votes/votes' %>
<%= render 'debates/votes', debate: @debate %>
<% 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>
</section>
@@ -24,10 +30,12 @@
<div class="row">
<div id="comments" class="small-12 column">
<h2><%= t("debates.show.comments") %></h2>
<% if user_signed_in? %>
<div>
<%= t("debates.show.leave_comment") %>
<%= render 'comments/form', parent: @debate %>
<%= render 'comments/form', {parent: @debate, toggeable: false} %>
</div>
<% end %>
<%= render @debate.root_comments %>
</div>
<% 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="right">
<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>

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
comments: Comments
leave_comment: Write a comment
login_to_comment: Log in to participate
edit_debate_link: Edit
edit:
editing: Edit debate

View File

@@ -37,6 +37,7 @@ es:
comment: Comentario
comments: Comentarios
leave_comment: Deja tu comentario
login_to_comment: Entra para participar
edit_debate_link: Editar
edit:
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"
root 'debates#index'
resources :debates do
resources :votes, only: :create
resources :comments, only: :create
member do
post :vote
end
resources :comments, only: :create, shallow: true do
member do
post :vote
end
end
end
resource :account, controller: "account", only: [:show, :update]

View File

@@ -19,6 +19,21 @@ feature 'Comments' do
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
user = create(:user)
debate = create(:debate)
@@ -26,8 +41,6 @@ feature 'Comments' do
login_as(user)
visit debate_path(debate)
click_on 'Comment'
fill_in 'comment_body', with: '¿Has pensado en esto...?'
click_button 'Publish comment'

View File

@@ -8,7 +8,7 @@ feature 'Debates' do
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|
within('#featured-debates') do
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,12 +26,14 @@ feature 'Tags' do
visit debates_path
first(:link, "Salud").click
within("#debates") do
expect(page).to have_css('.debate', count: 2)
expect(page).to have_content(debate1.title)
expect(page).to have_content(debate2.title)
expect(page).to_not have_content(debate3.title)
expect(page).to_not have_content(debate4.title)
end
end
scenario 'Show' do
debate = create(:debate, tag_list: 'Hacienda, Economía')

View File

@@ -2,6 +2,8 @@ require 'rails_helper'
feature 'Votes' do
feature 'Debates' do
background do
@manuela = create(:user)
@pablo = create(:user)
@@ -11,6 +13,20 @@ feature 'Votes' do
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)
@@ -19,38 +35,79 @@ feature 'Votes' do
expect(page).to have_content "2 votes"
within('#in_favor') do
within('.in-favor') do
expect(page).to have_content "50%"
end
within('#against') do
within('.against') do
expect(page).to have_content "50%"
end
end
scenario 'Create', :js do
find('#in_favor a').click
scenario 'Create from debate show', :js do
find('.in-favor a').click
within('#in_favor') do
within('.in-favor') do
expect(page).to have_content "100%"
end
within('#against') do
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
scenario 'Create from debate featured', :js do
visit debates_path
within('#in_favor') do
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
within('#against') do
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
@@ -58,18 +115,95 @@ feature 'Votes' do
end
scenario 'Trying to vote multiple times', :js do
find('#in_favor a').click
find('#in_favor a').click
find('.in-favor a').click
find('.in-favor a').click
within('#in_favor') do
within('.in-favor') do
expect(page).to have_content "100%"
end
within('#against') do
within('.against') do
expect(page).to have_content "0%"
end
expect(page).to have_content "1 vote"
end
end
feature 'Comments' do
background do
@manuela = create(:user)
@pablo = create(:user)
@debate = create(:debate)
@comment = create(:comment, commentable: @debate)
login_as(@manuela)
visit debate_path(@debate)
end
scenario 'Show' do
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
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

View File

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