effective_test_bot 0.4.5 → 0.4.6

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: 6ab5a8dbd613806a632a7d26883287d92b076ad0
4
- data.tar.gz: 282a10e85908184563c4b2b344ee2fc007dbf41a
3
+ metadata.gz: 0b7f79228e53f919d49e05e1c4664c154e8852f1
4
+ data.tar.gz: 23d86e7bffe2f127072aa2a27254e2420305526d
5
5
  SHA512:
6
- metadata.gz: 13b966c0c1b0b1222f1d44df755a029a4217781b4eacfa57334882bc9d3ab51b021b8e2b572a9087be3612549fdcda9c3c3c6801a39fd869ef4e97e68d6ab2a3
7
- data.tar.gz: 92e89261d74ec87d44177c121c80952a993595b486ba27cf0f9784f8a1647c2cd531e6f61a4801d61a3ef2a4be0a9c93b87f85eb183be8c526439f03dfb0f0be
6
+ metadata.gz: 001cada50f2fe9ad01c38607d7a42ac40176cb69dc09897e5874c50819c9e28ef51bdda5759455db13e722219dec2a13db1f6ee4d8dd75cdf5ef36c98ac49496
7
+ data.tar.gz: e0639c6e7c1a233ac3e98dab49290814cffe7d8668173d683bc2a64c04ecb63264377510ad92bd3c630de6c72b75958ad123286b4ef7fecf8127bb972d6013c2
@@ -1,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '0.4.5'.freeze
2
+ VERSION = '0.4.6'.freeze
3
3
  end
@@ -33,6 +33,7 @@ module EffectiveTestBotFormFiller
33
33
  tab.click()
34
34
  synchronize!
35
35
  save_test_bot_screenshot
36
+ @shared_max_fields = nil # Reset value_for_input_numeric_field() history
36
37
 
37
38
  within('div' + tab['href']) { fill_form_fields(fills) }
38
39
  end
@@ -116,6 +117,8 @@ module EffectiveTestBotFormFiller
116
117
  else
117
118
  Faker::Date.backward(365).strftime('%Y-%m-%d %H:%m')
118
119
  end
120
+ elsif classes.include?('numeric')
121
+ value_for_input_numeric_field(field, "input.numeric[name$='[#{attribute}]']")
119
122
  elsif classes.include?('email') || attribute.include?('email')
120
123
  Faker::Internet.email
121
124
  elsif classes.include?('price') # effective_form_inputs price
@@ -156,10 +159,7 @@ module EffectiveTestBotFormFiller
156
159
 
157
160
  field.all('option:enabled').select { |option| option.value.present? }.sample.try(:text) || '' # Don't select an empty option
158
161
  when 'input_number'
159
- min = (Float(field['min']) rescue 1)
160
- max = (Float(field['max']) rescue 1000)
161
- number = Random.new.rand(min..max)
162
- number.kind_of?(Float) ? number.round(2) : number
162
+ value_for_input_numeric_field(field, "input[type='number'][name$='[#{attribute}]']")
163
163
  when 'input_email'
164
164
  Faker::Internet.email
165
165
  when 'input_password'
@@ -181,6 +181,35 @@ module EffectiveTestBotFormFiller
181
181
  end
182
182
  end
183
183
 
184
+ def value_for_input_numeric_field(field, selector)
185
+ min = (Float(field['min']) rescue 0)
186
+ max = (Float(field['max']) rescue 1000)
187
+ number = Random.new.rand(min..max)
188
+ number = (number.kind_of?(Float) ? number.round(2) : number)
189
+
190
+ return number if field['max'].blank?
191
+
192
+ shared_max_fields = all(selector)
193
+ return number if shared_max_fields.length <= 1
194
+
195
+ # So there's definitely 2+ fields that share the same max, named the same
196
+ # We want the total value of all these fields to add upto the max single max value
197
+ @shared_max_fields ||= {}
198
+ @shared_max_fields[selector] ||= max
199
+
200
+ available = @shared_max_fields[selector]
201
+
202
+ amount = if max.kind_of?(Float)
203
+ (((max * 1000.0) / shared_max_fields.length.to_f).ceil() / 1000.0).round(2)
204
+ else
205
+ (max / shared_max_fields.length.to_f).ceil
206
+ end
207
+ amount = [[amount, min].max, available].min
208
+
209
+ @shared_max_fields[selector] = (available - amount)
210
+ amount
211
+ end
212
+
184
213
  # The field here is going to be the %input{:type => file}. Files can be one or more pathnames
185
214
  # http://stackoverflow.com/questions/5188240/using-selenium-to-imitate-dragging-a-file-onto-an-upload-element/11203629#11203629
186
215
  def upload_effective_asset(field, files)
@@ -7,7 +7,7 @@ module EffectiveTestBotScreenshotsHelper
7
7
  def save_test_bot_screenshot
8
8
  return unless EffectiveTestBot.screenshots? && defined?(current_test)
9
9
 
10
- full_path = current_test_temp_path + '/' + "#{current_test_screenshot_id}.png"
10
+ full_path = current_test_temp_path + "/#{current_test_screenshot_id}.png"
11
11
  page.save_screenshot(full_path)
12
12
  end
13
13
 
@@ -101,11 +101,11 @@ module EffectiveTestBotScreenshotsHelper
101
101
  # current_test_failure_path: destination for .gifs of failing tests
102
102
 
103
103
  def current_test_temp_path
104
- @_current_test_temp_path ||= File.join(Rails.root, 'tmp', 'test_bot', current_test || 'none')
104
+ @_current_test_temp_path ||= "#{Rails.root}/tmp/test_bot/#{current_test || 'none'}"
105
105
  end
106
106
 
107
107
  def current_test_failure_path
108
- File.join(Rails.root, 'tmp', 'test_bot')
108
+ "#{Rails.root}/tmp/test_bot"
109
109
  end
110
110
 
111
111
  def current_test_failure_filename
@@ -115,11 +115,11 @@ module EffectiveTestBotScreenshotsHelper
115
115
 
116
116
  # Where the tour animated gif ends up
117
117
  def current_test_tour_path
118
- File.join(Rails.root, 'test', 'tours')
118
+ "#{Rails.root}/test/tours"
119
119
  end
120
120
 
121
121
  def current_test_tour_filename
122
- current_test + '.gif'
122
+ "#{current_test}.gif"
123
123
  end
124
124
 
125
125
  private
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.4.5
4
+ version: 0.4.6
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-10-12 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails