Skip to content

Commit a1e9072

Browse files
committed
Merge pull request #9401 from BookingSync/warn-route-queryparams-array
Raise an error when attempting to merge an Array from mergedProperties
2 parents 140db71 + 7a31f9a commit a1e9072

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

packages/ember-metal/lib/mixin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
meta as metaFor,
2121
wrap,
2222
makeArray,
23-
apply
23+
apply,
24+
isArray
2425
} from "ember-metal/utils";
2526
import expandProperties from "ember-metal/expand_properties";
2627
import {
@@ -210,6 +211,9 @@ function applyConcatenatedProperties(obj, key, value, values) {
210211
function applyMergedProperties(obj, key, value, values) {
211212
var baseValue = values[key] || obj[key];
212213

214+
Ember.assert("You passed in `" + JSON.stringify(value) + "` as the value for `" + key +
215+
"` but `" + key + "` cannot be an Array", !isArray(value));
216+
213217
if (!baseValue) { return value; }
214218

215219
var newBase = merge({}, baseValue);

packages/ember-metal/tests/mixin/mergedProperties_test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,21 @@ test("mergedProperties' overwriting methods can call _super", function() {
126126
var obj = mixin({}, MixinA, MixinB, MixinC);
127127
equal(obj.foo.meth("WOOT"), "WAT");
128128
});
129+
130+
test('Merging an Array should raise an error', function() {
131+
132+
expect(1);
133+
134+
var MixinA = Mixin.create({
135+
mergedProperties: ['foo'],
136+
foo: { a: true, b: true, c: true }
137+
});
138+
139+
var MixinB = Mixin.create({
140+
foo: ["a"]
141+
});
142+
143+
expectAssertion(function() {
144+
mixin({}, MixinA, MixinB);
145+
}, 'You passed in `["a"]` as the value for `foo` but `foo` cannot be an Array');
146+
});

packages/ember/tests/routing/query_params_test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,20 @@ test("can use refreshModel even w URL changes that remove QPs from address bar",
575575
equal(indexController.get('omg'), 'lol');
576576
});
577577

578+
test("warn user that routes query params configuration must be an Object, not an Array", function() {
579+
expect(1);
580+
581+
App.ApplicationRoute = Ember.Route.extend({
582+
queryParams: [
583+
{'commitBy': { replace: true }}
584+
]
585+
});
586+
587+
expectAssertion(function() {
588+
bootApplication();
589+
}, 'You passed in `[{"commitBy":{"replace":true}}]` as the value for `queryParams` but `queryParams` cannot be an Array');
590+
});
591+
578592
test("can opt into a replace query by specifying replace:true in the Router config hash", function() {
579593
expect(2);
580594
App.ApplicationController = Ember.Controller.extend({

0 commit comments

Comments
 (0)