remotipart 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +35 -0
  3. data/Appraisals +25 -0
  4. data/Gemfile +13 -0
  5. data/History.rdoc +5 -0
  6. data/README.rdoc +2 -0
  7. data/Rakefile +5 -7
  8. data/gemfiles/rails_3.2.gemfile +26 -0
  9. data/gemfiles/rails_4.2.gemfile +24 -0
  10. data/gemfiles/rails_5.2.gemfile +24 -0
  11. data/gemfiles/rails_6.0.gemfile +24 -0
  12. data/lib/remotipart/rails/version.rb +2 -2
  13. data/lib/remotipart/render_overrides.rb +2 -2
  14. data/lib/remotipart/view_helper.rb +0 -9
  15. data/remotipart.gemspec +76 -4
  16. data/spec/dummy_app/.gitignore +17 -0
  17. data/spec/dummy_app/Rakefile +7 -0
  18. data/spec/dummy_app/app/assets/images/rails.png +0 -0
  19. data/spec/dummy_app/app/assets/javascripts/application.js.erb +8 -0
  20. data/spec/dummy_app/app/assets/javascripts/comments.js +28 -0
  21. data/spec/dummy_app/app/assets/stylesheets/application.css +6 -0
  22. data/spec/dummy_app/app/assets/stylesheets/scaffold.css +65 -0
  23. data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
  24. data/spec/dummy_app/app/controllers/comments_controller.rb +72 -0
  25. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  26. data/spec/dummy_app/app/helpers/comments_helper.rb +2 -0
  27. data/spec/dummy_app/app/models/comment.rb +7 -0
  28. data/spec/dummy_app/app/views/comments/_comment.html.erb +9 -0
  29. data/spec/dummy_app/app/views/comments/_form.html.erb +40 -0
  30. data/spec/dummy_app/app/views/comments/_new_comment_links.html.erb +5 -0
  31. data/spec/dummy_app/app/views/comments/create.html.erb +7 -0
  32. data/spec/dummy_app/app/views/comments/create.js.erb +20 -0
  33. data/spec/dummy_app/app/views/comments/destroy.js.erb +1 -0
  34. data/spec/dummy_app/app/views/comments/edit.html.erb +6 -0
  35. data/spec/dummy_app/app/views/comments/escape_test.html.erb +1 -0
  36. data/spec/dummy_app/app/views/comments/index.html.erb +19 -0
  37. data/spec/dummy_app/app/views/comments/new.html.erb +7 -0
  38. data/spec/dummy_app/app/views/comments/show.html.erb +15 -0
  39. data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
  40. data/spec/dummy_app/bin/bundle +3 -0
  41. data/spec/dummy_app/bin/rails +4 -0
  42. data/spec/dummy_app/bin/rake +4 -0
  43. data/spec/dummy_app/bin/setup +34 -0
  44. data/spec/dummy_app/bin/update +29 -0
  45. data/spec/dummy_app/config.ru +4 -0
  46. data/spec/dummy_app/config/application.rb +18 -0
  47. data/spec/dummy_app/config/boot.rb +3 -0
  48. data/spec/dummy_app/config/database.yml +7 -0
  49. data/spec/dummy_app/config/environment.rb +5 -0
  50. data/spec/dummy_app/config/environments/development.rb +54 -0
  51. data/spec/dummy_app/config/environments/test.rb +53 -0
  52. data/spec/dummy_app/config/initializers/secret_token.rb +3 -0
  53. data/spec/dummy_app/config/routes.rb +6 -0
  54. data/spec/dummy_app/config/secrets.yml +5 -0
  55. data/spec/dummy_app/db/migrate/20110209210252_create_comments.rb +14 -0
  56. data/spec/dummy_app/db/migrate/20110209210315_add_attachment_to_comment.rb +15 -0
  57. data/spec/dummy_app/db/migrate/20110714205346_add_other_attachment_to_comment.rb +8 -0
  58. data/spec/dummy_app/db/schema.rb +31 -0
  59. data/spec/dummy_app/db/seeds.rb +7 -0
  60. data/spec/features/comments_spec.rb +414 -0
  61. data/spec/fixtures/hi.txt +1 -0
  62. data/spec/fixtures/qr.jpg +0 -0
  63. data/spec/spec_helper.rb +40 -0
  64. data/spec/support/arel_helper.rb +15 -0
  65. data/spec/support/connection_helper.rb +12 -0
  66. data/spec/support/integration_helper.rb +28 -0
  67. data/vendor/assets/javascripts/jquery.iframe-transport.js +3 -1
  68. metadata +130 -3
