Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fire iteration with callRemote method test
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
var App = App || {}; | ||
|
||
App.build_form = function(opt) { | ||
|
||
console.log('opt is'); | ||
console.log(opt); | ||
|
||
var defaults = { | ||
action: 'http://example.com/address', | ||
'data-remote': 'true' | ||
}; | ||
|
||
var options = $.extend(defaults, opt); | ||
|
||
|
||
console.log('options is'); | ||
console.log(options); | ||
|
||
$(document.body).append($('<form />', options)); | ||
|
||
$('form').append($('<input />', { | ||
id: 'user_name', | ||
type: 'text', | ||
size: '30', | ||
'name': 'user_name', | ||
'value': 'john' | ||
})); | ||
} | ||
|
||
module('call-remote', { | ||
teardown: function() { | ||
$('form').remove(); | ||
} | ||
}); | ||
|
||
test('method should be picked up from method attribute', function() { | ||
expect(1); | ||
|
||
App.build_form({'method': 'put', 'data-method': 'fail'}); | ||
|
||
var ajaxArgs; | ||
|
||
jack(function() { | ||
jack.expect('$.ajax').once().mock(function(args) { | ||
ajaxArgs = args; | ||
}); | ||
$('form[data-remote]').trigger('submit'); | ||
}); | ||
|
||
equals(ajaxArgs.type, 'PUT', 'ajax arguments should have PUT as request type'); | ||
}); | ||
|
||
test('method should be picked up from data-method attribute', function() { | ||
expect(1); | ||
|
||
App.build_form({'data-method': 'put'}); | ||
|
||
var ajaxArgs; | ||
|
||
jack(function() { | ||
jack.expect('$.ajax').once().mock(function(args) { | ||
ajaxArgs = args; | ||
}); | ||
$('form[data-remote]').trigger('submit'); | ||
}); | ||
|
||
equals(ajaxArgs.type, 'PUT', 'ajax arguments should have PUT as request type'); | ||
}); | ||
|
||
test('default method should be picked up', function() { | ||
expect(1); | ||
|
||
App.build_form({}); | ||
|
||
var ajaxArgs; | ||
|
||
jack(function() { | ||
jack.expect('$.ajax').once().mock(function(args) { | ||
ajaxArgs = args; | ||
}); | ||
$('form[data-remote]').trigger('submit'); | ||
}); | ||
|
||
equals(ajaxArgs.type, 'GET', 'ajax arguments should have PUT as request type'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//take into account CSRF stuff | ||
module('data-remote', { | ||
|
||
teardown: function() { | ||
|