File: test_inclusion_validator.rb

package info (click to toggle)
ruby-client-side-validations 3.2.6%2Bgh-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 672 kB
  • ctags: 510
  • sloc: ruby: 2,959; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 1,532 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'active_model/cases/test_base'

class ActiveModel::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)
  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)
  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)
  end

  def test_inclusion_client_side_hash_ignore_proc
    @person.stubs(:range).returns([1,2])
    expected_hash = nil
    assert_equal expected_hash, InclusionValidator.new(:attributes => [:name], :in => Proc.new { |o| o.range }).client_side_hash(@person, :age)
  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.new { |o| o.range }).client_side_hash(@person, :age, true)
  end
end