Sha256: 94d461a0101ba94c070370ee8868ff023a1e7181578cf048b892c07777ffe5d4

Contents?: true

Size: 1.75 KB

Versions: 54

Compression:

Stored size: 1.75 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: '/people/validate'
          type: 'post'
          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

54 entries across 54 versions & 1 rubygems

Version Path
ende-0.4.25 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.24 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.23 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.5.1 components/indefinido/indemma/master/src/spec/record/validations/remote_spec.coffee
ende-0.4.22 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.21 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.5.0 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.20 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.19 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.18 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.17 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.16 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.3.13 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.3.12 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.3.11 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.15 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.14 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.13 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.12 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee
ende-0.4.11 vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee