remotipart 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +35 -0
- data/Appraisals +25 -0
- data/Gemfile +13 -0
- data/History.rdoc +5 -0
- data/README.rdoc +2 -0
- data/Rakefile +5 -7
- data/gemfiles/rails_3.2.gemfile +26 -0
- data/gemfiles/rails_4.2.gemfile +24 -0
- data/gemfiles/rails_5.2.gemfile +24 -0
- data/gemfiles/rails_6.0.gemfile +24 -0
- data/lib/remotipart/rails/version.rb +2 -2
- data/lib/remotipart/render_overrides.rb +2 -2
- data/lib/remotipart/view_helper.rb +0 -9
- data/remotipart.gemspec +76 -4
- data/spec/dummy_app/.gitignore +17 -0
- data/spec/dummy_app/Rakefile +7 -0
- data/spec/dummy_app/app/assets/images/rails.png +0 -0
- data/spec/dummy_app/app/assets/javascripts/application.js.erb +8 -0
- data/spec/dummy_app/app/assets/javascripts/comments.js +28 -0
- data/spec/dummy_app/app/assets/stylesheets/application.css +6 -0
- data/spec/dummy_app/app/assets/stylesheets/scaffold.css +65 -0
- data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
- data/spec/dummy_app/app/controllers/comments_controller.rb +72 -0
- data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_app/app/helpers/comments_helper.rb +2 -0
- data/spec/dummy_app/app/models/comment.rb +7 -0
- data/spec/dummy_app/app/views/comments/_comment.html.erb +9 -0
- data/spec/dummy_app/app/views/comments/_form.html.erb +40 -0
- data/spec/dummy_app/app/views/comments/_new_comment_links.html.erb +5 -0
- data/spec/dummy_app/app/views/comments/create.html.erb +7 -0
- data/spec/dummy_app/app/views/comments/create.js.erb +20 -0
- data/spec/dummy_app/app/views/comments/destroy.js.erb +1 -0
- data/spec/dummy_app/app/views/comments/edit.html.erb +6 -0
- data/spec/dummy_app/app/views/comments/escape_test.html.erb +1 -0
- data/spec/dummy_app/app/views/comments/index.html.erb +19 -0
- data/spec/dummy_app/app/views/comments/new.html.erb +7 -0
- data/spec/dummy_app/app/views/comments/show.html.erb +15 -0
- data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy_app/bin/bundle +3 -0
- data/spec/dummy_app/bin/rails +4 -0
- data/spec/dummy_app/bin/rake +4 -0
- data/spec/dummy_app/bin/setup +34 -0
- data/spec/dummy_app/bin/update +29 -0
- data/spec/dummy_app/config.ru +4 -0
- data/spec/dummy_app/config/application.rb +18 -0
- data/spec/dummy_app/config/boot.rb +3 -0
- data/spec/dummy_app/config/database.yml +7 -0
- data/spec/dummy_app/config/environment.rb +5 -0
- data/spec/dummy_app/config/environments/development.rb +54 -0
- data/spec/dummy_app/config/environments/test.rb +53 -0
- data/spec/dummy_app/config/initializers/secret_token.rb +3 -0
- data/spec/dummy_app/config/routes.rb +6 -0
- data/spec/dummy_app/config/secrets.yml +5 -0
- data/spec/dummy_app/db/migrate/20110209210252_create_comments.rb +14 -0
- data/spec/dummy_app/db/migrate/20110209210315_add_attachment_to_comment.rb +15 -0
- data/spec/dummy_app/db/migrate/20110714205346_add_other_attachment_to_comment.rb +8 -0
- data/spec/dummy_app/db/schema.rb +31 -0
- data/spec/dummy_app/db/seeds.rb +7 -0
- data/spec/features/comments_spec.rb +414 -0
- data/spec/fixtures/hi.txt +1 -0
- data/spec/fixtures/qr.jpg +0 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/support/arel_helper.rb +15 -0
- data/spec/support/connection_helper.rb +12 -0
- data/spec/support/integration_helper.rb +28 -0
- data/vendor/assets/javascripts/jquery.iframe-transport.js +3 -1
- metadata +130 -3
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(*Rails.groups)
|
8
|
+
|
9
|
+
module DummyApp
|
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
|
+
config.assets.paths << Rails.root.join("..", "..", "vendor", "assets", "javascripts")
|
14
|
+
config.active_record.raise_in_transactional_callbacks = true if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR == 2
|
15
|
+
config.active_record.time_zone_aware_types = [:datetime, :time] if Rails::VERSION::MAJOR >= 5
|
16
|
+
config.active_record.sqlite3.represent_boolean_as_integer = true if config.active_record.sqlite3.respond_to?(:represent_boolean_as_integer=) && Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
DummyApp::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 web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
|
15
|
+
# Enable/disable caching. By default caching is disabled.
|
16
|
+
if Rails.root.join('tmp/caching-dev.txt').exist?
|
17
|
+
config.action_controller.perform_caching = true
|
18
|
+
config.cache_store = :memory_store
|
19
|
+
config.public_file_server.headers = {'Cache-Control' => 'public, max-age=172800'}
|
20
|
+
else
|
21
|
+
config.action_controller.perform_caching = false
|
22
|
+
config.cache_store = :null_store
|
23
|
+
end
|
24
|
+
|
25
|
+
# Don't care if the mailer can't send.
|
26
|
+
config.action_mailer.raise_delivery_errors = false
|
27
|
+
|
28
|
+
# Print deprecation notices to the Rails logger.
|
29
|
+
config.active_support.deprecation = :log
|
30
|
+
|
31
|
+
# Raise an error on page load if there are pending migrations.
|
32
|
+
config.active_record.migration_error = :page_load
|
33
|
+
|
34
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
35
|
+
# This option may cause significant delays in view rendering with a large
|
36
|
+
# number of complex assets.
|
37
|
+
config.assets.debug = true
|
38
|
+
|
39
|
+
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
|
40
|
+
# yet still be able to expire them through the digest params.
|
41
|
+
config.assets.digest = true
|
42
|
+
|
43
|
+
# Adds additional error checking when serving assets at runtime.
|
44
|
+
# Checks for improperly declared sprockets dependencies.
|
45
|
+
# Raises helpful error messages.
|
46
|
+
config.assets.raise_runtime_errors = true
|
47
|
+
|
48
|
+
# Raises error for missing translations
|
49
|
+
# config.action_view.raise_on_missing_translations = true
|
50
|
+
|
51
|
+
# Use an evented file watcher to asynchronously detect changes in source code,
|
52
|
+
# routes, locales, etc. This feature depends on the listen gem.
|
53
|
+
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
54
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
DummyApp::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
|
+
# Do not eager load code on boot. This avoids loading your whole application
|
11
|
+
# just for the purpose of running a single test. If you are using a tool that
|
12
|
+
# preloads Rails for running tests, you may have to set it to true.
|
13
|
+
config.eager_load = false
|
14
|
+
|
15
|
+
# Configure public file server for tests with Cache-Control for performance.
|
16
|
+
if config.respond_to?(:public_file_server)
|
17
|
+
config.public_file_server.enabled = true
|
18
|
+
config.public_file_server.headers = {'Cache-Control' => 'public, max-age=3600'}
|
19
|
+
else
|
20
|
+
if Rails::VERSION::MAJOR < 4
|
21
|
+
config.assets.enabled = true
|
22
|
+
config.assets.debug = true
|
23
|
+
config.serve_static_assets = true
|
24
|
+
else
|
25
|
+
config.serve_static_files = true
|
26
|
+
end
|
27
|
+
config.static_cache_control = 'public, max-age=3600'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Show full error reports and disable caching.
|
31
|
+
config.consider_all_requests_local = true
|
32
|
+
config.action_controller.perform_caching = false
|
33
|
+
|
34
|
+
# Raise exceptions instead of rendering exception templates.
|
35
|
+
config.action_dispatch.show_exceptions = false
|
36
|
+
|
37
|
+
# Disable request forgery protection in test environment.
|
38
|
+
config.action_controller.allow_forgery_protection = false
|
39
|
+
|
40
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
41
|
+
# The :test delivery method accumulates sent emails in the
|
42
|
+
# ActionMailer::Base.deliveries array.
|
43
|
+
config.action_mailer.delivery_method = :test
|
44
|
+
|
45
|
+
# Randomize the order test cases are executed.
|
46
|
+
config.active_support.test_order = :random
|
47
|
+
|
48
|
+
# Print deprecation notices to the stderr.
|
49
|
+
config.active_support.deprecation = :stderr
|
50
|
+
|
51
|
+
# Raises error for missing translations
|
52
|
+
# config.action_view.raise_on_missing_translations = true
|
53
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
development:
|
2
|
+
secret_key_base: d059ae03480564f4e9dcb7c96b901e5803037b0e09fd53e96343dff0d18dc54390a2f07b99c231eacb1d0cc6b74b90676fec4786afaf0f2e7f69b971ab2f9600
|
3
|
+
|
4
|
+
test:
|
5
|
+
secret_key_base: e5e0e4811c8cfc047799cf3e82d1626adbf02fa7a3530b4bdd39cc17e1098d328f4da6ada090ec01449b5c92662bcec92cfb13b4c3c4c4bb3fac5a303e91c356
|
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class AddOtherAttachmentToComment < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :comments, :other_attachment_file_name, :string
|
4
|
+
add_column :comments, :other_attachment_content_type, :string
|
5
|
+
add_column :comments, :other_attachment_file_size, :integer
|
6
|
+
add_column :comments, :other_attachment_updated_at, :datetime
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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 to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20110714205346) do
|
15
|
+
|
16
|
+
create_table "comments", :force => true 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
|
+
t.string "other_attachment_file_name"
|
26
|
+
t.string "other_attachment_content_type"
|
27
|
+
t.integer "other_attachment_file_size"
|
28
|
+
t.datetime "other_attachment_updated_at"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,7 @@
|
|
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)
|
@@ -0,0 +1,414 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'comments', type: :feature do
|
4
|
+
it 'creates a new comment', js: true do
|
5
|
+
visit root_path
|
6
|
+
click_link 'New Comment'
|
7
|
+
|
8
|
+
# New Comment link should disappear
|
9
|
+
expect(page).to have_no_link('New Comment')
|
10
|
+
# Comment form should appear
|
11
|
+
expect(page).to have_field('comment_subject')
|
12
|
+
expect(page).to have_field('comment_body')
|
13
|
+
expect(page).to have_no_field('comment_file')
|
14
|
+
|
15
|
+
# Filling in form and submitting
|
16
|
+
comment_subject = 'A new comment!'
|
17
|
+
comment_body = 'Woo, this is my comment, dude.'
|
18
|
+
fill_in 'comment_subject', with: comment_subject
|
19
|
+
fill_in 'comment_body', with: comment_body
|
20
|
+
click_button 'Create Comment'
|
21
|
+
|
22
|
+
# Comment should appear in the comments table
|
23
|
+
within '#comments' do
|
24
|
+
expect(page).to have_content(comment_subject)
|
25
|
+
expect(page).to have_content(comment_body)
|
26
|
+
end
|
27
|
+
# Form should clear
|
28
|
+
expect(page).to have_field('comment_subject', with: '')
|
29
|
+
expect(page).to have_field('comment_body', with: '')
|
30
|
+
# ...and be replaced by link again
|
31
|
+
expect(page).to have_link('Cancel')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "cancels creating a comment", js: true do
|
35
|
+
visit root_path
|
36
|
+
click_link 'New Comment'
|
37
|
+
|
38
|
+
expect(page).to have_field('comment_subject')
|
39
|
+
expect(page).to have_link('Cancel')
|
40
|
+
click_link 'Cancel'
|
41
|
+
|
42
|
+
# Form should disappear
|
43
|
+
expect(page).to have_no_field('comment_subject')
|
44
|
+
expect(page).to have_link('New Comment')
|
45
|
+
end
|
46
|
+
|
47
|
+
it "deletes a comment", js: true do
|
48
|
+
Comment.create(subject: 'The Great Yogurt', body: 'The Schwarz is strong with this one.')
|
49
|
+
visit root_path
|
50
|
+
|
51
|
+
within '#comments' do
|
52
|
+
expect(page).to have_content('The Great Yogurt')
|
53
|
+
accept_js_confirm do
|
54
|
+
click_link 'Destroy'
|
55
|
+
end
|
56
|
+
|
57
|
+
expect(page).to have_no_content('The Great Yogurt')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "uploads a file", js: true do
|
62
|
+
visit root_path
|
63
|
+
click_link 'New Comment with Attachment'
|
64
|
+
|
65
|
+
expect(page).to have_field('comment_subject')
|
66
|
+
expect(page).to have_field('comment_body')
|
67
|
+
expect(page).to have_field('comment_attachment')
|
68
|
+
expect(page).to have_field('comment_other_attachment')
|
69
|
+
|
70
|
+
comment_subject = 'Newby'
|
71
|
+
comment_body = 'Woot, a file!'
|
72
|
+
fill_in 'comment_subject', with: comment_subject
|
73
|
+
fill_in 'comment_body', with: comment_body
|
74
|
+
|
75
|
+
# Attach file
|
76
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
77
|
+
other_file_path = File.join(fixture_path, 'hi.txt')
|
78
|
+
attach_file 'comment_attachment', file_path
|
79
|
+
attach_file 'comment_other_attachment', other_file_path
|
80
|
+
|
81
|
+
page_should_not_redirect do
|
82
|
+
click_button 'Create Comment'
|
83
|
+
end
|
84
|
+
|
85
|
+
within '#comments' do
|
86
|
+
expect(page).to have_selector("td", text: comment_subject)
|
87
|
+
expect(page).to have_selector("td", text: comment_body)
|
88
|
+
expect(page).to have_selector("a", text: File.basename(file_path))
|
89
|
+
expect(page).to have_selector("a", text: File.basename(other_file_path))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "Disables submit button while submitting", js: true do
|
94
|
+
visit root_path
|
95
|
+
|
96
|
+
click_link 'New Comment'
|
97
|
+
# Needed to make test wait for above to finish
|
98
|
+
form = find('form')
|
99
|
+
|
100
|
+
button = find_button('Create Comment')
|
101
|
+
page.execute_script(%q{$('form').append('<input name="pause" type="hidden" value=1 />');})
|
102
|
+
|
103
|
+
fill_in 'comment_subject', with: 'Hi'
|
104
|
+
fill_in 'comment_body', with: 'there'
|
105
|
+
click_button 'Create Comment'
|
106
|
+
|
107
|
+
expect(button[:disabled]).to be true
|
108
|
+
expect(button.value).to eq "Submitting..."
|
109
|
+
|
110
|
+
sleep 1.5
|
111
|
+
|
112
|
+
expect(button[:disabled]).to be false
|
113
|
+
expect(button.value).to eq "Create Comment"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "triggers ajax:remotipartSubmit event hook", js: true do
|
117
|
+
visit root_path
|
118
|
+
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function() { $('#comments').after('remotipart!'); });")
|
119
|
+
|
120
|
+
click_link 'New Comment with Attachment'
|
121
|
+
|
122
|
+
fill_in 'comment_subject', with: 'Hi'
|
123
|
+
fill_in 'comment_body', with: 'there'
|
124
|
+
attach_file 'comment_attachment', File.join(fixture_path, 'qr.jpg')
|
125
|
+
click_button 'Create Comment'
|
126
|
+
|
127
|
+
expect(page).to have_content('remotipart!')
|
128
|
+
end
|
129
|
+
|
130
|
+
it "allows remotipart submission to be cancelable via event hook", js: true do
|
131
|
+
visit root_path
|
132
|
+
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function() { $('#comments').after('remotipart!'); return false; });")
|
133
|
+
|
134
|
+
click_link 'New Comment with Attachment'
|
135
|
+
|
136
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
137
|
+
fill_in 'comment_subject', with: 'Hi'
|
138
|
+
fill_in 'comment_body', with: 'there'
|
139
|
+
attach_file 'comment_attachment', file_path
|
140
|
+
click_button 'Create Comment'
|
141
|
+
|
142
|
+
expect(page).to have_content('remotipart!')
|
143
|
+
|
144
|
+
within '#comments' do
|
145
|
+
expect(page).to have_no_content('Hi')
|
146
|
+
expect(page).to have_no_content('there')
|
147
|
+
expect(page).to have_no_content(File.basename(file_path))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it "allows custom data-type on form", js: true do
|
152
|
+
visit root_path
|
153
|
+
page.execute_script("$(document).delegate('form', 'ajax:success', function(evt, data, status, xhr) { $('#comments').after(xhr.responseText); });")
|
154
|
+
|
155
|
+
click_link 'New Comment with Attachment'
|
156
|
+
|
157
|
+
# Needed to make test wait for above to finish
|
158
|
+
form = find('form')
|
159
|
+
page.execute_script("$('form').attr('data-type', 'html');")
|
160
|
+
|
161
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
162
|
+
fill_in 'comment_subject', with: 'Hi'
|
163
|
+
fill_in 'comment_body', with: 'there'
|
164
|
+
attach_file 'comment_attachment', file_path
|
165
|
+
click_button 'Create Comment'
|
166
|
+
|
167
|
+
expect(page).to have_content('HTML response')
|
168
|
+
end
|
169
|
+
|
170
|
+
it "allows users to use ajax response data safely", js: true do
|
171
|
+
visit root_path
|
172
|
+
page.execute_script("$(document).delegate('form', 'ajax:success', function(evt, data, status, xhr) { $('#comments').after(data); });")
|
173
|
+
|
174
|
+
click_link 'New Comment with Attachment'
|
175
|
+
|
176
|
+
# Needed to make test wait for above to finish
|
177
|
+
form = find('form')
|
178
|
+
page.execute_script("$('form').attr('data-type', 'html');")
|
179
|
+
|
180
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
181
|
+
fill_in 'comment_subject', with: 'Hi'
|
182
|
+
fill_in 'comment_body', with: 'there'
|
183
|
+
attach_file 'comment_attachment', file_path
|
184
|
+
click_button 'Create Comment'
|
185
|
+
|
186
|
+
expect(page).to have_content('HTML response')
|
187
|
+
end
|
188
|
+
|
189
|
+
it "escapes html response content properly", js: true do
|
190
|
+
visit root_path
|
191
|
+
page.execute_script("$(document).delegate('form', 'ajax:success', function(evt, data, status, xhr) { $('#comments').after(xhr.responseText); });")
|
192
|
+
|
193
|
+
click_link 'New Comment with Attachment'
|
194
|
+
|
195
|
+
# Needed to make test wait for above to finish
|
196
|
+
form = find('form')
|
197
|
+
page.execute_script("$('form').attr('data-type', 'html');")
|
198
|
+
page.execute_script("$('form').append('<input type=\"hidden\" name=\"template\" value=\"escape\" />');")
|
199
|
+
|
200
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
201
|
+
fill_in 'comment_subject', with: 'Hi'
|
202
|
+
fill_in 'comment_body', with: 'there'
|
203
|
+
attach_file 'comment_attachment', file_path
|
204
|
+
click_button 'Create Comment'
|
205
|
+
|
206
|
+
expect(find('input[name="quote"]').value).to eq '"'
|
207
|
+
end
|
208
|
+
|
209
|
+
it "returns the correct response status", js: true do
|
210
|
+
visit root_path
|
211
|
+
|
212
|
+
click_link 'New Comment with Attachment'
|
213
|
+
# Needed to make test wait for above to finish
|
214
|
+
input = find('#comment_subject')
|
215
|
+
page.execute_script("$('#comment_subject').removeAttr('required');")
|
216
|
+
|
217
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
218
|
+
fill_in 'comment_body', with: 'there'
|
219
|
+
attach_file 'comment_attachment', file_path
|
220
|
+
click_button 'Create Comment'
|
221
|
+
|
222
|
+
#within '#error_explanation' do
|
223
|
+
# expect(page).to have_content "Subject can't be blank"
|
224
|
+
#end
|
225
|
+
expect(page).to have_content "Error status code: 422"
|
226
|
+
expect(page).to have_content "Error status message: Unprocessable Entity"
|
227
|
+
end
|
228
|
+
|
229
|
+
it "passes the method as _method parameter (rails convention)", js: true do
|
230
|
+
visit root_path
|
231
|
+
|
232
|
+
click_link 'New Comment with Attachment'
|
233
|
+
sleep 0.5
|
234
|
+
page.execute_script(%q{$('form').append('<input name="_method" type="hidden" value="put" />');})
|
235
|
+
|
236
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
237
|
+
fill_in 'comment_subject', with: 'Hi'
|
238
|
+
fill_in 'comment_body', with: 'there'
|
239
|
+
attach_file 'comment_attachment', file_path
|
240
|
+
click_button 'Create Comment'
|
241
|
+
|
242
|
+
expect(page).to have_content 'PUT request!'
|
243
|
+
end
|
244
|
+
|
245
|
+
it "does not submit via remotipart unless file is present", js: true do
|
246
|
+
visit root_path
|
247
|
+
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function() { $('#comments').after('remotipart!'); });")
|
248
|
+
|
249
|
+
click_link 'New Comment with Attachment'
|
250
|
+
|
251
|
+
fill_in 'comment_subject', with: 'Hi'
|
252
|
+
fill_in 'comment_body', with: 'there'
|
253
|
+
click_button 'Create Comment'
|
254
|
+
|
255
|
+
expect(page).to have_no_content('remotipart!')
|
256
|
+
end
|
257
|
+
|
258
|
+
it "fires all the ajax callbacks on the form", js: true do
|
259
|
+
visit root_path
|
260
|
+
click_link 'New Comment with Attachment'
|
261
|
+
|
262
|
+
# Needed to make test wait for above to finish
|
263
|
+
form = find('form')
|
264
|
+
|
265
|
+
page.execute_script("$('form').bind('ajax:beforeSend', function() { $('#comments').after('thebefore'); });")
|
266
|
+
page.execute_script("$(document).delegate('form', 'ajax:success', function() { $('#comments').after('success'); });")
|
267
|
+
page.execute_script("$(document).delegate('form', 'ajax:complete', function() { $('#comments').after('complete'); });")
|
268
|
+
|
269
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
270
|
+
fill_in 'comment_subject', with: 'Hi'
|
271
|
+
fill_in 'comment_body', with: 'there'
|
272
|
+
attach_file 'comment_attachment', file_path
|
273
|
+
click_button 'Create Comment'
|
274
|
+
|
275
|
+
expect(page).to have_content('before')
|
276
|
+
expect(page).to have_content('success')
|
277
|
+
expect(page).to have_content('complete')
|
278
|
+
end
|
279
|
+
|
280
|
+
it "fires the ajax callbacks for json data-type with remotipart", js: true do
|
281
|
+
visit root_path
|
282
|
+
click_link 'New Comment with Attachment'
|
283
|
+
|
284
|
+
# Needed to make test wait for above to finish
|
285
|
+
form = find('form')
|
286
|
+
|
287
|
+
page.execute_script("$('form').data('type', 'json');")
|
288
|
+
|
289
|
+
page.execute_script("$('form').bind('ajax:beforeSend', function() { $('#comments').after('thebefore'); });")
|
290
|
+
page.execute_script("$(document).delegate('form', 'ajax:success', function() { $('#comments').after('success'); });")
|
291
|
+
page.execute_script("$(document).delegate('form', 'ajax:complete', function() { $('#comments').after('complete'); });")
|
292
|
+
|
293
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
294
|
+
fill_in 'comment_subject', with: 'Hi'
|
295
|
+
fill_in 'comment_body', with: 'there'
|
296
|
+
attach_file 'comment_attachment', file_path
|
297
|
+
click_button 'Create Comment'
|
298
|
+
|
299
|
+
expect(page).to have_content('before')
|
300
|
+
expect(page).to have_content('success')
|
301
|
+
expect(page).to have_content('complete')
|
302
|
+
end
|
303
|
+
|
304
|
+
it "only fires the beforeSend hook once", js: true do
|
305
|
+
visit root_path
|
306
|
+
click_link 'New Comment with Attachment'
|
307
|
+
|
308
|
+
# Needed to make test wait for above to finish
|
309
|
+
form = find('form')
|
310
|
+
|
311
|
+
page.execute_script("$('form').bind('ajax:beforeSend', function() { $('#comments').after('<div class=\"ajax\">ajax!</div>'); });")
|
312
|
+
|
313
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
314
|
+
fill_in 'comment_subject', with: 'Hi'
|
315
|
+
fill_in 'comment_body', with: 'there'
|
316
|
+
attach_file 'comment_attachment', file_path
|
317
|
+
click_button 'Create Comment'
|
318
|
+
|
319
|
+
expect(page).to have_css("div.ajax", :count => 1)
|
320
|
+
end
|
321
|
+
|
322
|
+
it "cleans up after itself when uploading files", js: true do
|
323
|
+
visit root_path
|
324
|
+
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function(evt, xhr, data) { if ($(this).data('remotipartSubmitted')) { $('#comments').after('remotipart before!'); } });")
|
325
|
+
|
326
|
+
click_link 'New Comment with Attachment'
|
327
|
+
page.execute_script("$('form').attr('data-type', 'html');")
|
328
|
+
|
329
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
330
|
+
fill_in 'comment_subject', with: 'Hi'
|
331
|
+
fill_in 'comment_body', with: 'there'
|
332
|
+
attach_file 'comment_attachment', file_path
|
333
|
+
click_button 'Create Comment'
|
334
|
+
|
335
|
+
expect(page).to have_content('remotipart before!')
|
336
|
+
|
337
|
+
page.execute_script("if (!$('form').data('remotipartSubmitted')) { $('#comments').after('no remotipart after!'); } ")
|
338
|
+
expect(page).to have_content('no remotipart after!')
|
339
|
+
end
|
340
|
+
|
341
|
+
it "submits via remotipart when a file upload is present", js: true do
|
342
|
+
visit root_path
|
343
|
+
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function(evt, xhr, data) { $('#comments').after('<div class=\"remotipart\">remotipart!</div>'); });")
|
344
|
+
|
345
|
+
click_link 'New Comment with Attachment'
|
346
|
+
page.execute_script("$('form').attr('data-type', 'html');")
|
347
|
+
|
348
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
349
|
+
fill_in 'comment_subject', with: 'Hi'
|
350
|
+
fill_in 'comment_body', with: 'there'
|
351
|
+
attach_file 'comment_attachment', file_path
|
352
|
+
click_button 'Create Comment'
|
353
|
+
|
354
|
+
expect(page).to have_css("div.remotipart")
|
355
|
+
end
|
356
|
+
|
357
|
+
it "does not submit via remotipart when a file upload is not present", js: true do
|
358
|
+
visit root_path
|
359
|
+
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function(evt, xhr, data) { $('#comments').after('<div class=\"remotipart\">remotipart!</div>'); });")
|
360
|
+
|
361
|
+
click_link 'New Comment with Attachment'
|
362
|
+
page.execute_script("$('form').attr('data-type', 'html');")
|
363
|
+
|
364
|
+
fill_in 'comment_subject', with: 'Hi'
|
365
|
+
fill_in 'comment_body', with: 'there'
|
366
|
+
click_button 'Create Comment'
|
367
|
+
|
368
|
+
expect(page).not_to have_css("div.remotipart")
|
369
|
+
end
|
370
|
+
|
371
|
+
it "Disables submit button while submitting with remotipart", js: true do
|
372
|
+
visit root_path
|
373
|
+
|
374
|
+
click_link 'New Comment with Attachment'
|
375
|
+
|
376
|
+
button = find_button('Create Comment')
|
377
|
+
# clicking 'Create Comment' button causes capybara evaluation freeze until request ends, so perform check by JavaScript
|
378
|
+
page.execute_script("$('form').bind('ajax:remotipartComplete', function(data) { window.commitButtonDisabled = $('input[name=\"commit\"]').is(':disabled'); window.commitButtonValue = $('input[name=\"commit\"]').val(); });")
|
379
|
+
|
380
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
381
|
+
fill_in 'comment_subject', with: 'Hi'
|
382
|
+
fill_in 'comment_body', with: 'there'
|
383
|
+
attach_file 'comment_attachment', file_path
|
384
|
+
click_button 'Create Comment'
|
385
|
+
|
386
|
+
expect(page.evaluate_script("window.commitButtonDisabled")).to be true
|
387
|
+
expect(page.evaluate_script("window.commitButtonValue")).to eq "Submitting..."
|
388
|
+
|
389
|
+
expect(button[:disabled]).to be false
|
390
|
+
expect(button.value).to eq "Create Comment"
|
391
|
+
end
|
392
|
+
|
393
|
+
it "submits the clicked button with the form like non-file remote form", js: true do
|
394
|
+
visit root_path
|
395
|
+
click_link 'New Comment with Attachment'
|
396
|
+
|
397
|
+
form = find('form')
|
398
|
+
page.execute_script("$('form').bind('ajax:remotipartSubmit', function(e, xhr, settings) { $('#comments').after('<div class=\"params\">' + $.param(settings.data) + '</div>'); });")
|
399
|
+
|
400
|
+
file_path = File.join(fixture_path, 'qr.jpg')
|
401
|
+
fill_in 'comment_subject', with: 'Hi'
|
402
|
+
fill_in 'comment_body', with: 'there'
|
403
|
+
attach_file 'comment_attachment', file_path
|
404
|
+
click_button 'Create Comment'
|
405
|
+
|
406
|
+
expect(page).to have_content('commit=')
|
407
|
+
end
|
408
|
+
|
409
|
+
it "doesn't allow XSS via script injection for text responses", js: true do
|
410
|
+
visit "/say?message=%3C/textarea%3E%3Csvg/onload=alert(domain)%3E&remotipart_submitted=x"
|
411
|
+
expect(page).to have_selector("textarea")
|
412
|
+
expect(find("textarea").value).to eq('</textarea><svg/onload=alert(domain)>')
|
413
|
+
end
|
414
|
+
end
|