effective_test_bot 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4264790049653f4d61c579da4c76c30414783b2b
|
4
|
+
data.tar.gz: f760d945c4f4bbb14fe9d4f795b59aedc34f88f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09f18672e89360df638fe5dd3ffe22e6f522445a9fa63d9d3b51f714d0b03ef0b95ef7d8e9ce5111549604bfcc7ab010f1b234241a682d43f05f5aace2193505
|
7
|
+
data.tar.gz: c99c37e6a85fd1052759de639f2d4b89794b3ced10f28b593f2b2fd8c13b4b529f8854f3a782fa5d88881da876ed9a76afd15db48c81f85d5ddcc60bee75bbdd
|
@@ -0,0 +1 @@
|
|
1
|
+
This is a file that the EffectiveAssets file uploader will accept regardless of any :file_types passed
|
@@ -23,4 +23,10 @@ module EffectiveTestBotAssertions
|
|
23
23
|
def assert_page_status(status = 200)
|
24
24
|
assert_equal status, page.status_code, "page failed to load with #{status} HTTP status code"
|
25
25
|
end
|
26
|
+
|
27
|
+
def assert_no_js_errors
|
28
|
+
errors = page.driver.error_messages
|
29
|
+
assert_equal 0, errors.size, errors.ai
|
30
|
+
end
|
31
|
+
|
26
32
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
1
3
|
module EffectiveTestBotFormHelper
|
2
4
|
DIGITS = ('1'..'9').to_a
|
3
5
|
LETTERS = ('A'..'Z').to_a
|
@@ -20,7 +22,8 @@ module EffectiveTestBotFormHelper
|
|
20
22
|
when 'select'
|
21
23
|
field.select(fill_value(field, fills), match: :first)
|
22
24
|
when 'input_file'
|
23
|
-
|
25
|
+
file_path = fill_value(field, fills)
|
26
|
+
field['class'].include?('asset-box-uploader-fileinput') ? upload_effective_asset(field, file_path) : field.set(file_path)
|
24
27
|
when 'input_submit', 'input_search'
|
25
28
|
# Do nothing
|
26
29
|
else
|
@@ -30,7 +33,7 @@ module EffectiveTestBotFormHelper
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def clear_form
|
33
|
-
all('input,select,textarea').each { |field| field.set('') }
|
36
|
+
all('input,select,textarea').each { |field| (field.set('') rescue false) }
|
34
37
|
end
|
35
38
|
|
36
39
|
# Operates on just string keys
|
@@ -93,11 +96,14 @@ module EffectiveTestBotFormHelper
|
|
93
96
|
[true, false].sample
|
94
97
|
when 'input_radio'
|
95
98
|
[true, false].sample
|
99
|
+
when 'input_file'
|
100
|
+
"#{File.dirname(__FILE__)}/effective_assets_upload_file._test"
|
96
101
|
else
|
97
102
|
raise "fill_value unsupported field type: #{field['type']}"
|
98
103
|
end
|
99
104
|
end
|
100
105
|
|
106
|
+
# page.execute_script "$('form#new_#{resource_name}').submit();"
|
101
107
|
def submit_form(label = nil)
|
102
108
|
if label.present?
|
103
109
|
click_on(label)
|
@@ -106,4 +112,49 @@ module EffectiveTestBotFormHelper
|
|
106
112
|
end
|
107
113
|
synchronize!
|
108
114
|
end
|
115
|
+
|
116
|
+
# Submit form after disabling any HTML5 validations
|
117
|
+
def submit_novalidate_form(label = nil)
|
118
|
+
page.execute_script "for(var f=document.forms,i=f.length;i--;)f[i].setAttribute('novalidate','');"
|
119
|
+
submit_form(label)
|
120
|
+
end
|
121
|
+
|
122
|
+
# The field here is going to be the %input{:type => file}. Files can be one or more pathnames
|
123
|
+
# http://stackoverflow.com/questions/5188240/using-selenium-to-imitate-dragging-a-file-onto-an-upload-element/11203629#11203629
|
124
|
+
def upload_effective_asset(field, files)
|
125
|
+
files = Array(files)
|
126
|
+
uid = field['id']
|
127
|
+
|
128
|
+
page.driver.allow_url(Effective::Asset.s3_base_path)
|
129
|
+
|
130
|
+
js = "fileList = Array();"
|
131
|
+
|
132
|
+
files.each_with_index do |file, i|
|
133
|
+
# Generate a fake input selector
|
134
|
+
page.execute_script("if($('#effectiveAssetsPlaceholder#{i}').length == 0) {effectiveAssetsPlaceholder#{i} = window.$('<input/>').attr({id: 'effectiveAssetsPlaceholder#{i}', type: 'file'}).appendTo('body'); }")
|
135
|
+
|
136
|
+
# Attach file to the fake input selector through Capybara
|
137
|
+
page.document.attach_file("effectiveAssetsPlaceholder#{i}", files[i])
|
138
|
+
|
139
|
+
# Build up the fake js event
|
140
|
+
js = "#{js} fileList.push(effectiveAssetsPlaceholder#{i}.get(0).files[0]);"
|
141
|
+
end
|
142
|
+
|
143
|
+
# Trigger the fake drop event
|
144
|
+
page.execute_script("#{js} e = $.Event('drop'); e.originalEvent = {dataTransfer : { files : fileList } }; $('#s3_#{uid}').trigger(e);")
|
145
|
+
|
146
|
+
# Wait till the Uploader bar goes away
|
147
|
+
begin
|
148
|
+
Timeout.timeout(files.length * 5) do
|
149
|
+
within("#asset-box-input-#{uid}") do
|
150
|
+
within('.uploads') do
|
151
|
+
sleep(0.25) while (first('.upload').present? rescue false)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
rescue Timeout::Error
|
156
|
+
puts "file upload timed out after #{files.length * 5}s"
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
109
160
|
end
|
@@ -6,6 +6,7 @@ module CrudTest
|
|
6
6
|
|
7
7
|
assert_page_status
|
8
8
|
assert_page_title
|
9
|
+
assert_no_js_errors
|
9
10
|
|
10
11
|
# Make sure there's a form with a submit button
|
11
12
|
form_selector = "form#new_#{resource_name}"
|
@@ -21,33 +22,33 @@ module CrudTest
|
|
21
22
|
|
22
23
|
sign_in(user) and visit(new_resource_path)
|
23
24
|
|
24
|
-
before = { count: resource_class.count,
|
25
|
+
before = { count: resource_class.count, path: page.current_path }
|
25
26
|
|
26
27
|
within("form#new_#{resource_name}") do
|
27
28
|
fill_form(resource_attributes)
|
28
29
|
submit_form
|
29
30
|
end
|
30
31
|
|
31
|
-
after = { count: resource_class.count,
|
32
|
+
after = { count: resource_class.count, path: page.current_path }
|
32
33
|
|
33
34
|
refute_equal before[:count], after[:count], "unable to create #{resource_class} object"
|
34
|
-
refute_equal before[:
|
35
|
+
refute_equal before[:path], after[:path], "unable to create #{resource_class} object"
|
35
36
|
end
|
36
37
|
|
37
38
|
define_method 'test_bot: #create invalid' do
|
38
39
|
should_skip!(:create)
|
39
40
|
|
40
41
|
sign_in(user) and visit(new_resource_path)
|
41
|
-
before = { count: resource_class.count
|
42
|
+
before = { count: resource_class.count }
|
42
43
|
|
43
44
|
within("form#new_#{resource_name}") do
|
44
|
-
|
45
|
+
submit_novalidate_form
|
45
46
|
end
|
46
47
|
|
47
|
-
after = { count: resource_class.count
|
48
|
+
after = { count: resource_class.count }
|
48
49
|
|
49
50
|
assert_equal before[:count], after[:count], 'unexpectedly created object anyway'
|
50
|
-
assert_equal
|
51
|
+
assert_equal resources_path, page.current_path, 'did not return to #create url'
|
51
52
|
assert_page_title :any, 'page title missing after failed validation'
|
52
53
|
end
|
53
54
|
|
@@ -58,6 +59,7 @@ module CrudTest
|
|
58
59
|
|
59
60
|
assert_page_status
|
60
61
|
assert_page_title
|
62
|
+
assert_no_js_errors
|
61
63
|
|
62
64
|
# Make sure there's a form with a submit button
|
63
65
|
form_selector = "form#edit_#{resource_name}_#{resource.id}"
|
@@ -73,7 +75,7 @@ module CrudTest
|
|
73
75
|
|
74
76
|
visit(edit_resource_path(resource))
|
75
77
|
|
76
|
-
before = { count: resource_class.count,
|
78
|
+
before = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
|
77
79
|
|
78
80
|
within("form#edit_#{resource_name}_#{resource.id}") do
|
79
81
|
fill_form(resource_attributes)
|
@@ -81,7 +83,7 @@ module CrudTest
|
|
81
83
|
end
|
82
84
|
resource = resource_class.find(resource.id)
|
83
85
|
|
84
|
-
after = { count: resource_class.count,
|
86
|
+
after = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
|
85
87
|
|
86
88
|
assert_equal before[:count], after[:count], "updating resource unexpectedly changed #{resource_class}.count"
|
87
89
|
assert(after[:updated_at] > before[:updated_at], "failed to update resource") if resource.respond_to?(:updated_at)
|
@@ -92,19 +94,19 @@ module CrudTest
|
|
92
94
|
|
93
95
|
visit(edit_resource_path(resource))
|
94
96
|
|
95
|
-
before = { count: resource_class.count,
|
97
|
+
before = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
|
96
98
|
|
97
99
|
within("form#edit_#{resource_name}_#{resource.id}") do
|
98
100
|
clear_form
|
99
|
-
|
101
|
+
submit_novalidate_form
|
100
102
|
end
|
101
103
|
resource = resource_class.find(resource.id)
|
102
104
|
|
103
|
-
after = { count: resource_class.count,
|
105
|
+
after = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
|
104
106
|
|
105
107
|
assert_equal before[:count], after[:count], "updating resource unexpectedly changed #{resource_class}.count"
|
106
108
|
assert_equal(after[:updated_at], before[:updated_at], 'unexpectedly updated object anyway') if resource.respond_to?(:updated_at)
|
107
|
-
assert_equal
|
109
|
+
assert_equal resource_path(resource), page.current_path, 'did not return to #update url'
|
108
110
|
assert_page_title :any, 'page title missing after failed validation'
|
109
111
|
end
|
110
112
|
|
@@ -115,6 +117,7 @@ module CrudTest
|
|
115
117
|
|
116
118
|
assert_page_status
|
117
119
|
assert_page_title
|
120
|
+
assert_no_js_errors
|
118
121
|
end
|
119
122
|
|
120
123
|
define_method 'test_bot: #show' do
|
@@ -124,6 +127,7 @@ module CrudTest
|
|
124
127
|
|
125
128
|
assert_page_status
|
126
129
|
assert_page_title
|
130
|
+
assert_no_js_errors
|
127
131
|
end
|
128
132
|
|
129
133
|
define_method 'test_bot: #destroy' do
|
@@ -138,7 +142,7 @@ module CrudTest
|
|
138
142
|
if resource.respond_to?(:archived)
|
139
143
|
assert after[:archived] == true, "expected #{resource_class}.archived == true"
|
140
144
|
else
|
141
|
-
|
145
|
+
refute_equal before[:count], after[:count], "unable to delete #{resource_class}"
|
142
146
|
end
|
143
147
|
end
|
144
148
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_test_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- lib/generators/templates/test_helper.rb
|
212
212
|
- lib/tasks/effective_test_bot_tasks.rake
|
213
213
|
- test/concerns/acts_as_test_botable.rb
|
214
|
+
- test/support/effective_assets_upload_file._test
|
214
215
|
- test/support/effective_test_bot_assertions.rb
|
215
216
|
- test/support/effective_test_bot_form_helper.rb
|
216
217
|
- test/support/effective_test_bot_login_helper.rb
|