Merge pull request #40 from AyuntamientoMadrid/js_comments-21
Hide/show comment forms
This commit is contained in:
6
Gemfile
6
Gemfile
@@ -49,5 +49,11 @@ group :development, :test do
|
|||||||
gem 'rspec-rails', '~> 3.0'
|
gem 'rspec-rails', '~> 3.0'
|
||||||
gem 'capybara'
|
gem 'capybara'
|
||||||
gem 'factory_girl_rails'
|
gem 'factory_girl_rails'
|
||||||
|
gem 'launchy'
|
||||||
|
end
|
||||||
|
|
||||||
|
group :test do
|
||||||
|
gem 'database_cleaner'
|
||||||
|
gem 'poltergeist'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
19
Gemfile.lock
19
Gemfile.lock
@@ -43,6 +43,7 @@ GEM
|
|||||||
activesupport (>= 4.0)
|
activesupport (>= 4.0)
|
||||||
awesome_nested_set (>= 3.0)
|
awesome_nested_set (>= 3.0)
|
||||||
acts_as_votable (0.10.0)
|
acts_as_votable (0.10.0)
|
||||||
|
addressable (2.3.8)
|
||||||
arel (6.0.2)
|
arel (6.0.2)
|
||||||
awesome_nested_set (3.0.2)
|
awesome_nested_set (3.0.2)
|
||||||
activerecord (>= 4.0.0, < 5)
|
activerecord (>= 4.0.0, < 5)
|
||||||
@@ -58,6 +59,7 @@ GEM
|
|||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
rack-test (>= 0.5.4)
|
rack-test (>= 0.5.4)
|
||||||
xpath (~> 2.0)
|
xpath (~> 2.0)
|
||||||
|
cliver (0.3.2)
|
||||||
coffee-rails (4.1.0)
|
coffee-rails (4.1.0)
|
||||||
coffee-script (>= 2.2.0)
|
coffee-script (>= 2.2.0)
|
||||||
railties (>= 4.0.0, < 5.0)
|
railties (>= 4.0.0, < 5.0)
|
||||||
@@ -66,6 +68,7 @@ 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)
|
||||||
|
database_cleaner (1.4.1)
|
||||||
debug_inspector (0.0.2)
|
debug_inspector (0.0.2)
|
||||||
devise (3.5.1)
|
devise (3.5.1)
|
||||||
bcrypt (~> 3.0)
|
bcrypt (~> 3.0)
|
||||||
@@ -96,6 +99,8 @@ GEM
|
|||||||
railties (>= 4.2.0)
|
railties (>= 4.2.0)
|
||||||
thor (>= 0.14, < 2.0)
|
thor (>= 0.14, < 2.0)
|
||||||
json (1.8.3)
|
json (1.8.3)
|
||||||
|
launchy (2.4.3)
|
||||||
|
addressable (~> 2.3)
|
||||||
loofah (2.0.2)
|
loofah (2.0.2)
|
||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
mail (2.6.3)
|
mail (2.6.3)
|
||||||
@@ -108,6 +113,11 @@ GEM
|
|||||||
mini_portile (~> 0.6.0)
|
mini_portile (~> 0.6.0)
|
||||||
orm_adapter (0.5.0)
|
orm_adapter (0.5.0)
|
||||||
pg (0.18.2)
|
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 (1.6.4)
|
||||||
rack-test (0.6.3)
|
rack-test (0.6.3)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
@@ -191,6 +201,9 @@ GEM
|
|||||||
binding_of_caller (>= 0.7.2)
|
binding_of_caller (>= 0.7.2)
|
||||||
railties (>= 4.0)
|
railties (>= 4.0)
|
||||||
sprockets-rails (>= 2.0, < 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)
|
xpath (2.0.0)
|
||||||
nokogiri (~> 1.3)
|
nokogiri (~> 1.3)
|
||||||
|
|
||||||
@@ -204,12 +217,15 @@ DEPENDENCIES
|
|||||||
byebug
|
byebug
|
||||||
capybara
|
capybara
|
||||||
coffee-rails (~> 4.1.0)
|
coffee-rails (~> 4.1.0)
|
||||||
|
database_cleaner
|
||||||
devise
|
devise
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
foundation-rails
|
foundation-rails
|
||||||
jbuilder (~> 2.0)
|
jbuilder (~> 2.0)
|
||||||
jquery-rails
|
jquery-rails
|
||||||
|
launchy
|
||||||
pg
|
pg
|
||||||
|
poltergeist
|
||||||
rails (= 4.2.3)
|
rails (= 4.2.3)
|
||||||
recaptcha
|
recaptcha
|
||||||
responders
|
responders
|
||||||
@@ -220,6 +236,3 @@ DEPENDENCIES
|
|||||||
turbolinks
|
turbolinks
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
web-console (~> 2.0)
|
web-console (~> 2.0)
|
||||||
|
|
||||||
BUNDLED WITH
|
|
||||||
1.10.5
|
|
||||||
|
|||||||
13
app/assets/javascripts/comments.js.coffee
Normal file
13
app/assets/javascripts/comments.js.coffee
Normal 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)
|
||||||
11
app/helpers/comments_helper.rb
Normal file
11
app/helpers/comments_helper.rb
Normal 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
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
<%= form_for [@debate, Comment.new] do |f| %>
|
<%= link_to comment_link_text(parent), "", class: "js-add-comment-link", data: {'id': dom_id(parent)} %>
|
||||||
<%= f.text_area :body %>
|
|
||||||
<%= f.hidden_field :commentable_type, value: parent.class %>
|
|
||||||
<%= f.hidden_field :commentable_id, value: parent.id %>
|
|
||||||
|
|
||||||
<%= f.submit 'Publicar comentario' %>
|
<div id="js-comment-form-<%= dom_id(parent) %>" style="display:none">
|
||||||
<% end %>
|
<%= 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 comment_button_text(parent) %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
@@ -19,13 +19,15 @@ feature 'Comments' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Create' do
|
scenario 'Create', :js do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
debate = create(:debate)
|
debate = create(:debate)
|
||||||
|
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit debate_path(debate)
|
||||||
|
|
||||||
|
click_on 'Comentar'
|
||||||
|
|
||||||
fill_in 'comment_body', with: '¿Has pensado en esto...?'
|
fill_in 'comment_body', with: '¿Has pensado en esto...?'
|
||||||
click_button 'Publicar comentario'
|
click_button 'Publicar comentario'
|
||||||
|
|
||||||
@@ -36,7 +38,7 @@ feature 'Comments' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Reply' do
|
scenario 'Reply', :js do
|
||||||
citizen = create(:user, first_name: 'Ana')
|
citizen = create(:user, first_name: 'Ana')
|
||||||
manuela = create(:user, first_name: 'Manuela')
|
manuela = create(:user, first_name: 'Manuela')
|
||||||
debate = create(:debate)
|
debate = create(:debate)
|
||||||
@@ -45,9 +47,10 @@ feature 'Comments' do
|
|||||||
login_as(manuela)
|
login_as(manuela)
|
||||||
visit debate_path(debate)
|
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.'
|
fill_in 'comment_body', with: 'La semana que viene está hecho.'
|
||||||
click_button 'Publicar comentario'
|
click_button 'Publicar respuesta'
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_content 'Comentario guardado'
|
expect(page).to have_content 'Comentario guardado'
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ 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?
|
||||||
|
|
||||||
require 'spec_helper'
|
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
|
require 'spec_helper'
|
||||||
require 'capybara/rails'
|
require 'capybara/rails'
|
||||||
require 'capybara/rspec'
|
require 'capybara/rspec'
|
||||||
|
require 'capybara/poltergeist'
|
||||||
|
|
||||||
include Warden::Test::Helpers
|
include Warden::Test::Helpers
|
||||||
Warden.test_mode!
|
Warden.test_mode!
|
||||||
@@ -13,6 +14,7 @@ Warden.test_mode!
|
|||||||
ActiveRecord::Migration.maintain_test_schema!
|
ActiveRecord::Migration.maintain_test_schema!
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.use_transactional_fixtures = true
|
|
||||||
config.infer_spec_type_from_file_location!
|
config.infer_spec_type_from_file_location!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Capybara.javascript_driver = :poltergeist
|
||||||
|
|||||||
@@ -1,9 +1,26 @@
|
|||||||
require 'factory_girl_rails'
|
require 'factory_girl_rails'
|
||||||
|
require 'database_cleaner'
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
config.use_transactional_fixtures = false
|
||||||
|
|
||||||
config.filter_run :focus
|
config.filter_run :focus
|
||||||
config.run_all_when_everything_filtered = true
|
config.run_all_when_everything_filtered = true
|
||||||
config.include FactoryGirl::Syntax::Methods
|
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
|
# Allows RSpec to persist some state between runs in order to support
|
||||||
# the `--only-failures` and `--next-failure` CLI options.
|
# the `--only-failures` and `--next-failure` CLI options.
|
||||||
config.example_status_persistence_file_path = "spec/examples.txt"
|
config.example_status_persistence_file_path = "spec/examples.txt"
|
||||||
|
|||||||
Reference in New Issue
Block a user