@@ -0,0 +1,8 @@
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_asset "jquery#{ENV['JQUERY_VERSION']}" %>
5
+ <% require_asset "jquery_ujs" %>
6
+ <% require_asset "jquery.remotipart" %>
7
+ <% require_asset "comments" %>
8
+
@@ -0,0 +1,28 @@
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 = $('<div>', { id: errorDivId});
19
+ $form.prepend($errorDiv)
20
+ }
21
+ $errorDiv.html($('<h2>', {
22
+ text: 'You must fill in all required fields!'
23
+ }));
24
+ })
25
+ .delegate('form[data-remote]', 'ajax:error', function(e, xhr, status, statusText) {
26
+ $('#comments').after('Error status code: ' + xhr.status + ', Error status message: ' + statusText);
27
+ });
28
+
@@ -0,0 +1,6 @@
1
+ /*
2
+ * FIXME: Introduce SCSS & Sprockets
3
+ *= require 'scaffold'
4
+ *= require_self
5
+ *= require_tree .
6
+ */
@@ -0,0 +1,65 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,72 @@
1
+ class CommentsController < ApplicationController
2
+ def index
3
+ @comments = Comment.all
4
+ respond_to do |format|
5
+ format.html
6
+ format.json { render json: @comments }
7
+ end
8
+ end
9
+
10
+ def show
11
+ @comment = Comment.find(params[:id])
12
+ respond_to do |format|
13
+ format.html
14
+ format.json { render json: @comment }
15
+ end
16
+ end
17
+
18
+ def new
19
+ @comment = Comment.new
20
+ respond_to do |format|
21
+ format.html { render :layout => ! request.xhr? }
22
+ end
23
+ end
24
+
25
+ def edit
26
+ @comment = Comment.find(params[:id])
27
+ respond_to do |format|
28
+ format.html
29
+ format.json { render json: @comment }
30
+ end
31
+ end
32
+
33
+ def create
34
+ @comment = Comment.create(comment_params)
35
+ if request.xhr? || remotipart_submitted?
36
+ sleep 1 if params[:pause]
37
+ respond_to do |format|
38
+ format.html { render (params[:template] == 'escape' ? 'comments/escape_test' : 'comments/create'), layout: false }
39
+ format.js { render 'comments/create', layout: false, status:(@comment.errors.any? ? :unprocessable_entity : :ok) }
40
+ format.json { render json: @comment }
41
+ end
42
+ else
43
+ redirect_to comments_path
44
+ end
45
+ end
46
+
47
+ def update
48
+ @comment = Comment.find(params[:id])
49
+ respond_to do |format|
50
+ format.html { redirect_to @comment }
51
+ format.js { render json: @comment }
52
+ end
53
+ end
54
+
55
+ def destroy
56
+ @comment = Comment.destroy(params[:id])
57
+ end
58
+
59
+ def say
60
+ if Rails.version < '4'
61
+ render text: params[:message], content_type: 'text/plain'
62
+ else
63
+ render plain: params[:message]
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def comment_params
70
+ params.require(:comment).permit(:subject, :body, :attachment, :other_attachment)
71
+ end
72
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module CommentsHelper
2
+ end
@@ -0,0 +1,7 @@
1
+ class Comment < ActiveRecord::Base
2
+ has_attached_file :attachment
3
+ has_attached_file :other_attachment
4
+ validates :subject, :body, :presence => true
5
+ validates_attachment :attachment, content_type: { content_type: /\Aimage\/.*\Z/ }
6
+ validates_attachment :other_attachment, content_type: { content_type: 'text/plain' }
7
+ end
@@ -0,0 +1,9 @@
1
+ <tr class='comment' id='comment-<%= comment.id %>'>
2
+ <td><%= comment.subject %></td>
3
+ <td><%= comment.body %></td>
4
+ <td><%= link_to comment.attachment_file_name, comment.attachment.url if comment.attachment? %></td>
5
+ <td><%= link_to comment.other_attachment_file_name, comment.other_attachment.url if comment.other_attachment? %></td>
6
+ <td><%= link_to 'Show', comment %></td>
7
+ <td><%= link_to 'Edit', edit_comment_path(comment) %></td>
8
+ <td><%= link_to 'Destroy', comment, :data => {:confirm => 'Are you sure?'}, :method => :delete, :remote => true %></td>
9
+ </tr>
@@ -0,0 +1,40 @@
1
+ <%= form_for(@comment, :remote => (params[:action] == 'new' ? true : false)) do |f| %>
2
+ <% if @comment.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @comment.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <fieldset>
15
+ <legend class='required'>
16
+ Required fields
17
+ </legend>
18
+ <div class="field">
19
+ <%= f.label :subject, :class => 'required' %><br />
20
+ <%= f.text_field :subject, :required => true %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :body, :class => 'required' %><br />
24
+ <%= f.text_area :body, :required => true %>
25
+ </div>
26
+ <% if params[:attachment] %>
27
+ <div class="field">
28
+ <%= f.label :attachment %><br />
29
+ <%= f.file_field :attachment %>
30
+ </div>
31
+ <div class="field">
32
+ <%= f.label :other_attachment %><br />
33
+ <%= f.file_field :other_attachment %>
34
+ </div>
35
+ <% end %>
36
+ </fieldset>
37
+ <div class="actions">
38
+ <%= f.submit :data => {disable_with: "Submitting..."} %>
39
+ </div>
40
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <div id='new-comment-links'>
2
+ <%= link_to 'New Comment', new_comment_path, :remote => true, :'data-type' => 'html', :id => 'new-comment-link' %>
3
+ <br />
4
+ <%= link_to 'New Comment with Attachment', new_comment_path(:attachment => true), :remote => true, :'data-type' => 'html', :id => 'new-comment-attachment-link' %>
5
+ </div>
@@ -0,0 +1,7 @@
1
+ <span>
2
+ HTML response:
3
+ </span>
4
+
5
+ <table>
6
+ <%= render @comment %>
7
+ </table>
@@ -0,0 +1,20 @@
1
+ <%= remotipart_response do %>
2
+ <% unless @comment.errors.any? %>
3
+ $('#comments').append( '<%= escape_javascript(
4
+ render @comment
5
+ ) %>' );
6
+ $('#new-comment-form-container').find('input:not(:submit),select,textarea').val('');
7
+ <% if request.put? %>
8
+ $('#comments').after('PUT request!');
9
+ <% end %>
10
+ <% else %>
11
+ var $form = $('#new_comment'),
12
+ $errorDiv = $('<div id="error_explanation">'),
13
+ $errorList = $('<ul>');
14
+ <% @comment.errors.full_messages.each do |msg| %>
15
+ $errorList.append('<li><%= escape_javascript msg %></li>');
16
+ <% end %>
17
+ $form.find('#error_explanation').remove();
18
+ $form.prepend($errorDiv.append($errorList));
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1 @@
1
+ $('#comment-<%= @comment.id %>').remove();
@@ -0,0 +1,6 @@
1
+ <h1>Editing comment</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @comment %> |
6
+ <%= link_to 'Back', comments_path %>
@@ -0,0 +1 @@
1
+ <%= text_field_tag :quote, '"' %>
@@ -0,0 +1,19 @@
1
+ <h1>Listing comments</h1>
2
+
3
+ <table id='comments'>
4
+ <tr>
5
+ <th>Subject</th>
6
+ <th>Body</th>
7
+ <th>Attachment</td>
8
+ <th>Other Attachment</td>
9
+ <th></th>
10
+ <th></th>
11
+ <th></th>
12
+ </tr>
13
+
14
+ <%= render @comments %>
15
+ </table>
16
+
17
+ <br />
18
+
19
+ <%= render 'new_comment_links' %>
@@ -0,0 +1,7 @@
1
+ <div id='new-comment-form-container'>
2
+ <h1>New comment</h1>
3
+
4
+ <%= render 'form' %>
5
+
6
+ <%= link_to 'Cancel', comments_path, :id => 'cancel-button' %>
7
+ </div>
@@ -0,0 +1,15 @@
1
+ <table>
2
+ <tr>
3
+ <th>Subject</th>
4
+ <th>Body</th>
5
+ <th>Attachment</th>
6
+ <th></th>
7
+ <th></th>
8
+ <th></th>
9
+ </tr>
10
+ <%= render @comment %>
11
+ </table>
12
+
13
+ <br />
14
+
15
+ <%= link_to 'Back', comments_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>JqueryRails</title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') or system!('bundle install')
20
+
21
+ # puts "\n== Copying sample files =="
22
+ # unless File.exist?('config/database.yml')
23
+ # cp 'config/database.yml.sample', 'config/database.yml'
24
+ # end
25
+
26
+ puts "\n== Preparing database =="
27
+ system! 'bin/rails db:setup'
28
+
29
+ puts "\n== Removing old logs and tempfiles =="
30
+ system! 'bin/rails log:clear tmp:clear'
31
+
32
+ puts "\n== Restarting application server =="
33
+ system! 'bin/rails restart'
34
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a way to update your development environment automatically.
15
+ # Add necessary update steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system 'bundle check' or system! 'bundle install'
20
+
21
+ puts "\n== Updating database =="
22
+ system! 'bin/rails db:migrate'
23
+
24
+ puts "\n== Removing old logs and tempfiles =="
25
+ system! 'bin/rails log:clear tmp:clear'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system! 'bin/rails restart'
29
+ end