Merge pull request #40 from AyuntamientoMadrid/js_comments-21

Hide/show comment forms
This commit is contained in:
Raimond Garcia
2015-07-27 23:30:25 +02:00
8 changed files with 86 additions and 17 deletions

View File

@@ -49,5 +49,11 @@ group :development, :test do
gem 'rspec-rails', '~> 3.0'
gem 'capybara'
gem 'factory_girl_rails'
gem 'launchy'
end
group :test do
gem 'database_cleaner'
gem 'poltergeist'
end

View File

@@ -43,6 +43,7 @@ GEM
activesupport (>= 4.0)
awesome_nested_set (>= 3.0)
acts_as_votable (0.10.0)
addressable (2.3.8)
arel (6.0.2)
awesome_nested_set (3.0.2)
activerecord (>= 4.0.0, < 5)
@@ -58,6 +59,7 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
@@ -66,6 +68,7 @@ GEM
execjs
coffee-script-source (1.9.1.1)
columnize (0.9.0)
database_cleaner (1.4.1)
debug_inspector (0.0.2)
devise (3.5.1)
bcrypt (~> 3.0)
@@ -96,6 +99,8 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
launchy (2.4.3)
addressable (~> 2.3)
loofah (2.0.2)
nokogiri (>= 1.5.9)
mail (2.6.3)
@@ -108,6 +113,11 @@ GEM
mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
pg (0.18.2)
poltergeist (1.6.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
@@ -191,6 +201,9 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket-driver (0.6.2)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
nokogiri (~> 1.3)
@@ -204,12 +217,15 @@ DEPENDENCIES
byebug
capybara
coffee-rails (~> 4.1.0)
database_cleaner
devise
factory_girl_rails
foundation-rails
jbuilder (~> 2.0)
jquery-rails
launchy
pg
poltergeist
rails (= 4.2.3)
recaptcha
responders
@@ -220,6 +236,3 @@ DEPENDENCIES
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)
BUNDLED WITH
1.10.5

View File

@@ -0,0 +1,13 @@
jQuery ->
toggle_comment = (id) ->
$("#js-comment-form-#{id}").toggle()
ready = ->
$('.js-add-comment-link').click ->
id = $(this).data().id
toggle_comment(id)
false
$(document).ready(ready)
$(document).on('page:load', ready)

View File

@@ -0,0 +1,11 @@
module CommentsHelper
def comment_link_text(parent)
parent.class == Debate ? "Comentar" : "Responder"
end
def comment_button_text(parent)
parent.class == Debate ? "Publicar comentario" : "Publicar respuesta"
end
end

View File

@@ -1,7 +1,11 @@
<%= link_to comment_link_text(parent), "", class: "js-add-comment-link", data: {'id': dom_id(parent)} %>
<div id="js-comment-form-<%= dom_id(parent) %>" style="display:none">
<%= form_for [@debate, Comment.new] do |f| %>
<%= f.text_area :body %>
<%= f.hidden_field :commentable_type, value: parent.class %>
<%= f.hidden_field :commentable_id, value: parent.id %>
<%= f.submit 'Publicar comentario' %>
<%= f.submit comment_button_text(parent) %>
<% end %>
</div>

View File

@@ -19,13 +19,15 @@ feature 'Comments' do
end
end
scenario 'Create' do
scenario 'Create', :js do
user = create(:user)
debate = create(:debate)
login_as(user)
visit debate_path(debate)
click_on 'Comentar'
fill_in 'comment_body', with: '¿Has pensado en esto...?'
click_button 'Publicar comentario'
@@ -36,7 +38,7 @@ feature 'Comments' do
end
end
scenario 'Reply' do
scenario 'Reply', :js do
citizen = create(:user, first_name: 'Ana')
manuela = create(:user, first_name: 'Manuela')
debate = create(:debate)
@@ -45,9 +47,10 @@ feature 'Comments' do
login_as(manuela)
visit debate_path(debate)
within "#comment-#{comment.id}" do
click_link "Responder"
within "#js-comment-form-comment_#{comment.id}" do
fill_in 'comment_body', with: 'La semana que viene está hecho.'
click_button 'Publicar comentario'
click_button 'Publicar respuesta'
end
expect(page).to have_content 'Comentario guardado'

View File

@@ -2,10 +2,11 @@ ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'spec_helper'
require 'capybara/rails'
require 'capybara/rspec'
require 'capybara/poltergeist'
include Warden::Test::Helpers
Warden.test_mode!
@@ -13,6 +14,7 @@ Warden.test_mode!
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end
Capybara.javascript_driver = :poltergeist

View File

@@ -1,9 +1,26 @@
require 'factory_girl_rails'
require 'database_cleaner'
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.filter_run :focus
config.run_all_when_everything_filtered = true
config.include FactoryGirl::Syntax::Methods
config.before(:suite) do
DatabaseCleaner.clean_with :truncation
end
config.before(:each) do |example|
DatabaseCleaner.strategy= example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options.
config.example_status_persistence_file_path = "spec/examples.txt"