diff --git a/public/javascripts/rails.js b/public/javascripts/rails.js index 247c3ca60..9c8fef0ba 100644 --- a/public/javascripts/rails.js +++ b/public/javascripts/rails.js @@ -98,10 +98,14 @@ jQuery(function ($) { $('form[data-remote]').live('submit', function (e) { $(this).callRemote(); e.preventDefault(); - $(this).clearForm(); - $(this).focusout(); }); + $('form[data-remote]').live('ajax:success', function (e) { + $(this).clearForm(); + $(this).focusout(); + }); + + $('a[data-remote],input[data-remote]').live('click', function (e) { $(this).callRemote(); e.preventDefault(); diff --git a/spec/javascripts/helpers/SpecHelper.js b/spec/javascripts/helpers/SpecHelper.js index f7aa90333..2426c0a47 100644 --- a/spec/javascripts/helpers/SpecHelper.js +++ b/spec/javascripts/helpers/SpecHelper.js @@ -11,12 +11,13 @@ beforeEach(function() { $('#jasmine_content').empty(); - spec.clearLiveEventBindings(); + // NOTE Commented (as well as in afterEach) to keep the listeners from rails.js alive. + //spec.clearLiveEventBindings(); jasmine.Clock.useMock(); }); afterEach(function() { - spec.clearLiveEventBindings(); + //spec.clearLiveEventBindings(); expect(spec.loadFixtureCount).toBeLessThan(2); spec.loadFixtureCount = 0; }); diff --git a/spec/javascripts/rails-spec.js b/spec/javascripts/rails-spec.js new file mode 100644 index 000000000..c79917319 --- /dev/null +++ b/spec/javascripts/rails-spec.js @@ -0,0 +1,22 @@ +describe("rails", function() { + describe("remote forms", function() { + beforeEach(function() { + $("#jasmine_content").html( + '
' + ); + }); + it("should retain form values if ajax fails", function() { + $('#form').trigger('ajax:failure'); + expect($('#status_message_message').val()).not.toEqual(""); + }); + it("should clear form on ajax:success", function() { + $('#form').trigger('ajax:success'); + + expect($('#status_message_message').val()).toEqual(""); + + }); + }); +}); \ No newline at end of file diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index f023e116b..75a4b0d42 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -25,6 +25,7 @@ src_files: - public/javascripts/view.js - public/javascripts/stream.js - public/javascripts/validation.js + - public/javascripts/rails.js # stylesheets # # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.