diff --git a/app/assets/javascripts/app/models/_application_model.coffee b/app/assets/javascripts/app/models/_application_model.coffee index ca9640fee..8a0830c05 100644 --- a/app/assets/javascripts/app/models/_application_model.coffee +++ b/app/assets/javascripts/app/models/_application_model.coffee @@ -869,5 +869,7 @@ set new attributes of model (remove already available attributes) @configure_attributes = $.extend(true, [], @org_configure_attributes) @resetCallbacks: -> - @SUBSCRIPTION_ITEM = {} - @SUBSCRIPTION_COLLECTION = {} + if @SUBSCRIPTION_ITEM + @SUBSCRIPTION_ITEM = {} + if @SUBSCRIPTION_COLLECTION + @SUBSCRIPTION_COLLECTION = {} diff --git a/app/views/tests/model_binding.html.erb b/app/views/tests/model_binding.html.erb new file mode 100644 index 000000000..4748a1f1b --- /dev/null +++ b/app/views/tests/model_binding.html.erb @@ -0,0 +1,16 @@ + + + + + + + + + +
+ diff --git a/config/routes/test.rb b/config/routes/test.rb index 8ccccd6f6..1c906fdfa 100644 --- a/config/routes/test.rb +++ b/config/routes/test.rb @@ -3,6 +3,7 @@ Zammad::Application.routes.draw do match '/tests_core', to: 'tests#core', via: :get match '/tests_ui', to: 'tests#ui', via: :get match '/tests_model', to: 'tests#model', via: :get + match '/tests_model_binding', to: 'tests#model_binding', via: :get match '/tests_model_ui', to: 'tests#model_ui', via: :get match '/tests_form', to: 'tests#form', via: :get match '/tests_form_tree_select', to: 'tests#form_tree_select', via: :get diff --git a/public/assets/tests/model_binding.js b/public/assets/tests/model_binding.js new file mode 100644 index 000000000..e102a60a5 --- /dev/null +++ b/public/assets/tests/model_binding.js @@ -0,0 +1,52 @@ +window.onload = function() { + +test("model bindings and rebinding", function() { + + var callback_count1 = 0 + var callbacks = App.Template._callbacks + Object.keys(callbacks).forEach(function(key) { + callback_count1 = callback_count1 + callbacks[key].length + }); + equal(callback_count1, 2) + + equal(App.Template.SUBSCRIPTION_COLLECTION, undefined) + + App.Template.clearInMemory() + + equal(App.Template.SUBSCRIPTION_COLLECTION, undefined) + + var callback_count2 = 0 + callbacks = App.Template._callbacks + Object.keys(callbacks).forEach(function(key) { + callback_count2 = callback_count2 + callbacks[key].length + }); + equal(callback_count2, callback_count1) + + var render = function() {} + var subscribe_id = App.Template.subscribe(render, {initFetch: true}) + + ok(_.isObject(App.Template.SUBSCRIPTION_COLLECTION)) + ok(!_.isEmpty(App.Template.SUBSCRIPTION_COLLECTION)) + + var callback_count3 = 0 + callbacks = App.Template._callbacks + Object.keys(callbacks).forEach(function(key) { + callback_count3 = callback_count3 + callbacks[key].length + }); + equal(callback_count3, 6) + + App.Template.clearInMemory() + + ok(_.isObject(App.Template.SUBSCRIPTION_COLLECTION)) + ok(_.isEmpty(App.Template.SUBSCRIPTION_COLLECTION)) + + var callback_count4 = 0 + callbacks = App.Template._callbacks + Object.keys(callbacks).forEach(function(key) { + callback_count4 = callback_count4 + callbacks[key].length + }); + equal(callback_count4, callback_count3) + +}); + +} diff --git a/test/browser/aab_unit_test.rb b/test/browser/aab_unit_test.rb index fab47d2de..ea63b0a47 100644 --- a/test/browser/aab_unit_test.rb +++ b/test/browser/aab_unit_test.rb @@ -28,6 +28,13 @@ class AAbUnitTest < TestCase value: '0', ) + location(url: browser_url + '/tests_model_binding') + sleep 8 + match( + css: '.result .failed', + value: '0', + ) + location(url: browser_url + '/tests_model_ui') sleep 8 match(