From cdc44b767c41e933801f58cdcb967ee052b4b0b9 Mon Sep 17 00:00:00 2001 From: Christopher Santero Date: Sat, 23 May 2015 15:45:37 -0400 Subject: [PATCH] [BUGFIX beta] fix passing array argument to action helper --- .../lib/keywords/closure-action.js | 3 +- .../tests/helpers/closure_action_test.js | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/ember-routing-htmlbars/lib/keywords/closure-action.js b/packages/ember-routing-htmlbars/lib/keywords/closure-action.js index dea7e528cdb..151f6eb91e8 100644 --- a/packages/ember-routing-htmlbars/lib/keywords/closure-action.js +++ b/packages/ember-routing-htmlbars/lib/keywords/closure-action.js @@ -63,7 +63,8 @@ function createClosureAction(target, action, valuePath, actionArguments) { closureAction = function() { var args = actionArguments; if (arguments.length > 0) { - args = actionArguments.concat(...arguments); + var passedArguments = Array.prototype.slice.apply(arguments); + args = actionArguments.concat(passedArguments); } if (valuePath && args.length > 0) { args[0] = get(args[0], valuePath); diff --git a/packages/ember-routing-htmlbars/tests/helpers/closure_action_test.js b/packages/ember-routing-htmlbars/tests/helpers/closure_action_test.js index 8e7b03d622f..2d333fdf8f3 100644 --- a/packages/ember-routing-htmlbars/tests/helpers/closure_action_test.js +++ b/packages/ember-routing-htmlbars/tests/helpers/closure_action_test.js @@ -164,6 +164,42 @@ if (Ember.FEATURES.isEnabled("ember-routing-htmlbars-improved-actions")) { innerComponent.fireAction(); }); + QUnit.test("array arguments are passed correctly to action", function(assert) { + assert.expect(3); + + const first = 'foo'; + const second = [3, 5]; + const third = [4, 9]; + + innerComponent = EmberComponent.extend({ + fireAction() { + this.attrs.submit(second, third); + } + }).create(); + + outerComponent = EmberComponent.extend({ + layout: compile(` + {{view innerComponent submit=(action outerSubmit first)}} + `), + innerComponent, + value: '', + outerSubmit(actualFirst, actualSecond, actualThird) { + assert.equal(actualFirst, first, 'action has the correct first arg'); + assert.equal(actualSecond, second, 'action has the correct second arg'); + assert.equal(actualThird, third, 'action has the correct third arg'); + } + }).create(); + + runAppend(outerComponent); + + run(function() { + outerComponent.set('first', first); + outerComponent.set('second', second); + }); + + innerComponent.fireAction(); + }); + QUnit.test("mut values can be wrapped in actions, are settable", function(assert) { assert.expect(1);