Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ jobs:
channel: ['stable']

include:
- ruby-version: '3.2'
gemfile: rails_edge
channel: 'experimental'
- ruby-version: '3.3'
gemfile: rails_edge
channel: 'experimental'
Expand All @@ -32,12 +29,6 @@ jobs:
- ruby-version: '4.0'
gemfile: rails_edge
channel: 'experimental'
- ruby-version: 'head'
gemfile: rails_7.1
channel: 'experimental'
- ruby-version: 'head'
gemfile: rails_7.2
channel: 'experimental'
- ruby-version: 'head'
gemfile: rails_8.0
channel: 'experimental'
Expand Down
4 changes: 2 additions & 2 deletions test/active_model/cases/test_absence_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class AbsenceValidatorTest < ClientSideValidations::ActiveModelTestBase
def test_absence_client_side_hash
expected_hash = { message: 'must be blank' }

assert_equal expected_hash, AbsenceValidator.new(attributes: [:name]).client_side_hash(@person, :age)
assert_equal expected_hash, AbsenceValidator.new(attributes: [:first_name]).client_side_hash(@person, :first_name)
end

def test_absence_client_side_hash_with_custom_message
expected_hash = { message: 'is required to be blank' }

assert_equal expected_hash, AbsenceValidator.new(attributes: [:name], message: 'is required to be blank').client_side_hash(@person, :age)
assert_equal expected_hash, AbsenceValidator.new(attributes: [:first_name], message: 'is required to be blank').client_side_hash(@person, :first_name)
end
end
end
4 changes: 2 additions & 2 deletions test/active_model/cases/test_acceptance_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class AcceptanceValidatorTest < ClientSideValidations::ActiveModelTestBase
def test_acceptance_client_side_hash
expected_hash = { message: 'must be accepted', accept: ['1', true] }

assert_equal expected_hash, AcceptanceValidator.new(attributes: [:name], class: Person).client_side_hash(@person, :age)
assert_equal expected_hash, AcceptanceValidator.new(attributes: [:first_name], class: Person).client_side_hash(@person, :first_name)
end

def test_acceptance_client_side_hash_with_custom_message
expected_hash = { message: 'you must accept', accept: ['1', true] }

assert_equal expected_hash, AcceptanceValidator.new(attributes: [:name], class: Person, message: 'you must accept').client_side_hash(@person, :age)
assert_equal expected_hash, AcceptanceValidator.new(attributes: [:first_name], class: Person, message: 'you must accept').client_side_hash(@person, :first_name)
end
end
end
10 changes: 5 additions & 5 deletions test/active_model/cases/test_confirmation_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
module ActiveModel
class ConfirmationValidatorTest < ClientSideValidations::ActiveModelTestBase
def test_confirmation_client_side_hash
expected_hash = { message: I18n.t('errors.messages.confirmation', attribute: 'Age'), case_sensitive: true }
expected_hash = { message: I18n.t('errors.messages.confirmation', attribute: 'First name'), case_sensitive: true }

assert_equal expected_hash, ConfirmationValidator.new(attributes: [:name], class: Person).client_side_hash(@person, :age)
assert_equal expected_hash, ConfirmationValidator.new(attributes: [:first_name], class: Person).client_side_hash(@person, :first_name)
end

def test_confirmation_client_side_without_case_sensitive
expected_hash = { message: I18n.t('errors.messages.confirmation', attribute: 'Age'), case_sensitive: false }
expected_hash = { message: I18n.t('errors.messages.confirmation', attribute: 'First name'), case_sensitive: false }

assert_equal expected_hash, ConfirmationValidator.new(attributes: [:name], class: Person, case_sensitive: false).client_side_hash(@person, :age)
assert_equal expected_hash, ConfirmationValidator.new(attributes: [:first_name], class: Person, case_sensitive: false).client_side_hash(@person, :first_name)
end

def test_confirmation_client_side_hash_with_custom_message
expected_hash = { message: 'you must confirm', case_sensitive: true }

assert_equal expected_hash, ConfirmationValidator.new(attributes: [:name], class: Person, message: 'you must confirm').client_side_hash(@person, :age)
assert_equal expected_hash, ConfirmationValidator.new(attributes: [:first_name], class: Person, message: 'you must confirm').client_side_hash(@person, :first_name)
end
end
end
10 changes: 5 additions & 5 deletions test/active_model/cases/test_exclusion_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ class ExclusionValidatorTest < ClientSideValidations::ActiveModelTestBase
def test_exclusion_client_side_hash
expected_hash = { message: 'is reserved', in: [1, 2] }

assert_equal expected_hash, ExclusionValidator.new(attributes: [:name], in: [1, 2]).client_side_hash(@person, :age)
assert_equal expected_hash, ExclusionValidator.new(attributes: [:first_name], in: [1, 2]).client_side_hash(@person, :first_name)
end

def test_exclusion_client_side_hash_with_custom_message
expected_hash = { message: 'is exclusive', in: [1, 2] }

