├── .gitignore ├── .rspec ├── .travis.yml ├── Gemfile ├── README.md ├── Rakefile ├── app ├── assets │ ├── images │ │ └── rails.png │ ├── javascripts │ │ ├── application.js │ │ └── comments.js │ └── stylesheets │ │ ├── application.css │ │ └── scaffold.css ├── controllers │ ├── application_controller.rb │ └── comments_controller.rb ├── helpers │ ├── application_helper.rb │ └── comments_helper.rb ├── models │ └── comment.rb └── views │ ├── comments │ ├── _comment.html.erb │ ├── _form.html.erb │ ├── _new_comment_links.html.erb │ ├── create.js.erb │ ├── destroy.js.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb │ └── layouts │ └── application.html.erb ├── config.ru ├── config ├── application.rb ├── boot.rb ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── backtrace_silencers.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── secret_token.rb │ └── session_store.rb ├── locales │ └── en.yml └── routes.rb ├── db ├── migrate │ ├── 20110209210252_create_comments.rb │ └── 20110209210315_add_attachment_to_comment.rb ├── schema.rb └── seeds.rb ├── doc └── README_FOR_APP ├── gemfiles ├── 3.2.gemfile ├── 4.0.gemfile ├── 4.1.gemfile └── 4.2.gemfile ├── lib └── tasks │ └── .gitkeep ├── public ├── 404.html ├── 422.html ├── 500.html ├── favicon.ico ├── robots.txt └── stylesheets │ └── .gitkeep ├── script └── rails ├── spec ├── features │ └── comments_spec.rb ├── spec_helper.rb └── support │ └── integration_helper.rb └── vendor └── plugins └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle 2 | db/*.sqlite3 3 | log/*.log 4 | tmp/ 5 | *.swp 6 | .rvmrc 7 | public/system/* 8 | Gemfile.lock 9 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --colour 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 1.9.3 4 | - 2.0.0 5 | - 2.1.1 6 | - 2.1.5 7 | env: 8 | - "RAILS_VERSION=3.2" 9 | - "RAILS_VERSION=4.0" 10 | - "RAILS_VERSION=4.1" 11 | - "RAILS_VERSION=4.2" 12 | script: 13 | - RAILS_ENV=test xvfb-run bundle exec rspec -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | rails_version = ENV["RAILS_VERSION"] || "default" 4 | 5 | rails = case rails_version 6 | when "default" 7 | "~> 3.2.0" 8 | else 9 | "~> #{rails_version}" 10 | end 11 | 12 | version = ENV["RAILS_VERSION"] || "3.2" 13 | 14 | eval_gemfile File.expand_path("../gemfiles/#{version}.gemfile", __FILE__) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Demo Rails 3.1 App with jQuery UJS (AJAX) 2 | ========================================= 3 | 4 | [![Build Status](https://travis-ci.org/JangoSteve/Rails-jQuery-Demo.svg?branch=master)](https://travis-ci.org/JangoSteve/Rails-jQuery-Demo) 5 | 6 | This is a very simple demo Rails 3.1 with all CRUD 7 | (create, read, update, delete) functionality in AJAX using the jquery-rails 8 | gem which bundles jquery-ujs. 9 | 10 | For relevant code, see the Comments controller and views. Also see unobtrusive 11 | bindings in app/assets/javascripts/comments.js. 12 | 13 | Documentation & Resources 14 | ------------------------- 15 | 16 | Documentation and resources for the Rails jquery-ujs may be found in the 17 | following articles: 18 | 19 | * [Rails 3 Remote Links and Forms: A Definitive Guide](http://www.alfajango.com/blog/rails-3-remote-links-and-forms/) 20 | * [Rails 3 Remote Links and Forms Part 2: Data-type with jQuery](http://www.alfajango.com/blog/rails-3-remote-links-and-forms-data-type-with-jquery/) 21 | * [http://www.alfajango.com/blog/rails-jquery-ujs-now-interactive/](http://www.alfajango.com/blog/rails-jquery-ujs-now-interactive/) 22 | * [New ajax:aborted Rails jQuery UJS Hooks](http://www.alfajango.com/blog/new-ajax-aborted-rails-jquery-ujs-callbacks/) 23 | * [Wiki](https://github.com/rails/jquery-ujs/wiki) 24 | 25 | Also, see the [remotipart branch](https://github.com/JangoSteve/Rails-jQuery-Demo/tree/remotipart) for AJAX file-upload functionality. 26 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | require 'rake' 6 | 7 | JqueryRails::Application.load_tasks 8 | -------------------------------------------------------------------------------- /app/assets/images/rails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JangoSteve/Rails-jQuery-Demo/ce3b4dcfa45fb57bac2bb3bf9faaadb7e5994560/app/assets/images/rails.png -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // FIXME: Tell people that this is a manifest file, real code should go into discrete files 2 | // FIXME: Tell people how Sprockets and CoffeeScript works 3 | // 4 | //= require jquery 5 | //= require jquery_ujs 6 | //= require_tree . 7 | -------------------------------------------------------------------------------- /app/assets/javascripts/comments.js: -------------------------------------------------------------------------------- 1 | $(document) 2 | .delegate('#new-comment-link, #new-comment-attachment-link', 'ajax:success', function(e, data, status, xhr){ 3 | var $this = $(this), 4 | $container = $('#new-comment-links'), 5 | $responseText = $(xhr.responseText), 6 | $cancelButton = $responseText.find('#cancel-button'); 7 | $container.replaceWith($responseText) 8 | $cancelButton.click(function(e){ 9 | $cancelButton.parent().replaceWith($container); 10 | e.preventDefault(); 11 | }); 12 | }) 13 | .delegate('form[data-remote]', 'ajax:aborted:required', function(){ 14 | var $form = $(this), 15 | errorDivId = 'ajax-validation-errors', 16 | $errorDiv = $form.find('#' + errorDivId); 17 | if ( ! $errorDiv.length ) { 18 | $errorDiv = $('
', { id: errorDivId}); 19 | $form.prepend($errorDiv) 20 | } 21 | $errorDiv.html($('

', { 22 | text: 'You must fill in all required fields!' 23 | })); 24 | }); 25 | 26 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * FIXME: Introduce SCSS & Sprockets 3 | *= require 'scaffold' 4 | *= require_self 5 | *= require_tree . 6 | */ 7 | -------------------------------------------------------------------------------- /app/assets/stylesheets/scaffold.css: -------------------------------------------------------------------------------- 1 | body { background-color: #fff; color: #333; } 2 | 3 | body, p, ol, ul, td { 4 | font-family: verdana, arial, helvetica, sans-serif; 5 | font-size: 13px; 6 | line-height: 18px; 7 | } 8 | 9 | pre { 10 | background-color: #eee; 11 | padding: 10px; 12 | font-size: 11px; 13 | } 14 | 15 | a { color: #000; } 16 | a:visited { color: #666; } 17 | a:hover { color: #fff; background-color:#000; } 18 | 19 | div.field, div.actions { 20 | margin-bottom: 10px; 21 | } 22 | 23 | #notice { 24 | color: green; 25 | } 26 | 27 | legend.required:before { 28 | content: "*"; 29 | color: red; 30 | } 31 | label.required:after { 32 | content: "*"; 33 | color: red; 34 | } 35 | 36 | .field_with_errors { 37 | padding: 2px; 38 | background-color: red; 39 | display: table; 40 | } 41 | 42 | #error_explanation, #ajax-validation-errors { 43 | width: 450px; 44 | border: 2px solid red; 45 | padding: 7px; 46 | padding-bottom: 0; 47 | margin-bottom: 20px; 48 | background-color: #f0f0f0; 49 | } 50 | 51 | #error_explanation h2, #ajax-validation-errors h2{ 52 | text-align: left; 53 | font-weight: bold; 54 | padding: 5px 5px 5px 15px; 55 | font-size: 12px; 56 | margin: -7px; 57 | margin-bottom: 0px; 58 | background-color: #c00; 59 | color: #fff; 60 | } 61 | 62 | #error_explanation ul li { 63 | font-size: 12px; 64 | list-style: square; 65 | } 66 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | end 4 | -------------------------------------------------------------------------------- /app/controllers/comments_controller.rb: -------------------------------------------------------------------------------- 1 | class CommentsController < ApplicationController 2 | respond_to :js, :json, :html, :xml 3 | #respond_to :js, :only => [:create, :update, :destroy] 4 | # GET /comments 5 | # GET /comments.xml 6 | def index 7 | @comments = Comment.all 8 | end 9 | 10 | # GET /comments/1 11 | # GET /comments/1.xml 12 | def show 13 | @comment = Comment.find(params[:id]) 14 | end 15 | 16 | # GET /comments/new 17 | # GET /comments/new.xml 18 | def new 19 | @comment = Comment.new 20 | #respond_with(@comment, :layout => false) 21 | respond_with do |format| 22 | format.html { render :layout => ! request.xhr? } 23 | end 24 | end 25 | 26 | # GET /comments/1/edit 27 | def edit 28 | @comment = Comment.find(params[:id]) 29 | end 30 | 31 | # POST /comments 32 | # POST /comments.xml 33 | def create 34 | @comment = Comment.create(comment_params) 35 | sleep 1 if params[:pause] 36 | respond_with(@comment) 37 | #redirect_to comments_path unless request.xhr? 38 | end 39 | 40 | # PUT /comments/1 41 | # PUT /comments/1.xml 42 | def update 43 | @comment = Comment.find(params[:id]) 44 | respond_with do |format| 45 | format.html{ redirect_to @comment } 46 | end 47 | end 48 | 49 | # DELETE /comments/1 50 | # DELETE /comments/1.xml 51 | def destroy 52 | @comment = Comment.destroy(params[:id]) 53 | end 54 | 55 | private 56 | 57 | def comment_params 58 | if ENV["RAILS_VERSION"] != '3.2' 59 | params.require(:comment).permit(:subject, :body, :attachment) 60 | else 61 | params[:comment] 62 | end 63 | end 64 | 65 | end 66 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/comments_helper.rb: -------------------------------------------------------------------------------- 1 | module CommentsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/models/comment.rb: -------------------------------------------------------------------------------- 1 | class Comment < ActiveRecord::Base 2 | has_attached_file :attachment 3 | validates :subject, :body, :presence => true 4 | do_not_validate_attachment_file_type :attachment 5 | end 6 | -------------------------------------------------------------------------------- /app/views/comments/_comment.html.erb: -------------------------------------------------------------------------------- 1 | 2 | <%= comment.subject %> 3 | <%= comment.body %> 4 | <%= link_to comment.attachment_file_name, comment.attachment.url if comment.attachment? %> 5 | <%= link_to 'Show', comment %> 6 | <%= link_to 'Edit', edit_comment_path(comment) %> 7 | <%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete, :remote => true %> 8 | 9 | -------------------------------------------------------------------------------- /app/views/comments/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@comment, :remote => (params[:action] == 'new' ? true : false)) do |f| %> 2 | <% if @comment.errors.any? %> 3 |
4 |

<%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:

5 | 6 |
    7 | <% @comment.errors.full_messages.each do |msg| %> 8 |
  • <%= msg %>
  • 9 | <% end %> 10 |
11 |
12 | <% end %> 13 | 14 |
15 | 16 | Required fields 17 | 18 |
19 | <%= f.label :subject, :class => 'required' %>
20 | <%= f.text_field :subject, :required => true %> 21 |
22 |
23 | <%= f.label :body, :class => 'required' %>
24 | <%= f.text_area :body, :required => true %> 25 |
26 | <% if params[:attachment] %> 27 |
28 | <%= f.label :attachment, :class => 'required' %>
29 | <%= f.file_field :attachment, :required => true %> 30 |
31 | <% end %> 32 |
33 |
34 | <%= f.submit data:{:disable_with => 'Submitting...'} %> 35 |
36 | <% end %> 37 | -------------------------------------------------------------------------------- /app/views/comments/_new_comment_links.html.erb: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /app/views/comments/create.js.erb: -------------------------------------------------------------------------------- 1 | <% unless @comment.errors.any? %> 2 | $('#comments').append( '<%= escape_javascript( 3 | render @comment 4 | ) %>' ); 5 | $('#new-comment-form-container').find('input:not(:submit),select,textarea').val(''); 6 | <% else %> 7 | var $form = $('#new_comment'), 8 | $errorDiv = $('
'), 9 | $errorList = $('
    '); 10 | <% @comment.errors.full_messages.each do |msg| %> 11 | $errorList.append('
  • <%= escape_javascript msg %>
  • '); 12 | <% end %> 13 | $form.find('#error_explanation').remove(); 14 | $form.prepend($errorDiv.append($errorList)); 15 | <% end %> 16 | -------------------------------------------------------------------------------- /app/views/comments/destroy.js.erb: -------------------------------------------------------------------------------- 1 | $('#comment-<%= @comment.id %>').remove(); 2 | -------------------------------------------------------------------------------- /app/views/comments/edit.html.erb: -------------------------------------------------------------------------------- 1 |

    Editing comment

    2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Show', @comment %> | 6 | <%= link_to 'Back', comments_path %> 7 | -------------------------------------------------------------------------------- /app/views/comments/index.html.erb: -------------------------------------------------------------------------------- 1 |

    Listing comments

    2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | <%= render @comments %> 14 |
    SubjectBodyAttachment 8 |
    15 | 16 |
    17 | 18 | <%= render 'new_comment_links' %> 19 | -------------------------------------------------------------------------------- /app/views/comments/new.html.erb: -------------------------------------------------------------------------------- 1 |
    2 |

    New comment

    3 | 4 | <%= render 'form' %> 5 | 6 | <%= link_to 'Cancel', comments_path, :id => 'cancel-button' %> 7 |
    8 | -------------------------------------------------------------------------------- /app/views/comments/show.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | <%= render @comment %> 11 |
    SubjectBodyAttachment
    12 | 13 |
    14 | 15 | <%= link_to 'Back', comments_path %> 16 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JqueryRails 5 | <%= stylesheet_link_tag "application" %> 6 | <%= javascript_include_tag "application" %> 7 | <%= csrf_meta_tag %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run JqueryRails::Application 5 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | # If you have a Gemfile, require the gems listed there, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(:default, Rails.env) if defined?(Bundler) 8 | 9 | module JqueryRails 10 | class Application < Rails::Application 11 | # Settings in config/environments/* take precedence over those specified here. 12 | # Application configuration should go into files in config/initializers 13 | # -- all .rb files in that directory are automatically loaded. 14 | 15 | # Custom directories with classes and modules you want to be autoloadable. 16 | # config.autoload_paths += %W(#{config.root}/extras) 17 | 18 | # Only load the plugins named here, in the order given (default is alphabetical). 19 | # :all can be used as a placeholder for all plugins not explicitly named. 20 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 21 | 22 | # Activate observers that should always be running. 23 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 24 | 25 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 26 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 27 | # config.time_zone = 'Central Time (US & Canada)' 28 | 29 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 30 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 31 | # config.i18n.default_locale = :de 32 | 33 | # JavaScript files you want as :defaults (application.js is always included). 34 | # config.action_view.javascript_expansions[:defaults] = %w(jquery rails) 35 | 36 | # Configure the default encoding used in templates for Ruby 1.9. 37 | config.encoding = "utf-8" 38 | 39 | # Configure sensitive parameters which will be filtered from the log file. 40 | config.filter_parameters += [:password] 41 | 42 | config.assets.enabled = true 43 | 44 | config.generators do |g| 45 | g.test_framework :rspec 46 | g.view_specs false 47 | g.controller_specs false 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | # Set up gems listed in the Gemfile. 4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 5 | 6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 7 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | development: 4 | adapter: sqlite3 5 | database: db/development.sqlite3 6 | pool: 5 7 | timeout: 5000 8 | 9 | # Warning: The database defined as "test" will be erased and 10 | # re-generated from your development database when you run "rake". 11 | # Do not set this db to the same as development or production. 12 | test: 13 | adapter: sqlite3 14 | database: ":memory:" 15 | 16 | production: 17 | adapter: sqlite3 18 | database: db/production.sqlite3 19 | pool: 5 20 | timeout: 5000 21 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | JqueryRails::Application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | JqueryRails::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the webserver when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger 20 | config.active_support.deprecation = :log 21 | 22 | # Only use best-standards-support built into browsers 23 | config.action_dispatch.best_standards_support = :builtin 24 | end 25 | 26 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | JqueryRails::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The production environment is meant for finished, "live" apps. 5 | # Code is not reloaded between requests 6 | config.cache_classes = true 7 | 8 | # Full error reports are disabled and caching is turned on 9 | config.consider_all_requests_local = false 10 | config.action_controller.perform_caching = true 11 | 12 | # Specifies the header that your server uses for sending files 13 | config.action_dispatch.x_sendfile_header = "X-Sendfile" 14 | 15 | # For nginx: 16 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' 17 | 18 | # If you have no front-end server that supports something like X-Sendfile, 19 | # just comment this out and Rails will serve the files 20 | 21 | # See everything in the log (default is :info) 22 | # config.log_level = :debug 23 | 24 | # Use a different logger for distributed setups 25 | # config.logger = SyslogLogger.new 26 | 27 | # Use a different cache store in production 28 | # config.cache_store = :mem_cache_store 29 | 30 | # Disable Rails's static asset server 31 | # In production, Apache or nginx will already do this 32 | config.serve_static_assets = false 33 | 34 | # Enable serving of images, stylesheets, and javascripts from an asset server 35 | # config.action_controller.asset_host = "http://assets.example.com" 36 | 37 | # Disable delivery errors, bad email addresses will be ignored 38 | # config.action_mailer.raise_delivery_errors = false 39 | 40 | # Enable threaded mode 41 | # config.threadsafe! 42 | 43 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 44 | # the I18n.default_locale when a translation can not be found) 45 | config.i18n.fallbacks = true 46 | 47 | # Send deprecation notices to registered listeners 48 | config.active_support.deprecation = :notify 49 | end 50 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | JqueryRails::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Log error messages when you accidentally call methods on nil. 11 | config.whiny_nils = true 12 | 13 | # Show full error reports and disable caching 14 | config.consider_all_requests_local = true 15 | config.action_controller.perform_caching = false 16 | 17 | # Raise exceptions instead of rendering exception templates 18 | config.action_dispatch.show_exceptions = false 19 | 20 | # Disable request forgery protection in test environment 21 | config.action_controller.allow_forgery_protection = false 22 | 23 | # Tell Action Mailer not to deliver emails to the real world. 24 | # The :test delivery method accumulates sent emails in the 25 | # ActionMailer::Base.deliveries array. 26 | config.action_mailer.delivery_method = :test 27 | 28 | # Use SQL instead of Active Record's schema dumper when creating the test database. 29 | # This is necessary if your schema can't be completely dumped by the schema dumper, 30 | # like if you have constraints or database-specific column types 31 | # config.active_record.schema_format = :sql 32 | 33 | # Print deprecation notices to the stderr 34 | config.active_support.deprecation = :stderr 35 | end 36 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | JqueryRails::Application.config.secret_token = '14d748ccb7bec478834026d9ccd18693720043771abe1482a5de414d7e5c8e2bd1bff76c5c3fb23f1416cd733621cdf8da87b0ee6921c39af39cf6a71de399ad' 8 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | JqueryRails::Application.config.session_store :cookie_store, :key => '_jquery-rails_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # JqueryRails::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | JqueryRails::Application.routes.draw do 2 | resources :comments 3 | 4 | # The priority is based upon order of creation: 5 | # first created -> highest priority. 6 | 7 | # Sample of regular route: 8 | # match 'products/:id' => 'catalog#view' 9 | # Keep in mind you can assign values other than :controller and :action 10 | 11 | # Sample of named route: 12 | # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase 13 | # This route can be invoked with purchase_url(:id => product.id) 14 | 15 | # Sample resource route (maps HTTP verbs to controller actions automatically): 16 | # resources :products 17 | 18 | # Sample resource route with options: 19 | # resources :products do 20 | # member do 21 | # get 'short' 22 | # post 'toggle' 23 | # end 24 | # 25 | # collection do 26 | # get 'sold' 27 | # end 28 | # end 29 | 30 | # Sample resource route with sub-resources: 31 | # resources :products do 32 | # resources :comments, :sales 33 | # resource :seller 34 | # end 35 | 36 | # Sample resource route with more complex sub-resources 37 | # resources :products do 38 | # resources :comments 39 | # resources :sales do 40 | # get 'recent', :on => :collection 41 | # end 42 | # end 43 | 44 | # Sample resource route within a namespace: 45 | # namespace :admin do 46 | # # Directs /admin/products/* to Admin::ProductsController 47 | # # (app/controllers/admin/products_controller.rb) 48 | # resources :products 49 | # end 50 | 51 | # You can have the root of your site routed with "root" 52 | # just remember to delete public/index.html. 53 | # root :to => "welcome#index" 54 | root :to => "comments#index" 55 | 56 | # See how all your routes lay out with "rake routes" 57 | 58 | # This is a legacy wild controller route that's not recommended for RESTful applications. 59 | # Note: This route will make all actions in every controller accessible via GET requests. 60 | # match ':controller(/:action(/:id(.:format)))' 61 | end 62 | -------------------------------------------------------------------------------- /db/migrate/20110209210252_create_comments.rb: -------------------------------------------------------------------------------- 1 | class CreateComments < ActiveRecord::Migration 2 | def self.up 3 | create_table :comments do |t| 4 | t.string :subject 5 | t.text :body 6 | 7 | t.timestamps 8 | end 9 | end 10 | 11 | def self.down 12 | drop_table :comments 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20110209210315_add_attachment_to_comment.rb: -------------------------------------------------------------------------------- 1 | class AddAttachmentToComment < ActiveRecord::Migration 2 | def self.up 3 | add_column :comments, :attachment_file_name, :string 4 | add_column :comments, :attachment_content_type, :string 5 | add_column :comments, :attachment_file_size, :integer 6 | add_column :comments, :attachment_updated_at, :datetime 7 | end 8 | 9 | def self.down 10 | remove_column :comments, :attachment_file_name 11 | remove_column :comments, :attachment_content_type 12 | remove_column :comments, :attachment_file_size 13 | remove_column :comments, :attachment_updated_at 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended that you check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(version: 20110209210315) do 15 | 16 | create_table "comments", force: :cascade do |t| 17 | t.string "subject" 18 | t.text "body" 19 | t.datetime "created_at" 20 | t.datetime "updated_at" 21 | t.string "attachment_file_name" 22 | t.string "attachment_content_type" 23 | t.integer "attachment_file_size" 24 | t.datetime "attachment_updated_at" 25 | end 26 | 27 | end 28 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) 7 | # Mayor.create(:name => 'Daley', :city => cities.first) 8 | -------------------------------------------------------------------------------- /doc/README_FOR_APP: -------------------------------------------------------------------------------- 1 | Use this README file to introduce your application and point to useful places in the API for learning more. 2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. 3 | -------------------------------------------------------------------------------- /gemfiles/3.2.gemfile: -------------------------------------------------------------------------------- 1 | gem "rails", "~> 3.2.0" 2 | 3 | gem 'sass' 4 | gem 'coffee-script' 5 | gem 'uglifier' 6 | 7 | # Bundle edge Rails instead: 8 | # gem 'rails', :git => 'git://github.com/rails/rails.git' 9 | 10 | gem 'sqlite3' 11 | 12 | gem 'paperclip' 13 | gem 'jquery-rails' 14 | #gem 'activerecord-sqlite3-adapter' 15 | 16 | # Use unicorn as the web server 17 | # gem 'unicorn' 18 | 19 | # Deploy with Capistrano 20 | # gem 'capistrano' 21 | 22 | # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+) 23 | # gem 'ruby-debug' 24 | # gem 'ruby-debug19' 25 | 26 | # Bundle the extra gems: 27 | # gem 'bj' 28 | # gem 'nokogiri' 29 | # gem 'sqlite3-ruby', :require => 'sqlite3' 30 | # gem 'aws-s3', :require => 'aws/s3' 31 | 32 | # Bundle gems for the local environment. Make sure to 33 | # put test-only gems in this group so their generators 34 | # and rake tasks are available in development mode: 35 | # group :development, :test do 36 | # gem 'webrat' 37 | # end 38 | group :development, :test do 39 | gem 'rspec-rails' 40 | gem 'selenium-webdriver', '~> 2.44.0' 41 | gem 'capybara' 42 | gem 'launchy' 43 | end 44 | 45 | group :test do 46 | gem 'database_cleaner' 47 | end -------------------------------------------------------------------------------- /gemfiles/4.0.gemfile: -------------------------------------------------------------------------------- 1 | gem "rails", "~> 4.0" 2 | 3 | gem 'sass' 4 | gem 'coffee-script' 5 | gem 'uglifier' 6 | 7 | # Bundle edge Rails instead: 8 | # gem 'rails', :git => 'git://github.com/rails/rails.git' 9 | 10 | gem 'sqlite3' 11 | 12 | gem 'paperclip' 13 | gem 'jquery-rails' 14 | gem 'responders', '~> 2.0' 15 | #gem 'activerecord-sqlite3-adapter' 16 | 17 | # Use unicorn as the web server 18 | # gem 'unicorn' 19 | 20 | # Deploy with Capistrano 21 | # gem 'capistrano' 22 | 23 | # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+) 24 | # gem 'ruby-debug' 25 | # gem 'ruby-debug19' 26 | 27 | # Bundle the extra gems: 28 | # gem 'bj' 29 | # gem 'nokogiri' 30 | # gem 'sqlite3-ruby', :require => 'sqlite3' 31 | # gem 'aws-s3', :require => 'aws/s3' 32 | 33 | # Bundle gems for the local environment. Make sure to 34 | # put test-only gems in this group so their generators 35 | # and rake tasks are available in development mode: 36 | # group :development, :test do 37 | # gem 'webrat' 38 | # end 39 | group :development, :test do 40 | gem 'rspec-rails' 41 | gem 'selenium-webdriver', '~> 2.44.0' 42 | gem 'capybara' 43 | gem 'launchy' 44 | end 45 | 46 | group :test do 47 | gem 'database_cleaner' 48 | end -------------------------------------------------------------------------------- /gemfiles/4.1.gemfile: -------------------------------------------------------------------------------- 1 | gem "rails", "~> 4.1" 2 | 3 | gem 'sass' 4 | gem 'coffee-script' 5 | gem 'uglifier' 6 | 7 | # Bundle edge Rails instead: 8 | # gem 'rails', :git => 'git://github.com/rails/rails.git' 9 | 10 | gem 'sqlite3' 11 | 12 | gem 'paperclip' 13 | gem 'jquery-rails' 14 | gem 'responders', '~> 2.0' 15 | #gem 'activerecord-sqlite3-adapter' 16 | 17 | # Use unicorn as the web server 18 | # gem 'unicorn' 19 | 20 | # Deploy with Capistrano 21 | # gem 'capistrano' 22 | 23 | # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+) 24 | # gem 'ruby-debug' 25 | # gem 'ruby-debug19' 26 | 27 | # Bundle the extra gems: 28 | # gem 'bj' 29 | # gem 'nokogiri' 30 | # gem 'sqlite3-ruby', :require => 'sqlite3' 31 | # gem 'aws-s3', :require => 'aws/s3' 32 | 33 | # Bundle gems for the local environment. Make sure to 34 | # put test-only gems in this group so their generators 35 | # and rake tasks are available in development mode: 36 | # group :development, :test do 37 | # gem 'webrat' 38 | # end 39 | group :development, :test do 40 | gem 'rspec-rails' 41 | gem 'selenium-webdriver', '~> 2.44.0' 42 | gem 'capybara' 43 | gem 'launchy' 44 | end 45 | 46 | group :test do 47 | gem 'database_cleaner' 48 | end -------------------------------------------------------------------------------- /gemfiles/4.2.gemfile: -------------------------------------------------------------------------------- 1 | gem "rails", "~> 4.2" 2 | 3 | gem 'sass' 4 | gem 'coffee-script' 5 | gem 'uglifier' 6 | 7 | # Bundle edge Rails instead: 8 | # gem 'rails', :git => 'git://github.com/rails/rails.git' 9 | 10 | gem 'sqlite3' 11 | 12 | gem 'paperclip' 13 | gem 'jquery-rails' 14 | gem 'responders', '~> 2.0' 15 | #gem 'activerecord-sqlite3-adapter' 16 | 17 | # Use unicorn as the web server 18 | # gem 'unicorn' 19 | 20 | # Deploy with Capistrano 21 | # gem 'capistrano' 22 | 23 | # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+) 24 | # gem 'ruby-debug' 25 | # gem 'ruby-debug19' 26 | 27 | # Bundle the extra gems: 28 | # gem 'bj' 29 | # gem 'nokogiri' 30 | # gem 'sqlite3-ruby', :require => 'sqlite3' 31 | # gem 'aws-s3', :require => 'aws/s3' 32 | 33 | # Bundle gems for the local environment. Make sure to 34 | # put test-only gems in this group so their generators 35 | # and rake tasks are available in development mode: 36 | # group :development, :test do 37 | # gem 'webrat' 38 | # end 39 | group :development, :test do 40 | gem 'rspec-rails' 41 | gem 'selenium-webdriver', '~> 2.44.0' 42 | gem 'capybara' 43 | gem 'launchy' 44 | end 45 | 46 | group :test do 47 | gem 'database_cleaner' 48 | end -------------------------------------------------------------------------------- /lib/tasks/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JangoSteve/Rails-jQuery-Demo/ce3b4dcfa45fb57bac2bb3bf9faaadb7e5994560/lib/tasks/.gitkeep -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
    22 |

    The page you were looking for doesn't exist.

    23 |

    You may have mistyped the address or the page may have moved.

    24 |
    25 | 26 | 27 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
    22 |

    The change you wanted was rejected.

    23 |

    Maybe you tried to change something you didn't have access to.

    24 |
    25 | 26 | 27 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
    22 |

    We're sorry, but something went wrong.

    23 |

    We've been notified about this issue and we'll take a look at it shortly.

    24 |
    25 | 26 | 27 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JangoSteve/Rails-jQuery-Demo/ce3b4dcfa45fb57bac2bb3bf9faaadb7e5994560/public/favicon.ico -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-Agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /public/stylesheets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JangoSteve/Rails-jQuery-Demo/ce3b4dcfa45fb57bac2bb3bf9faaadb7e5994560/public/stylesheets/.gitkeep -------------------------------------------------------------------------------- /script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /spec/features/comments_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'tempfile' 3 | 4 | describe 'comments' do 5 | it 'creates a new comment', js: true do 6 | visit root_path 7 | click_link 'New Comment' 8 | 9 | # New Comment link should disappear 10 | expect(page).to have_no_link('New Comment') 11 | # Comment form should appear 12 | expect(page).to have_field('comment_subject') 13 | expect(page).to have_field('comment_body') 14 | expect(page).to have_no_field('comment_file') 15 | 16 | # Filling in form and submitting 17 | comment_subject = 'A new comment!' 18 | comment_body = 'Woo, this is my comment, dude.' 19 | fill_in 'comment_subject', with: comment_subject 20 | fill_in 'comment_body', with: comment_body 21 | click_button 'Create Comment' 22 | 23 | # Comment should appear in the comments table 24 | within '#comments' do 25 | expect(page).to have_content(comment_subject) 26 | expect(page).to have_content(comment_body) 27 | end 28 | # Form should clear 29 | expect(page).to have_field('comment_subject', with: '') 30 | expect(page).to have_field('comment_body', with: '') 31 | # ...and be replaced by link again 32 | expect(page).to have_link('Cancel') 33 | end 34 | 35 | it "cancels creating a comment", js: true do 36 | visit root_path 37 | click_link 'New Comment' 38 | 39 | expect(page).to have_field('comment_subject') 40 | expect(page).to have_link('Cancel') 41 | click_link 'Cancel' 42 | 43 | # Form should disappear 44 | expect(page).to have_no_field('comment_subject') 45 | expect(page).to have_link('New Comment') 46 | end 47 | 48 | it "deletes a comment", js: true do 49 | Comment.create(subject: 'The Great Yogurt', body: 'The Schwarz is strong with this one.') 50 | 51 | visit root_path 52 | within '#comments' do 53 | expect(page).to have_content('The Great Yogurt') 54 | accept_js_confirm do 55 | click_link 'Destroy' 56 | end 57 | 58 | expect(page).to have_no_content('The Great Yogurt') 59 | end 60 | end 61 | 62 | it "aborts ajax file upload and submits normally", js: true do 63 | visit root_path 64 | click_link 'New Comment with Attachment' 65 | 66 | page.execute_script("$(document).delegate('form', 'ajax:aborted:file', function() { $('#comments').after('aborted: file'); return false; });") 67 | 68 | # Filling in form and submitting 69 | comment_subject = 'A new comment!' 70 | comment_body = 'Woo, this is my comment, dude.' 71 | fill_in 'comment_subject', with: comment_subject 72 | fill_in 'comment_body', with: comment_body 73 | # Attach file 74 | file = Tempfile.new('foo') 75 | attach_file 'comment_attachment', file.path 76 | click_button 'Create Comment' 77 | 78 | # Comment should appear in the comments table 79 | expect(page).to have_content('aborted: file') 80 | 81 | page.execute_script("$(document).delegate('form', 'ajax:aborted:file', function() { return true; });") 82 | click_button 'Create Comment' 83 | 84 | # Comment should appear in the comments table 85 | within '.comment' do 86 | expect(page).to have_content(comment_subject) 87 | expect(page).to have_content(comment_body) 88 | end 89 | end 90 | 91 | it "Disables submit button while submitting", js: true do 92 | visit root_path 93 | 94 | click_link 'New Comment' 95 | # Needed to make test wait for above to finish 96 | form = find('form') 97 | 98 | page.execute_script(%q{$('form').append('');}) 99 | 100 | button = find_button('Create Comment') 101 | 102 | fill_in 'comment_subject', with: 'Hi' 103 | fill_in 'comment_body', with: 'there' 104 | click_button 'Create Comment' 105 | 106 | expect(%w(true disabled)).to include(button[:disabled]) 107 | expect(button.value).to eq "Submitting..." 108 | 109 | sleep 1.5 110 | 111 | expect(button[:disabled]).to_not be 112 | expect(button.value).to eq "Create Comment" 113 | end 114 | end 115 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | ENV["RAILS_ENV"] ||= 'test' 3 | require File.expand_path("../../config/environment", __FILE__) 4 | require 'rspec/rails' 5 | require 'capybara/rspec' 6 | require 'capybara/rails' 7 | require 'database_cleaner' 8 | 9 | # Requires supporting ruby files with custom matchers and macros, etc, 10 | # in spec/support/ and its subdirectories. 11 | Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 12 | 13 | def in_memory_database? 14 | Rails.env == "test" and 15 | ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLite3Adapter || 16 | ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLiteAdapter and 17 | Rails.configuration.database_configuration['test']['database'] == ':memory:' 18 | end 19 | 20 | if in_memory_database? 21 | class ActiveRecord::Base 22 | mattr_accessor :shared_connection 23 | @@shared_connection = nil 24 | 25 | def self.connection 26 | @@shared_connection || retrieve_connection 27 | end 28 | end 29 | end 30 | 31 | # Forces all threads to share the same connection. This works on 32 | # Capybara because it starts the web server in a thread. 33 | ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection 34 | 35 | RSpec.configure do |config| 36 | 37 | if in_memory_database? 38 | load "#{Rails.root.to_s}/db/schema.rb" # use db agnostic schema by default 39 | end 40 | 41 | config.include IntegrationHelper, :type => :feature 42 | config.include Rails.application.routes.url_helpers 43 | config.include Capybara::DSL 44 | # == Mock Framework 45 | # 46 | # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 47 | # 48 | # config.mock_with :mocha 49 | # config.mock_with :flexmock 50 | # config.mock_with :rr 51 | config.mock_with :rspec 52 | 53 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 54 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 55 | 56 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 57 | # examples within a transaction, remove the following line or assign false 58 | # instead of true. 59 | config.use_transactional_fixtures = false 60 | 61 | config.filter_run focus: true 62 | config.run_all_when_everything_filtered = true 63 | 64 | config.before(:suite) do 65 | DatabaseCleaner.strategy = :truncation 66 | end 67 | 68 | config.before(:each) do 69 | DatabaseCleaner.start 70 | end 71 | 72 | config.after(:each) do 73 | DatabaseCleaner.clean 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /spec/support/integration_helper.rb: -------------------------------------------------------------------------------- 1 | module IntegrationHelper 2 | # If you do something that triggers a confirm, do it inside an accept_js_confirm or reject_js_confirm block 3 | def accept_js_confirm 4 | page.evaluate_script 'window.original_confirm_function = window.confirm;' 5 | page.evaluate_script 'window.confirm = function(msg) { return true; }' 6 | yield 7 | page.evaluate_script 'window.confirm = window.original_confirm_function;' 8 | end 9 | 10 | # If you do something that triggers a confirm, do it inside an accept_js_confirm or reject_js_confirm block 11 | def reject_js_confirm 12 | page.evaluate_script 'window.original_confirm_function = window.confirm;' 13 | page.evaluate_script 'window.confirm = function(msg) { return false; }' 14 | yield 15 | page.evaluate_script 'window.confirm = window.original_confirm_function;' 16 | end 17 | end 18 | 19 | RSpec.configure do |config| 20 | config.include IntegrationHelper 21 | end -------------------------------------------------------------------------------- /vendor/plugins/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JangoSteve/Rails-jQuery-Demo/ce3b4dcfa45fb57bac2bb3bf9faaadb7e5994560/vendor/plugins/.gitkeep --------------------------------------------------------------------------------