From 01117038da4a62046d92ac38742004fed4f80c0f Mon Sep 17 00:00:00 2001 From: Stuart Knightley Date: Mon, 2 Sep 2013 21:22:52 -0700 Subject: [PATCH 1/2] Add failing spec for sorted block with missing sorted property --- spec/observe-sorted-spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/observe-sorted-spec.js b/spec/observe-sorted-spec.js index b07dda8..a860406 100644 --- a/spec/observe-sorted-spec.js +++ b/spec/observe-sorted-spec.js @@ -26,5 +26,29 @@ describe("sorted block observer", function () { expect(object.sorted).toEqual([array[2], array[0], array[1]]); }); + it("sorts objects missing the sorted property", function () { + + var array = [ + {key: 0}, + {key: 1}, + {key: 2} + ]; + + var object = Bindings.defineBindings({ + array: array + }, { + sorted: {"<-": "array.sorted{value}"} + }); + + expect(object.sorted.length).toEqual(3); + + array[2].value = 'a'; + array[1].value = 'b'; + array[0].value = 'c'; + + expect(object.sorted.length).toEqual(3); + expect(object.sorted).toEqual([array[2], array[1], array[0]]); + }); + }); From 298f6f72944993575228e54556ae8f1a0ad0ce4a Mon Sep 17 00:00:00 2001 From: Stuart Knightley Date: Mon, 2 Sep 2013 21:35:06 -0700 Subject: [PATCH 2/2] Add failing spec for sorted block with equal sorted values --- spec/observe-sorted-spec.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/observe-sorted-spec.js b/spec/observe-sorted-spec.js index a860406..7814c24 100644 --- a/spec/observe-sorted-spec.js +++ b/spec/observe-sorted-spec.js @@ -50,5 +50,25 @@ describe("sorted block observer", function () { expect(object.sorted).toEqual([array[2], array[1], array[0]]); }); + it("sorts objects with equal values", function () { + + var array = [ + {key: 0, value: "b"}, + {key: 1, value: "b"}, + {key: 2, value: "b"} + ]; + + var object = Bindings.defineBindings({ + array: array + }, { + sorted: {"<-": "array.sorted{value}"} + }); + + array[2].value = 'a'; + array[0].value = 'c'; + + expect(object.sorted).toEqual([array[2], array[1], array[0]]); + }); + });