assert_equal expected_hash, ExclusionValidator.new(attributes: [:name], in: [1, 2], message: 'is exclusive').client_side_hash(@person, :age)
assert_equal expected_hash, ExclusionValidator.new(attributes: [:first_name], in: [1, 2], message: 'is exclusive').client_side_hash(@person, :first_name)
end

def test_exclusion_client_side_hash_with_ranges
expected_hash = { message: 'is reserved', range: 1..2 }

assert_equal expected_hash, ExclusionValidator.new(attributes: [:name], in: 1..2).client_side_hash(@person, :age)
assert_equal expected_hash, ExclusionValidator.new(attributes: [:first_name], in: 1..2).client_side_hash(@person, :first_name)
end

def test_exclusion_client_side_hash_ignore_proc
@person.stubs(:range).returns([1, 2])

assert_nil ExclusionValidator.new(attributes: [:name], in: proc { |o| o.range }).client_side_hash(@person, :age)
assert_nil ExclusionValidator.new(attributes: [:first_name], in: proc { |o| o.range }).client_side_hash(@person, :first_name)
end

def test_exclusion_client_side_hash_observe_proc
@person.stubs(:range).returns([1, 2])
expected_hash = { message: 'is reserved', in: [1, 2] }

assert_equal expected_hash, ExclusionValidator.new(attributes: [:name], in: proc { |o| o.range }).client_side_hash(@person, :age, true)
assert_equal expected_hash, ExclusionValidator.new(attributes: [:first_name], in: proc { |o| o.range }).client_side_hash(@person, :first_name, true)
end
end
end
14 changes: 7 additions & 7 deletions test/active_model/cases/test_format_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,45 @@ class FormatValidatorTest < ClientSideValidations::ActiveModelTestBase
def test_format_client_side_hash
expected_hash = { message: 'is invalid', with: /.+/ }

assert_equal expected_hash, FormatValidator.new(attributes: [:name], with: /.+/).client_side_hash(@person, :age)
assert_equal expected_hash, FormatValidator.new(attributes: [:first_name], with: /.+/).client_side_hash(@person, :first_name)
end

def test_format_client_side_hash_without
expected_hash = { message: 'is invalid', without: /.+/ }

assert_equal expected_hash, FormatValidator.new(attributes: [:name], without: /.+/).client_side_hash(@person, :age)
assert_equal expected_hash, FormatValidator.new(attributes: [:first_name], without: /.+/).client_side_hash(@person, :first_name)
end

def test_format_client_side_hash_with_custom_message
expected_hash = { message: 'is wrong format', with: /.+/ }

assert_equal expected_hash, FormatValidator.new(attributes: [:name], with: /.+/, message: 'is wrong format').client_side_hash(@person, :age)
assert_equal expected_hash, FormatValidator.new(attributes: [:first_name], with: /.+/, message: 'is wrong format').client_side_hash(@person, :first_name)
end

def test_format_client_side_hash_ignore_proc
@person.stubs(:matcher).returns(/.+/)

assert_nil FormatValidator.new(attributes: [:name], with: proc { |o| o.matcher }).client_side_hash(@person, :age)
assert_nil FormatValidator.new(attributes: [:first_name], with: proc { |o| o.matcher }).client_side_hash(@person, :first_name)
end

def test_format_client_side_hash_without_ignore_proc
@person.stubs(:matcher).returns(/.+/)

assert_nil FormatValidator.new(attributes: [:name], without: proc { |o| o.matcher }).client_side_hash(@person, :age)
assert_nil FormatValidator.new(attributes: [:first_name], without: proc { |o| o.matcher }).client_side_hash(@person, :first_name)
end

def test_format_client_side_hash_observe_proc
@person.stubs(:matcher).returns(/.+/)
expected_hash = { message: 'is invalid', with: /.+/ }

assert_equal expected_hash, FormatValidator.new(attributes: [:name], with: proc { |o| o.matcher }).client_side_hash(@person, :age, true)
assert_equal expected_hash, FormatValidator.new(attributes: [:first_name], with: proc { |o| o.matcher }).client_side_hash(@person, :first_name, true)
end

def test_format_client_side_hash_without_observe_proc
@person.stubs(:matcher).returns(/.+/)
expected_hash = { message: 'is invalid', without: /.+/ }

assert_equal expected_hash, FormatValidator.new(attributes: [:name], without: proc { |o| o.matcher }).client_side_hash(@person, :age, true)
assert_equal expected_hash, FormatValidator.new(attributes: [:first_name], without: proc { |o| o.matcher }).client_side_hash(@person, :first_name, true)
end
end
end
10 changes: 5 additions & 5 deletions test/active_model/cases/test_inclusion_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ class InclusionValidatorTest < ClientSideValidations::ActiveModelTestBase
def test_inclusion_client_side_hash
expected_hash = { message: 'is not included in the list', in: [1, 2] }

assert_equal expected_hash, InclusionValidator.new(attributes: [:name], in: [1, 2]).client_side_hash(@person, :age)
assert_equal expected_hash, InclusionValidator.new(attributes: [:first_name], in: [1, 2]).client_side_hash(@person, :first_name)
end

