2 * Copyright 2010-2013 Ben Birch
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this software except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 describe("app.data.Model", function() {
18 var Model = window.app.data.Model;
20 it("test setting model does a shallow copy", function() {
22 var array = [ 1, 2, 3 ];
30 expect( m.get("foo") ).toBe("bar");
31 expect( m.get("array").length ).toBe( 3 );
32 expect( m.get("array")[1] ).toBe( 2 );
33 expect( m.get("array") ).toBe( array );
34 expect( m.get("test") ).toBe( test );
37 it("should replace model with shallow copy when put with no path", function() {
38 var m = new Model({ foo: "bar" });
39 m.set({ bar: "blat" });
40 expect( m.get("foo")).toBe( undefined );
41 expect( m.get("bar")).toBe("blat");
44 it("test getting values from deep in a model", function() {
57 expect( m.get("foo.bar.baz.quix") ).toBe( "abcdefg" );
60 it("test setting non-existant values creates new values", function() {
68 m.set("foo.bar", "123" );
69 m.set("foo.baz", "456" );
70 expect( m.get("foo.bar") ).toBe( "123" );
71 expect( m.get("foo.baz") ).toBe( "456" );
74 it("test setting values deep in a model", function() {
82 m.set("foo.bar", "123" );
83 m.set("foo.baz", "456" );
84 m.set("foo.something.else.is.here", "xyz" );
85 expect( m.get("foo.something.else.is").here ).toBe( "xyz" );
86 expect( m.get("foo.something.else.is.here") ).toBe( "xyz" );