Sha256: 188ffe4d756708dbeafdea4c82bba325b74c3f7a9bf2e222656d5e91d4ecc47b

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

require 'test_helper.rb'

describe "Respond To Validation" do
  def build_respond_to_record attrs = {}
    TestRecord.reset_callbacks(:validate)
    TestRecord.validates :responder, :respond_to => { :call => true, :if => :local_condition }, :if => :global_condition
    TestRecord.new attrs
  end

  it "respond_to?" do
    subject = build_respond_to_record
    subject.responder = lambda {}
    subject.global_condition = true
    subject.local_condition = true

    subject.valid?.must_equal true
    subject.errors.size.must_equal 0
  end

  describe "when does not respond_to?" do
    it "rejects the responder" do
      subject = build_respond_to_record :responder => 42, :global_condition => true, :local_condition => true
      subject.valid?.must_equal false
      subject.errors.size.must_equal 1
    end

    it "generates an error message of type invalid" do
      subject = build_respond_to_record :responder => 42, :global_condition => true, :local_condition => true
      subject.valid?.must_equal false
      subject.errors[:responder].include?(subject.errors.generate_message(:responder, :invalid)).must_equal true
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
activevalidators-2.1.0 test/validations/respond_to_test.rb
activevalidators-2.0.2 test/validations/respond_to_test.rb
activevalidators-2.0.1 test/validations/respond_to_test.rb
activevalidators-2.0.0 test/validations/respond_to_test.rb
activevalidators-1.9.0 test/validations/respond_to_test.rb
activevalidators-1.8.1 test/validations/respond_to_test.rb
activevalidators-1.8.0 test/validations/respond_to_test.rb
activevalidators-1.7.1 test/validations/respond_to_test.rb
activevalidators-1.7.0 test/validations/respond_to_test.rb
activevalidators-1.6.0 test/validations/respond_to_test.rb