def test_inclusion_client_side_hash_with_custom_message
expected_hash = { message: 'is not a choice', in: [1, 2] }

assert_equal expected_hash, InclusionValidator.new(attributes: [:name], in: [1, 2], message: 'is not a choice').client_side_hash(@person, :age)
assert_equal expected_hash, InclusionValidator.new(attributes: [:first_name], in: [1, 2], message: 'is not a choice').client_side_hash(@person, :first_name)
end

def test_inclusion_client_side_hash_with_range
expected_hash = { message: 'is not included in the list', range: 1..2 }

assert_equal expected_hash, InclusionValidator.new(attributes: [:name], in: 1..2).client_side_hash(@person, :age)
assert_equal expected_hash, InclusionValidator.new(attributes: [:first_name], in: 1..2).client_side_hash(@person, :first_name)
end

def test_inclusion_client_side_hash_ignore_proc
@person.stubs(:range).returns([1, 2])

assert_nil InclusionValidator.new(attributes: [:name], in: proc { |o| o.range }).client_side_hash(@person, :age)
assert_nil InclusionValidator.new(attributes: [:first_name], in: proc { |o| o.range }).client_side_hash(@person, :first_name)
end

def test_inclusion_client_side_hash_observe_proc
@person.stubs(:range).returns([1, 2])
expected_hash = { message: 'is not included in the list', in: [1, 2] }

assert_equal expected_hash, InclusionValidator.new(attributes: [:name], in: proc { |o| o.range }).client_side_hash(@person, :age, true)
assert_equal expected_hash, InclusionValidator.new(attributes: [:first_name], in: proc { |o| o.range }).client_side_hash(@person, :first_name, true)
end
end
end
10 changes: 5 additions & 5 deletions test/active_model/cases/test_length_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_length_client_side_hash
is: 10
}

assert_equal expected_hash, LengthValidator.new(attributes: [:age], is: 10).client_side_hash(@person, :first_name)
assert_equal expected_hash, LengthValidator.new(attributes: [:age], is: 10).client_side_hash(@person, :age)
end

def test_length_client_side_hash_with_allow_nil
Expand All @@ -29,7 +29,7 @@ def test_length_client_side_hash_with_custom_message
is: 10
}

assert_equal expected_hash, LengthValidator.new(attributes: [:age], is: 10, wrong_length: 'is the wrong length (should be %{count} words)').client_side_hash(@person, :first_name)
assert_equal expected_hash, LengthValidator.new(attributes: [:age], is: 10, wrong_length: 'is the wrong length (should be %{count} words)').client_side_hash(@person, :age)
end

def test_length_client_side_hash_with_custom_general_message
Expand All @@ -42,7 +42,7 @@ def test_length_client_side_hash_with_custom_general_message
maximum: 10
}

assert_equal expected_hash, LengthValidator.new(attributes: [:age], minimum: 4, maximum: 10, message: 'is not the correct length', too_long: 'is way too long').client_side_hash(@person, :first_name)
assert_equal expected_hash, LengthValidator.new(attributes: [:age], minimum: 4, maximum: 10, message: 'is not the correct length', too_long: 'is way too long').client_side_hash(@person, :age)
end

def test_length_client_side_hash_with_minimum_and_maximum
Expand All @@ -55,7 +55,7 @@ def test_length_client_side_hash_with_minimum_and_maximum
maximum: 10
}

assert_equal expected_hash, LengthValidator.new(attributes: [:age], minimum: 5, maximum: 10).client_side_hash(@person, :first_name)
assert_equal expected_hash, LengthValidator.new(attributes: [:age], minimum: 5, maximum: 10).client_side_hash(@person, :age)
end

def test_length_client_side_hash_with_range
Expand All @@ -68,7 +68,7 @@ def test_length_client_side_hash_with_range
maximum: 10
}

assert_equal expected_hash, LengthValidator.new(attributes: [:age], within: 5..10).client_side_hash(@person, :first_name)
assert_equal expected_hash, LengthValidator.new(attributes: [:age], within: 5..10).client_side_hash(@person, :age)
end
end
end
4 changes: 2 additions & 2 deletions test/active_model/cases/test_presence_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class PresenceValidatorTest < ClientSideValidations::ActiveModelTestBase
def test_presence_client_side_hash
expected_hash = { message: I18n.t('errors.messages.blank') }

assert_equal expected_hash, PresenceValidator.new(attributes: [:name]).client_side_hash(@person, :age)
assert_equal expected_hash, PresenceValidator.new(attributes: [:first_name]).client_side_hash(@person, :first_name)
end

def test_presence_client_side_hash_with_custom_message
expected_hash = { message: 'is required' }

assert_equal expected_hash, PresenceValidator.new(attributes: [:name], message: 'is required').client_side_hash(@person, :age)
assert_equal expected_hash, PresenceValidator.new(attributes: [:first_name], message: 'is required').client_side_hash(@person, :first_name)
end
end
end