diff --git a/Rakefile b/Rakefile index 7553d2cb910..d005125d524 100644 --- a/Rakefile +++ b/Rakefile @@ -81,7 +81,6 @@ task :test, [:suite] => :dist do |t, args| "package=all&extendprototypes=true&nojshint=true", "package=all&extendprototypes=true&jquery=git&nojshint=true", "package=all&nocpdefaultcacheable=true&nojshint=true", - "package=all&noviewpreservescontext=true&nojshint=true", "package=all&dist=build&nojshint=true"] } diff --git a/packages/ember-handlebars/lib/helpers/outlet.js b/packages/ember-handlebars/lib/helpers/outlet.js index 9bde74536b3..2519a3254b7 100644 --- a/packages/ember-handlebars/lib/helpers/outlet.js +++ b/packages/ember-handlebars/lib/helpers/outlet.js @@ -51,11 +51,7 @@ Ember.Handlebars.registerHelper('outlet', function(property, options) { property = 'view'; } - if(Ember.VIEW_PRESERVES_CONTEXT) { - options.hash.currentViewBinding = "view.context." + property; - } else { - options.hash.currentViewBinding = "controller." + property; - } + options.hash.currentViewBinding = "view.context." + property; return Ember.Handlebars.helpers.view.call(this, Ember.Handlebars.OutletView, options); }); diff --git a/packages/ember-handlebars/lib/helpers/view.js b/packages/ember-handlebars/lib/helpers/view.js index e6d033366ad..95a308e34dc 100644 --- a/packages/ember-handlebars/lib/helpers/view.js +++ b/packages/ember-handlebars/lib/helpers/view.js @@ -11,7 +11,6 @@ require("ember-handlebars"); var get = Ember.get, set = Ember.set; var PARENT_VIEW_PATH = /^parentView\./; var EmberHandlebars = Ember.Handlebars; -var VIEW_PRESERVES_CONTEXT = Ember.VIEW_PRESERVES_CONTEXT; EmberHandlebars.ViewHelper = Ember.Object.create({ @@ -143,7 +142,7 @@ EmberHandlebars.ViewHelper = Ember.Object.create({ // We only want to override the `_context` computed property if there is // no specified controller. See View#_context for more information. - if (VIEW_PRESERVES_CONTEXT && !newView.proto().controller && !newView.proto().controllerBinding && !viewOptions.controller && !viewOptions.controllerBinding) { + if (!newView.proto().controller && !newView.proto().controllerBinding && !viewOptions.controller && !viewOptions.controllerBinding) { viewOptions._context = thisContext; } diff --git a/packages/ember-handlebars/tests/handlebars_test.js b/packages/ember-handlebars/tests/handlebars_test.js index f1b0b26b45f..c8501e19bd7 100644 --- a/packages/ember-handlebars/tests/handlebars_test.js +++ b/packages/ember-handlebars/tests/handlebars_test.js @@ -220,23 +220,13 @@ test("child views can be inserted using the {{view}} Handlebars helper", functio templates: templates }); - if (Ember.VIEW_PRESERVES_CONTEXT) { - view.set('cruel', "cruel"); - } else { - TemplateTests.LabelView.reopen({ cruel: "cruel" }); - } + view.set('cruel', "cruel"); appendView(); ok(view.$("#hello-world:contains('Hello world!')").length, "The parent view renders its contents"); - - if (Ember.VIEW_PRESERVES_CONTEXT) { - ok(view.$("#child-view:contains('Goodbye cruel world!')").length === 1, "The child view renders its content once"); - ok(view.$().text().match(/Hello world!.*Goodbye cruel world\!/), "parent view should appear before the child view"); - } else { - ok(view.$("#child-view:contains('Goodbye cruel world?')").length === 1, "The child view renders its content once"); - ok(view.$().text().match(/Hello world!.*Goodbye cruel world\?/), "parent view should appear before the child view"); - } + ok(view.$("#child-view:contains('Goodbye cruel world!')").length === 1, "The child view renders its content once"); + ok(view.$().text().match(/Hello world!.*Goodbye cruel world\!/), "parent view should appear before the child view"); }); test("should accept relative paths to views", function() { @@ -281,23 +271,14 @@ test("child views can be inserted inside a bind block", function() { templates: templates }); - if (Ember.VIEW_PRESERVES_CONTEXT) { - view.set('content', Ember.Object.create({ blah: "wot" })); - } else { - TemplateTests.BQView.reopen({ content: Ember.Object.create({ blah: "wot" }) }); - } + view.set('content', Ember.Object.create({ blah: "wot" })); appendView(); ok(view.$("#hello-world:contains('Hello world!')").length, "The parent view renders its contents"); - if (Ember.VIEW_PRESERVES_CONTEXT) { - ok(view.$("blockquote").text().match(/Goodbye.*wot.*cruel.*world\!/), "The child view renders its content once"); - ok(view.$().text().match(/Hello world!.*Goodbye.*wot.*cruel.*world\!/), "parent view should appear before the child view"); - } else { - ok(view.$("blockquote").text().match(/Goodbye.*wot.*cruel.*world\?/), "The child view renders its content once"); - ok(view.$().text().match(/Hello world!.*Goodbye.*wot.*cruel.*world\?/), "parent view should appear before the child view"); - } + ok(view.$("blockquote").text().match(/Goodbye.*wot.*cruel.*world\!/), "The child view renders its content once"); + ok(view.$().text().match(/Hello world!.*Goodbye.*wot.*cruel.*world\!/), "parent view should appear before the child view"); }); test("Ember.View should bind properties in the parent context", function() { @@ -767,77 +748,46 @@ test("views set the template of their children to a passed block", function() { ok(view.$('h1:has(span)').length === 1, "renders the passed template inside the parent template"); }); -if (Ember.VIEW_PRESERVES_CONTEXT) { - - test("views render their template in the context of the parent view's context", function() { - var templates = Ember.Object.create({ - parent: Ember.Handlebars.compile('

{{#with content}}{{#view}}{{firstName}} {{lastName}}{{/view}}{{/with}}

') - }); - - view = Ember.View.create({ - templates: templates, - templateName: 'parent', - - content: { - firstName: "Lana", - lastName: "del Heeeyyyyyy" - } - }); - - appendView(); - equal(view.$('h1').text(), "Lana del Heeeyyyyyy", "renders properties from parent context"); +test("views render their template in the context of the parent view's context", function() { + var templates = Ember.Object.create({ + parent: Ember.Handlebars.compile('

{{#with content}}{{#view}}{{firstName}} {{lastName}}{{/view}}{{/with}}

') }); - test("views make a view keyword available that allows template to reference view context", function() { - var templates = Ember.Object.create({ - parent: Ember.Handlebars.compile('

{{#with content}}{{#view subview}}{{view.firstName}} {{lastName}}{{/view}}{{/with}}

') - }); - - view = Ember.View.create({ - templates: templates, - templateName: 'parent', - - content: { - subview: Ember.View.extend({ - firstName: "Brodele" - }), - firstName: "Lana", - lastName: "del Heeeyyyyyy" - } - }); + view = Ember.View.create({ + templates: templates, + templateName: 'parent', - appendView(); - equal(view.$('h1').text(), "Brodele del Heeeyyyyyy", "renders properties from parent context"); + content: { + firstName: "Lana", + lastName: "del Heeeyyyyyy" + } }); -} else { - - test("should pass hash arguments to the view object", function() { - TemplateTests.bindTestObject = Ember.Object.create({ - bar: 'bat' - }); - - TemplateTests.HashArgTemplateView = Ember.View.extend({ - }); - - Ember.run(function() { - view = Ember.View.create({ - template: Ember.Handlebars.compile('{{#view TemplateTests.HashArgTemplateView fooBinding="TemplateTests.bindTestObject.bar"}}{{foo}}{{/view}}') - }); - - appendView(); - }); + appendView(); + equal(view.$('h1').text(), "Lana del Heeeyyyyyy", "renders properties from parent context"); +}); - equal(view.$().text(), "bat", "prints initial bound value"); +test("views make a view keyword available that allows template to reference view context", function() { + var templates = Ember.Object.create({ + parent: Ember.Handlebars.compile('

{{#with content}}{{#view subview}}{{view.firstName}} {{lastName}}{{/view}}{{/with}}

') + }); - Ember.run(function() { - set(TemplateTests.bindTestObject, 'bar', 'brains'); - }); + view = Ember.View.create({ + templates: templates, + templateName: 'parent', - equal(view.$().text(), "brains", "prints updated bound value"); + content: { + subview: Ember.View.extend({ + firstName: "Brodele" + }), + firstName: "Lana", + lastName: "del Heeeyyyyyy" + } }); -} + appendView(); + equal(view.$('h1').text(), "Brodele del Heeeyyyyyy", "renders properties from parent context"); +}); test("should warn if setting a template on a view with a templateName already specified", function() { view = Ember.View.create({ @@ -2304,9 +2254,7 @@ test("should update bound values after view's parent is removed and then re-appe }) }); - var targetView = Ember.VIEW_PRESERVES_CONTEXT ? parentView : parentView.get('testView'); - - targetView.setProperties({ + parentView.setProperties({ showStuff: true, boundValue: "foo" }); @@ -2318,29 +2266,29 @@ test("should update bound values after view's parent is removed and then re-appe equal(Ember.$.trim(view.$().text()), "foo"); Ember.run(function() { - set(targetView, 'showStuff', false); + set(parentView, 'showStuff', false); }); equal(Ember.$.trim(view.$().text()), "Not true."); Ember.run(function() { - set(targetView, 'showStuff', true); + set(parentView, 'showStuff', true); }); equal(Ember.$.trim(view.$().text()), "foo"); Ember.run(function() { parentView.remove(); - set(targetView, 'showStuff', false); + set(parentView, 'showStuff', false); }); Ember.run(function() { - set(targetView, 'showStuff', true); + set(parentView, 'showStuff', true); }); Ember.run(function() { parentView.appendTo('#qunit-fixture'); }); Ember.run(function() { - set(targetView, 'boundValue', "bar"); + set(parentView, 'boundValue', "bar"); }); equal(Ember.$.trim(view.$().text()), "bar"); }); diff --git a/packages/ember-handlebars/tests/helpers/each_test.js b/packages/ember-handlebars/tests/helpers/each_test.js index 708451ef347..f63866dbf22 100644 --- a/packages/ember-handlebars/tests/helpers/each_test.js +++ b/packages/ember-handlebars/tests/helpers/each_test.js @@ -270,72 +270,68 @@ test("it works with the controller keyword", function() { equal(view.$().text(), "foobarbaz"); }); -if (Ember.VIEW_PRESERVES_CONTEXT) { +module("{{#each foo in bar}}"); - module("{{#each foo in bar}}"); - - test("#each accepts a name binding and does not change the context", function() { - view = Ember.View.create({ - template: templateFor("{{#each item in items}}{{title}} {{item}}{{/each}}"), - title: "My Cool Each Test", - items: Ember.A([1, 2]) - }); - - append(view); - - equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2"); +test("#each accepts a name binding and does not change the context", function() { + view = Ember.View.create({ + template: templateFor("{{#each item in items}}{{title}} {{item}}{{/each}}"), + title: "My Cool Each Test", + items: Ember.A([1, 2]) }); - test("#each accepts a name binding and can display child properties", function() { - view = Ember.View.create({ - template: templateFor("{{#each item in items}}{{title}} {{item.name}}{{/each}}"), - title: "My Cool Each Test", - items: Ember.A([{ name: 1 }, { name: 2 }]) - }); + append(view); - append(view); + equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2"); +}); - equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2"); +test("#each accepts a name binding and can display child properties", function() { + view = Ember.View.create({ + template: templateFor("{{#each item in items}}{{title}} {{item.name}}{{/each}}"), + title: "My Cool Each Test", + items: Ember.A([{ name: 1 }, { name: 2 }]) }); - test("#each accepts 'this' as the right hand side", function() { - view = Ember.View.create({ - template: templateFor("{{#each item in this}}{{view.title}} {{item.name}}{{/each}}"), - title: "My Cool Each Test", - controller: Ember.A([{ name: 1 }, { name: 2 }]) - }); + append(view); - append(view); + equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2"); +}); - equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2"); +test("#each accepts 'this' as the right hand side", function() { + view = Ember.View.create({ + template: templateFor("{{#each item in this}}{{view.title}} {{item.name}}{{/each}}"), + title: "My Cool Each Test", + controller: Ember.A([{ name: 1 }, { name: 2 }]) }); - test("views inside #each preserve the new context", function() { - var controller = Ember.A([ { name: "Adam" }, { name: "Steve" } ]); + append(view); - view = Ember.View.create({ - controller: controller, - template: templateFor('{{#each controller}}{{#view}}{{name}}{{/view}}{{/each}}') - }); + equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2"); +}); - append(view); +test("views inside #each preserve the new context", function() { + var controller = Ember.A([ { name: "Adam" }, { name: "Steve" } ]); - equal(view.$().text(), "AdamSteve"); + view = Ember.View.create({ + controller: controller, + template: templateFor('{{#each controller}}{{#view}}{{name}}{{/view}}{{/each}}') }); - test("controller is assignable inside an #each", function() { - var controller = Ember.ArrayController.create({ - content: Ember.A([ { name: "Adam" }, { name: "Steve" } ]) - }); + append(view); - view = Ember.View.create({ - controller: controller, - template: templateFor('{{#each itemController in this}}{{#view controllerBinding="itemController"}}{{name}}{{/view}}{{/each}}') - }); + equal(view.$().text(), "AdamSteve"); +}); - append(view); +test("controller is assignable inside an #each", function() { + var controller = Ember.ArrayController.create({ + content: Ember.A([ { name: "Adam" }, { name: "Steve" } ]) + }); - equal(view.$().text(), "AdamSteve"); + view = Ember.View.create({ + controller: controller, + template: templateFor('{{#each itemController in this}}{{#view controllerBinding="itemController"}}{{name}}{{/view}}{{/each}}') }); -} + append(view); + + equal(view.$().text(), "AdamSteve"); +}); diff --git a/packages/ember-handlebars/tests/helpers/if_unless_test.js b/packages/ember-handlebars/tests/helpers/if_unless_test.js index 560add6cafa..060a401eda3 100644 --- a/packages/ember-handlebars/tests/helpers/if_unless_test.js +++ b/packages/ember-handlebars/tests/helpers/if_unless_test.js @@ -14,18 +14,14 @@ module("Handlebars {{#if}} and {{#unless}} helpers", { } }); -if (Ember.VIEW_PRESERVES_CONTEXT) { +test("unless should keep the current context (#784)", function() { + view = Ember.View.create({ + o: Ember.Object.create({foo: '42'}), - test("unless should keep the current context (#784)", function() { - view = Ember.View.create({ - o: Ember.Object.create({foo: '42'}), - - template: Ember.Handlebars.compile('{{#with o}}{{#view Ember.View}}{{#unless view.doesNotExist}}foo: {{foo}}{{/unless}}{{/view}}{{/with}}') - }); - - appendView(view); - - equal(view.$().text(), 'foo: 42'); + template: Ember.Handlebars.compile('{{#with o}}{{#view Ember.View}}{{#unless view.doesNotExist}}foo: {{foo}}{{/unless}}{{/view}}{{/with}}') }); -} + appendView(view); + + equal(view.$().text(), 'foo: 42'); +}); diff --git a/packages/ember-handlebars/tests/helpers/outlet_test.js b/packages/ember-handlebars/tests/helpers/outlet_test.js index 73655b71db2..627c9319bf2 100644 --- a/packages/ember-handlebars/tests/helpers/outlet_test.js +++ b/packages/ember-handlebars/tests/helpers/outlet_test.js @@ -58,26 +58,24 @@ test("outlet should allow controllers to fill in slots in prerender state", func equal(view.$().text(), 'HIBYE'); }); -if(Ember.VIEW_PRESERVES_CONTEXT) { - test("outlet should allow a view's default context to fill in slots", function() { - var template = "

HI

{{outlet}}"; - view = Ember.View.create({ - template: Ember.Handlebars.compile(template) - }); - - appendView(view); +test("outlet should allow a view's default context to fill in slots", function() { + var template = "

HI

{{outlet}}"; + view = Ember.View.create({ + template: Ember.Handlebars.compile(template) + }); - equal(view.$().text(), 'HI'); + appendView(view); - Ember.run(function() { - view.set('view', Ember.View.create({ - template: compile("

BYE

") - })); - }); + equal(view.$().text(), 'HI'); - equal(view.$().text(), 'HIBYE'); + Ember.run(function() { + view.set('view', Ember.View.create({ + template: compile("

BYE

") + })); }); -} + + equal(view.$().text(), 'HIBYE'); +}); test("outlet should support an optional name", function() { var controller = Ember.Object.create(); diff --git a/packages/ember-handlebars/tests/helpers/with_test.js b/packages/ember-handlebars/tests/helpers/with_test.js index 22bcd0937e8..19cd468ad15 100644 --- a/packages/ember-handlebars/tests/helpers/with_test.js +++ b/packages/ember-handlebars/tests/helpers/with_test.js @@ -122,22 +122,20 @@ test("it should support #with foo as bar, then #with bar as qux", function() { equal(view.$().text(), "butterfly", "should update"); }); -if (Ember.VIEW_PRESERVES_CONTEXT) { - module("Handlebars {{#with this as foo}}"); +module("Handlebars {{#with this as foo}}"); - test("it should support #with this as qux", function() { - var view = Ember.View.create({ - template: Ember.Handlebars.compile("{{#with this as person}}{{person.name}}{{/with}}"), - controller: Ember.Object.create({ name: "Los Pivots" }) - }); - - appendView(view); - equal(view.$().text(), "Los Pivots", "should be properly scoped"); +test("it should support #with this as qux", function() { + var view = Ember.View.create({ + template: Ember.Handlebars.compile("{{#with this as person}}{{person.name}}{{/with}}"), + controller: Ember.Object.create({ name: "Los Pivots" }) + }); - Ember.run(function() { - Ember.set(view, 'controller.name', "l'Pivots"); - }); + appendView(view); + equal(view.$().text(), "Los Pivots", "should be properly scoped"); - equal(view.$().text(), "l'Pivots", "should update"); + Ember.run(function() { + Ember.set(view, 'controller.name', "l'Pivots"); }); -} + + equal(view.$().text(), "l'Pivots", "should update"); +}); diff --git a/packages/ember-metal/lib/core.js b/packages/ember-metal/lib/core.js index 4670242d7fb..9dc5a1ad086 100644 --- a/packages/ember-metal/lib/core.js +++ b/packages/ember-metal/lib/core.js @@ -123,46 +123,6 @@ Ember.SHIM_ES5 = (Ember.ENV.SHIM_ES5 === false) ? false : Ember.EXTEND_PROTOTYPE */ Ember.CP_DEFAULT_CACHEABLE = (Ember.ENV.CP_DEFAULT_CACHEABLE !== false); -/** - Determines whether views render their templates using themselves - as the context, or whether it is inherited from the parent. This option - will be removed in the 1.1 release. - - If you need to update your application to use the new context rules, simply - prefix property access with `view.`: - - Before: - - ``` handlebars - {{#each App.photosController}} - Photo Title: {{title}} - {{#view App.InfoView contentBinding="this"}} - {{content.date}} - {{content.cameraType}} - {{otherViewProperty}} - {{/view}} - {{/each}} - ``` - - After: - - ``` handlebars - {{#each App.photosController}} - Photo Title: {{title}} - {{#view App.InfoView}} - {{date}} - {{cameraType}} - {{view.otherViewProperty}} - {{/view}} - {{/each}} - ``` - - @property VIEW_PRESERVES_CONTEXT - @type Boolean - @default true -*/ -Ember.VIEW_PRESERVES_CONTEXT = (Ember.ENV.VIEW_PRESERVES_CONTEXT !== false); - /** Empty function. Useful for some operations. diff --git a/packages/ember-views/lib/views/view.js b/packages/ember-views/lib/views/view.js index 0f9bef83355..6eb129933cf 100644 --- a/packages/ember-views/lib/views/view.js +++ b/packages/ember-views/lib/views/view.js @@ -26,8 +26,7 @@ var childViewsProperty = Ember.computed(function() { return ret; }).property().cacheable(); -var VIEW_PRESERVES_CONTEXT = Ember.VIEW_PRESERVES_CONTEXT; -Ember.warn("The way that the {{view}} helper affects templates is about to change. Previously, templates inside child views would use the new view as the context. Soon, views will preserve their parent context when rendering their template. You can opt-in early to the new behavior by setting `ENV.VIEW_PRESERVES_CONTEXT = true`. For more information, see https://gist.github.com/2494968. You should update your templates as soon as possible; this default will change soon, and the option will be eliminated entirely before the 1.0 release.", VIEW_PRESERVES_CONTEXT); +Ember.warn("The VIEW_PRESERVES_CONTEXT flag has been removed and the functionality can no longer be disabled.", Ember.ENV.VIEW_PRESERVES_CONTEXT !== false); /** Global hash of shared templates. This will automatically be populated @@ -898,15 +897,13 @@ Ember.View = Ember.CoreView.extend( return value; } - if (VIEW_PRESERVES_CONTEXT) { - if (controller = get(this, 'controller')) { - return controller; - } + if (controller = get(this, 'controller')) { + return controller; + } - parentView = get(this, '_parentView'); - if (parentView) { - return get(parentView, '_context'); - } + parentView = get(this, '_parentView'); + if (parentView) { + return get(parentView, '_context'); } return this; diff --git a/packages/ember-views/tests/views/container_view_test.js b/packages/ember-views/tests/views/container_view_test.js index 76089b8b7cd..9e5063fe0fa 100644 --- a/packages/ember-views/tests/views/container_view_test.js +++ b/packages/ember-views/tests/views/container_view_test.js @@ -157,11 +157,9 @@ test("if a ContainerView starts with a currentView, it is rendered as a child vi equal(get(container, 'childViews.length'), 1, "should have one child view"); equal(get(container, 'childViews').objectAt(0), mainView, "should have the currentView as the only child view"); equal(mainView.get('parentView'), container, "parentView is setup"); - if (Ember.VIEW_PRESERVES_CONTEXT) { - equal(context, container.get('context'), 'context preserved'); - equal(templateData.keywords.controller, controller, 'templateData is setup'); - equal(templateData.keywords.view, mainView, 'templateData is setup'); - } + equal(context, container.get('context'), 'context preserved'); + equal(templateData.keywords.controller, controller, 'templateData is setup'); + equal(templateData.keywords.view, mainView, 'templateData is setup'); }); test("if a ContainerView is created with a currentView, it is rendered as a child view", function() { @@ -190,11 +188,9 @@ test("if a ContainerView is created with a currentView, it is rendered as a chil equal(get(container, 'childViews.length'), 1, "should have one child view"); equal(get(container, 'childViews').objectAt(0), mainView, "should have the currentView as the only child view"); equal(mainView.get('parentView'), container, "parentView is setup"); - if (Ember.VIEW_PRESERVES_CONTEXT) { - equal(context, container.get('context'), 'context preserved'); - equal(templateData.keywords.controller, controller, 'templateData is setup'); - equal(templateData.keywords.view, mainView, 'templateData is setup'); - } + equal(context, container.get('context'), 'context preserved'); + equal(templateData.keywords.controller, controller, 'templateData is setup'); + equal(templateData.keywords.view, mainView, 'templateData is setup'); }); test("if a ContainerView starts with no currentView and then one is set, the ContainerView is updated", function() { diff --git a/packages/ember-views/tests/views/view/context_test.js b/packages/ember-views/tests/views/view/context_test.js index 77b55e7e578..018a9e69b35 100644 --- a/packages/ember-views/tests/views/view/context_test.js +++ b/packages/ember-views/tests/views/view/context_test.js @@ -1,58 +1,32 @@ module("Ember.View - context property"); -if (Ember.VIEW_PRESERVES_CONTEXT) { - test("setting a controller on a inner view should change it context", function() { - var App = {}; - var a = { name: 'a' }; - var b = { name: 'b' }; - - var innerView = Ember.View.create(); - var middleView = Ember.ContainerView.create(); - var outerView = App.outerView = Ember.ContainerView.create({ - controller: a - }); - - Ember.run(function() { - outerView.appendTo('#qunit-fixture'); - }); - - Ember.run(function () { - outerView.set('currentView', middleView); - }); - - Ember.run(function () { - innerView.set('controller', b); - middleView.set('currentView', innerView); - }); - - // assert - equal(outerView.get('context'), a, 'outer context correct'); - equal(middleView.get('context'), a, 'middle context correct'); - equal(innerView.get('context'), b, 'inner context correct'); +test("setting a controller on a inner view should change it context", function() { + var App = {}; + var a = { name: 'a' }; + var b = { name: 'b' }; + + var innerView = Ember.View.create(); + var middleView = Ember.ContainerView.create(); + var outerView = App.outerView = Ember.ContainerView.create({ + controller: a }); -} else { - test("context defaults to current view", function() { - var innerView = Ember.View.create(); - var middleView = Ember.ContainerView.create(); - var outerView = Ember.ContainerView.create(); - - Ember.run(function() { - outerView.appendTo('#qunit-fixture'); - }); - Ember.run(function () { - outerView.set('currentView', middleView); - }); + Ember.run(function() { + outerView.appendTo('#qunit-fixture'); + }); - Ember.run(function () { - middleView.set('currentView', innerView); - }); + Ember.run(function () { + outerView.set('currentView', middleView); + }); - // assert - equal(outerView.get('context'), outerView, 'outer context correct'); - equal(middleView.get('context'), middleView, 'middle context correct'); - equal(innerView.get('context'), innerView, 'inner context correct'); + Ember.run(function () { + innerView.set('controller', b); + middleView.set('currentView', innerView); }); -} + // assert + equal(outerView.get('context'), a, 'outer context correct'); + equal(middleView.get('context'), a, 'middle context correct'); + equal(innerView.get('context'), b, 'inner context correct'); +}); diff --git a/packages/ember-views/tests/views/view/template_test.js b/packages/ember-views/tests/views/view/template_test.js index 842a21f38fb..38672753797 100644 --- a/packages/ember-views/tests/views/view/template_test.js +++ b/packages/ember-views/tests/views/view/template_test.js @@ -1,7 +1,5 @@ var set = Ember.set, get = Ember.get; -var VIEW_PRESERVES_CONTEXT = Ember.VIEW_PRESERVES_CONTEXT; - module("Ember.View - Template Functionality"); test("should call the function of the associated template", function() { @@ -111,7 +109,7 @@ test("should render an empty element if no template is specified", function() { }); test("should provide a controller to the template if a controller is specified on the view", function() { - expect(VIEW_PRESERVES_CONTEXT ? 7 : 5); + expect(7); var Controller1 = Ember.Object.extend({ toString: function() { return "Controller1"; } @@ -194,9 +192,6 @@ test("should provide a controller to the template if a controller is specified o strictEqual(optionsDataKeywordsControllerForView, controller1, "passes the original controller in the data"); strictEqual(optionsDataKeywordsControllerForChildView, controller1, "passes the controller in the data to child views"); - - if (VIEW_PRESERVES_CONTEXT) { - strictEqual(contextForView, controller2, "passes the controller in as the main context of the parent view"); - strictEqual(contextForControllerlessView, controller1, "passes the controller in as the main context of the child view"); - } + strictEqual(contextForView, controller2, "passes the controller in as the main context of the parent view"); + strictEqual(contextForControllerlessView, controller1, "passes the controller in as the main context of the child view"); }); diff --git a/tests/index.html b/tests/index.html index 228c78e8242..d8dce097b85 100644 --- a/tests/index.html +++ b/tests/index.html @@ -76,12 +76,6 @@ var noCpDefaultCacheable = QUnit.urlParams.nocpdefaultcacheable; ENV['CP_DEFAULT_CACHEABLE'] = !noCpDefaultCacheable; - // Handle preserving context - QUnit.config.urlConfig.push('noviewpreservescontext'); - - var noViewPreservesContext = QUnit.urlParams.noviewpreservescontext; - ENV['VIEW_PRESERVES_CONTEXT'] = !noViewPreservesContext; - // Don't worry about jQuery version ENV['FORCE_JQUERY'] = true;