Sha256: cd3073a692e2dd82b973922d503ef598d172d0a92fd9fc1b0070806947e747fe
Contents?: true
Size: 1.93 KB
Versions: 14
Compression:
Stored size: 1.93 KB
Contents
# frozen_string_literal: true module Eac module TestUtils # Add more helper methods to be used by all tests here... def valid_invalid_column_values_test(record, column, valid_values, invalid_values) valid_values.each do |v| record.send("#{column}=", v) assert record.valid?, "#{record.errors.messages}, #{column} = #{v.inspect} should be valid" end invalid_values.each do |v| record.send("#{column}=", v) assert_not record.valid?, "#{column} = #{v.inspect} should be invalid" end end # Verifica falhas em campos específicos de um record def assert_record_errors(record, fields_without_error, fields_with_error) fields_without_error.each do |c| assert record.errors[c].empty?, "Column: #{c} should not have errors (#{record.errors[c]})" end fields_with_error. each do |c| assert_not record.errors[c].empty?, "Column: #{c} should have errors" end end # Verifica, campo por campo, se invalida o registro. def assert_column_changes(ppp, expected_valid_result, changes) changes.each do |k, v| ppp.send("#{k}=", v) assert_equal expected_valid_result, ppp.valid?, "\"#{k}\" change should be " + (expected_valid_result ? 'valid' : 'invalid') assert_not ppp.errors[k].empty? unless expected_valid_result ppp.restore_attributes end end # Ex.: attrs = {a: 1, b: 2} resulta em # [{a: nil, b: nil}, {a: 1, b: nil}, {a: nil, b: 2}, {a: 1, b: 2}]. def all_combinations(attrs) combs = [{}] attrs.each do |attr_name, value| new_comb = [] assert_not value.nil?, "#{attr_name}=#{value}" [nil, value].each do |vv| combs.each do |c| cc = c.dup cc[attr_name] = vv new_comb << cc end end combs = new_comb end combs end end end
Version data entries
14 entries across 14 versions & 1 rubygems