File: test_exclusion_validator.rb

package info (click to toggle)
ruby-client-side-validations 3.2.6%2Bgh-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 676 kB
  • sloc: javascript: 3,019; ruby: 2,959; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,480 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
32
require 'active_model/cases/test_base'

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

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