4bbd93ded1
Adding the .ruby-verison file triggered previously un-run cops, specifically: This cop is designed to help upgrade to Ruby 3.0. It will add the comment `# frozen_string_literal: true` to the top of files to enable frozen string literals. Frozen string literals will be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+. More info on rubocop [Automatic-Corrections](https://github.com/bbatsov/rubocop/wiki/Automatic-Corrections)
51 lines
1.5 KiB
Ruby
51 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
require 'test_helper'
|
|
|
|
class InputOptionsPresenceValidatorTest < ActiveSupport::TestCase
|
|
test "should pass when inpute type not radio or checkbox" do
|
|
obj = InputOptionsValidatable.new
|
|
obj.input_type = "text"
|
|
|
|
assert obj.valid?
|
|
assert_equal 0, obj.errors.messages[:input_options].count
|
|
end
|
|
|
|
test "should fail when missing options for radio" do
|
|
obj = InputOptionsValidatable.new
|
|
obj.input_type = "radio"
|
|
obj.input_options = nil
|
|
obj.valid?
|
|
|
|
refute obj.errors.messages.empty?, 'needs an error message'
|
|
assert_match(/provide.*option/i, obj.errors.messages[:input_options].join)
|
|
end
|
|
|
|
test "should pass when provided options for radio" do
|
|
obj = InputOptionsValidatable.new
|
|
obj.input_type = "radio"
|
|
obj.input_options = ['one', 'two', nil]
|
|
|
|
assert obj.valid?
|
|
assert_equal 0, obj.errors.messages[:input_options].count
|
|
end
|
|
|
|
test "should fail when missing options for checkbox" do
|
|
obj = InputOptionsValidatable.new
|
|
obj.input_type = "checkbox"
|
|
obj.input_options = nil
|
|
obj.valid?
|
|
|
|
refute obj.errors.messages.empty?, 'needs an error message'
|
|
assert_match(/provide.*option/i, obj.errors.messages[:input_options].join)
|
|
end
|
|
|
|
test "should pass when provided options for checkbox" do
|
|
obj = InputOptionsValidatable.new
|
|
obj.input_type = "checkbox"
|
|
obj.input_options = ['one', 'two', nil]
|
|
|
|
assert obj.valid?
|
|
assert_equal 0, obj.errors.messages[:input_options].count
|
|
end
|
|
end
|