<commit_before>$ ->
  fixture = $('#qunit-fixture')

  window.formSubmitted = ->

  module "Remote"
    setup: ->
      window.formSubmitted = ->

    teardown: ->
      $(document).undelegate '.test'
      $('#qunit-fixture').html ""

  asyncTest "link is submitted via AJAX with GET method", ->
    link = $("<a data-remote href='/echo?callback=formSubmitted'>")
    fixture.append link

    window.formSubmitted = (data) ->
      equal 'GET', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is submitted via AJAX with POST method", ->
    link = $("<a data-remote data-method=post href='/echo?callback=formSubmitted'>")
    fixture.append link

    window.formSubmitted = (data) ->
      equal 'POST', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is submitted via AJAX with PUT method", ->
    link = $("<a data-remote data-method=put href='/echo?callback=formSubmitted'>")
    fixture.append link

    window.formSubmitted = (data) ->
      equal 'PUT', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is submitted via AJAX with DELETE method", ->
    link = $("<a data-remote data-method=delete href='/echo?callback=formSubmitted'>")
    fixture.append link

    window.formSubmitted = (data) ->
      equal 'DELETE', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is submitted via AJAX that accepts JSON", ->
    link = $("<a data-remote href='/echo' data-type=json>")
    fixture.append link

    $(document).delegate 'a', 'ajaxSuccess.test', (event, xhr, settings, data) ->
      equal 'GET', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is prevented from being submitted", ->
    link = $("<a data-remote href='/echo'>")
    fixture.append link

    $(document).delegate 'a', 'ajaxBeforeSend.test', ->
      ok true
      false

    $(document).delegate 'a', 'ajaxSuccess.test', ->
      ok false

    link.trigger 'click'

    setTimeout (-> start()), 50


  asyncTest "form is submitted via AJAX with GET method", ->
    form = $("<form data-remote action='/echo?callback=formSubmitted'><input name=foo value=bar></form>")
    fixture.append form

    window.formSubmitted = (data) ->
      equal 'GET', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      equal 'bar', data.params['foo']
      start()

    $(form).submit()

  asyncTest "form is submitted via AJAX with POST method", ->
    form = $("<form data-remote method=post action='/echo?callback=formSubmitted'><input name=foo value=bar></form>")
    fixture.append form

    window.formSubmitted = (data) ->
      equal 'POST', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      equal 'bar', data.params['foo']
      start()

    $(form).submit()

  asyncTest "form is submitted via AJAX with PUT method", ->
    form = $("<form data-remote method=put action='/echo?callback=formSubmitted'><input name=foo value=bar></form>")
    fixture.append form

    window.formSubmitted = (data) ->
      equal 'PUT', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      equal 'bar', data.params['foo']
      start()

    $(form).submit()

  asyncTest "form is submitted via AJAX with DELETE method", ->
    form = $("<form data-remote method=delete action='/echo?callback=formSubmitted'><input name=foo value=bar></form>")
    fixture.append form

    window.formSubmitted = (data) ->
      equal 'DELETE', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      equal 'bar', data.params['foo']
      start()

    $(form).submit()

  asyncTest "form is submitted via AJAX that accepts JSON", -><commit_msg>Don't need to test data on delete<commit_after>$ ->
  fixture = $('#qunit-fixture')

  window.formSubmitted = ->

  module "Remote"
    setup: ->
      window.formSubmitted = ->

    teardown: ->
      $(document).undelegate '.test'
      $('#qunit-fixture').html ""

  asyncTest "link is submitted via AJAX with GET method", ->
    link = $("<a data-remote href='/echo?callback=formSubmitted'>")
    fixture.append link

    window.formSubmitted = (data) ->
      equal 'GET', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is submitted via AJAX with POST method", ->
    link = $("<a data-remote data-method=post href='/echo?callback=formSubmitted'>")
    fixture.append link

    window.formSubmitted = (data) ->
      equal 'POST', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is submitted via AJAX with PUT method", ->
    link = $("<a data-remote data-method=put href='/echo?callback=formSubmitted'>")
    fixture.append link

    window.formSubmitted = (data) ->
      equal 'PUT', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is submitted via AJAX with DELETE method", ->
    link = $("<a data-remote data-method=delete href='/echo?callback=formSubmitted'>")
    fixture.append link

    window.formSubmitted = (data) ->
      equal 'DELETE', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is submitted via AJAX that accepts JSON", ->
    link = $("<a data-remote href='/echo' data-type=json>")
    fixture.append link

    $(document).delegate 'a', 'ajaxSuccess.test', (event, xhr, settings, data) ->
      equal 'GET', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    link.trigger 'click'

  asyncTest "link is prevented from being submitted", ->
    link = $("<a data-remote href='/echo'>")
    fixture.append link

    $(document).delegate 'a', 'ajaxBeforeSend.test', ->
      ok true
      false

    $(document).delegate 'a', 'ajaxSuccess.test', ->
      ok false

    link.trigger 'click'

    setTimeout (-> start()), 50


  asyncTest "form is submitted via AJAX with GET method", ->
    form = $("<form data-remote action='/echo?callback=formSubmitted'><input name=foo value=bar></form>")
    fixture.append form

    window.formSubmitted = (data) ->
      equal 'GET', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      equal 'bar', data.params['foo']
      start()

    $(form).submit()

  asyncTest "form is submitted via AJAX with POST method", ->
    form = $("<form data-remote method=post action='/echo?callback=formSubmitted'><input name=foo value=bar></form>")
    fixture.append form

    window.formSubmitted = (data) ->
      equal 'POST', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      equal 'bar', data.params['foo']
      start()

    $(form).submit()

  asyncTest "form is submitted via AJAX with PUT method", ->
    form = $("<form data-remote method=put action='/echo?callback=formSubmitted'><input name=foo value=bar></form>")
    fixture.append form

    window.formSubmitted = (data) ->
      equal 'PUT', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      equal 'bar', data.params['foo']
      start()

    $(form).submit()

  asyncTest "form is submitted via AJAX with DELETE method", ->
    form = $("<form data-remote method=delete action='/echo?callback=formSubmitted'></form>")
    fixture.append form

    window.formSubmitted = (data) ->
      equal 'DELETE', data.REQUEST_METHOD
      equal '/echo', data.REQUEST_PATH
      start()

    $(form).submit()

  asyncTest "form is submitted via AJAX that accepts JSON", ->
{'fraction_non_alphanumeric': 0.14640166276955052, 'fraction_numerical': 0.0005196154845414394, 'mean_word_length': 3.054239073196419, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 94, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6094348', 'n_tokens_mistral': 2341, 'n_tokens_neox': 2233, 'n_words': 625}