Sha256: 22382fc469b79e13403a4db38431a8f38beccd4a1e82eee5364c327f192b3660

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

root = exports ? window

require 'indemma/lib/record/validatable'

describe 'model #() validates_remotely',  ->
  model   = root.model
  request = arthur  = person = null

  describe 'basic usage', ->

    beforeEach ->
      person = model.call
        resource  : 'person'
        name      : String
        validates_remotely: 'name'

      arthur = person name: "Arthur Dent"

    afterEach ->
      person?.validators.length = 0

    describe '#validate', ->

      beforeEach ->
        request = jQuery.Deferred()
        sinon.stub(jQuery, "ajax").returns(request)

      afterEach  -> jQuery.ajax.restore()

      it 'should send paramenters accordingly', ->
        arthur.validate()

        jQuery.ajax.called.should.be.true
        jQuery.ajax.calledWithMatch(
          url: '/persons/validate'
          data:
            person:
              name: 'Arthur Dent'
        ).should.be.true


      it 'should add errors to record when request responds with errors', ->
        arthur.validate()
        request.resolveWith arthur,
          [name: ['The name should be Marvin!', 'The name should be in lowercase!']]

        arthur.errors.length.should.be.eq 2
        arthur.errors.messages.name.should.exist

  describe 'with options usage', ->

    beforeEach ->
      person?.validators.length = 0

      person = model.call
        resource  : 'person'
        name      : String
        validates_remotely: 'name'

      arthur = person name: "Arthur Dent"

    describe '#validate', ->

      beforeEach ->
        request = jQuery.Deferred()
        sinon.stub(jQuery, "ajax").returns(request)

      afterEach  -> jQuery.ajax.restore()

      it 'should make ajax call', ->
        arthur.validate()
        jQuery.ajax.called.should.be.true

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ende-0.2.3 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.2.2 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.2.1 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.2.0 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee