diff --git a/Gemfile b/Gemfile index f2ef657e5..751fab83b 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 34de0c6d2..98a7de5b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee new file mode 100644 index 000000000..b40da3485 --- /dev/null +++ b/app/assets/javascripts/comments.js.coffee @@ -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) \ No newline at end of file diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 000000000..8e8aae90c --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -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 \ No newline at end of file diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 4ef99b4b0..e3f796026 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,7 +1,11 @@ -<%= 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' %> -<% end %> \ No newline at end of file +<%= link_to comment_link_text(parent), "", class: "js-add-comment-link", data: {'id': dom_id(parent)} %> + +
\ No newline at end of file diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index f392003e2..31c07770c 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -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' diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index fc6f2bb68..2d2a80824 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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 \ No newline at end of file +end + +Capybara.javascript_driver = :poltergeist diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7ad54cc81..156073f78 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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"