Sha256: 88204ade6f7a76235b170e3467e7ae454d23e5d4822941a1cd64068548239ed0

Contents?: true

Size: 1.87 KB

Versions: 37

Compression:

Stored size: 1.87 KB

Contents

// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2010 Apple Inc. and contributors.
// License:   Licensed under MIT license (see license.js)
// ==========================================================================
/*globals module ok equals same test MyApp */

(function() {
  
  var store, Person, Place, Male, Female, home, colin, maggie;
  
  module("Polymorphic SC.Record - toOne tests", {
    setup: function() {
      SC.RunLoop.begin();
      store = SC.Store.create();

      Person = SC.Record.extend({
        name: SC.Record.attr(String)
      });
      Person.isPolymorphic = YES;

      Place = SC.Record.extend({
        where: SC.Record.attr(String),
        person: SC.Record.toOne(Person, {inverse: 'place'})
      });

      Male = Person.extend({
        isMale: YES
      });

      Female = Person.extend({
        isFemale: YES
      });

      home = store.createRecord(Place, {
        guid: '0',
        where: 'Canada',
        person: '1'
      });

      colin = store.createRecord(Male, {
        guid: '1',
        name: 'Colin'
      });

      maggie = store.createRecord(Female, {
        guid: '2',
        name: 'Maggie'
      });
    },
    teardown: function() {
      store = Person = Place = Male = Female = home = colin = maggie = null;
      SC.RunLoop.end();
    }
  });

  test("toOne relationship returns record of correct type", function() {
    equals(home.get('person'), colin, "Correct record is returned for polymorphic relationship");
    ok(SC.kindOf(home.get('person'), Male), "Correct record type is returned for polymorphic relationship");
  });

  test("setting toOne relationship works", function() {
    home.set('person', maggie);
    ok(SC.kindOf(home.get('person'), Female), "Changing toOne to record of different type works");
  });

})();

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
sproutcore-1.10.3.1 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.10.2 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.10.1 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.10.0 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.10.0.rc.3 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.10.0.rc.2 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.10.0.rc.1 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.9.2 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.9.1 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.9.0 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.8.2.1 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.8.1 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.8.0 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.7.1.beta-java lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.7.1.beta lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.6.0.1-java lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.6.0.1 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.6.0.1-x86-mingw32 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.6.0 lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js
sproutcore-1.6.0-java lib/frameworks/sproutcore/frameworks/experimental/frameworks/polymorphism/tests/models/polymorphism/single.js