forked from fixin.me/fixin.me
Avoid duplicated symbols, check created record attributes
This commit is contained in:
parent
30ee4a861e
commit
e15b983b56
@ -26,6 +26,7 @@
|
|||||||
default: &default
|
default: &default
|
||||||
adapter: mysql2
|
adapter: mysql2
|
||||||
encoding: utf8mb4
|
encoding: utf8mb4
|
||||||
|
collation: utf8mb4_0900_as_ci
|
||||||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
||||||
username: fixinme
|
username: fixinme
|
||||||
password:
|
password:
|
||||||
|
@ -29,23 +29,27 @@ class UnitsTest < ApplicationSystemTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "new" do
|
test "new and create" do
|
||||||
type, label = LINK_LABELS.assoc([:add_unit, :add_subunit].sample)
|
type, label = LINK_LABELS.assoc([:add_unit, :add_subunit].sample)
|
||||||
add_link = all(:link, exact_text: label).sample
|
add_link = all(:link, exact_text: label).sample
|
||||||
add_link.click
|
add_link.click
|
||||||
assert_equal 'disabled', add_link[:disabled]
|
assert_equal 'disabled', add_link[:disabled]
|
||||||
|
|
||||||
|
params = nil
|
||||||
within 'tbody > tr:has(input[type=text], textarea)' do
|
within 'tbody > tr:has(input[type=text], textarea)' do
|
||||||
assert_selector ':focus'
|
assert_selector ':focus'
|
||||||
|
|
||||||
maxlength = all(:fillable_field).to_h { |f| [f[:name], f[:maxlength].to_i || 2**16] }
|
maxlength = all(:fillable_field).to_h { |f| [f[:name], f[:maxlength].to_i || 2**16] }
|
||||||
|
params = {
|
||||||
fill_in 'unit[symbol]',
|
symbol: random_string(rand([1..3, 4..maxlength['unit[symbol]']].sample),
|
||||||
with: random_string(rand([1..3, 4..maxlength['unit[symbol]']].sample))
|
except: units.map(&:symbol)),
|
||||||
fill_in 'unit[description]', with: random_string(rand(0..maxlength['unit[description]']))
|
description: random_string(rand(0..maxlength['unit[description]']))
|
||||||
|
}.with_indifferent_access
|
||||||
within :field, 'unit[multiplier]' do |field|
|
within :field, 'unit[multiplier]' do |field|
|
||||||
fill_in with: random_number(field[:max], field[:step])
|
params[:multiplier] = random_number(field[:max], field[:step])
|
||||||
end if add_link[:text] != t('units.index.add_unit')
|
end if type == :add_subunit
|
||||||
|
|
||||||
|
params.each_pair { |name, value| fill_in "unit[#{name}]", with: value }
|
||||||
|
|
||||||
assert_difference ->{ Unit.count }, 1 do
|
assert_difference ->{ Unit.count }, 1 do
|
||||||
click_on t('helpers.submit.create')
|
click_on t('helpers.submit.create')
|
||||||
@ -58,7 +62,8 @@ class UnitsTest < ApplicationSystemTestCase
|
|||||||
end
|
end
|
||||||
assert_no_selector :element, :a, 'disabled': 'disabled',
|
assert_no_selector :element, :a, 'disabled': 'disabled',
|
||||||
exact_text: Regexp.union(LINK_LABELS.fetch_values(:add_unit, :add_subunit))
|
exact_text: Regexp.union(LINK_LABELS.fetch_values(:add_unit, :add_subunit))
|
||||||
assert_selector '.flash.notice', text: t('units.create.success', unit: Unit.all.last.symbol)
|
assert_selector '.flash.notice', text: t('units.create.success', unit: Unit.last.symbol)
|
||||||
|
assert_equal params, Unit.last.attributes.slice(*params.keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: check proper form/button redisplay and flash messages on add/edit
|
# TODO: check proper form/button redisplay and flash messages on add/edit
|
||||||
|
@ -26,11 +26,11 @@ class ActiveSupport::TestCase
|
|||||||
*"\u0710".."\u07FF"]
|
*"\u0710".."\u07FF"]
|
||||||
}
|
}
|
||||||
UNICODE_CHARS.default = UNICODE_CHARS[1] + UNICODE_CHARS[2]
|
UNICODE_CHARS.default = UNICODE_CHARS[1] + UNICODE_CHARS[2]
|
||||||
def random_string(bytes = 10)
|
def random_string(bytes = 10, except: [])
|
||||||
result = ''
|
begin
|
||||||
while bytes > 0
|
result = ''
|
||||||
result += UNICODE_CHARS[bytes].sample.tap { |c| bytes -= c.bytesize }
|
result += UNICODE_CHARS[bytes - result.bytesize].sample while bytes > result.bytesize
|
||||||
end
|
end while except.include?(result)
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user