backbone-nested-attributes 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWFlNThjYTFiNzFjZjkwYWU3MGYyZjI3MWJkNmMyZjlhNzY0OTY4ZA==
4
+ ZDEyYjJmMDFiN2I5ZDJhM2MwN2E2YjBjOGNkNjk2MTBlNjU3ZGYyNw==
5
5
  data.tar.gz: !binary |-
6
- MDYyODc4OTUxN2RjNzk4NmIyNTAzZDBmZWVhZTYwODk0MTI4NTFmYg==
7
- !binary "U0hBNTEy":
6
+ YWU2ZDI4ZTBmODNkNDg3OGMxMDUzMmExYWFlZmQ2Zjc2N2QzNzkzYQ==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTBhMGM4ODYxMTRmY2ExODJkN2IzZDMxYmZlZDU1MTkwYmIwMzc4YmU2NjNk
10
- MWYwMWY2YmFhZWQ1ZTJkY2Q4MDY3NTUwMDNhNTQzZGZjNWZiZDFmMzAyYjg1
11
- MWZmY2Q5ZDg5MTIyYzYyZWM0OWNlODVlZTI2MzdjMTlhMmY4Y2E=
9
+ OTJlYmY0N2YyNzk3YjQ1MDcwMWQ1MTUwNjBiYjFiZGI1MzRjZjAzM2ZiYWZk
10
+ MTNmZTU5YzU1MjAwMDI5ZjhhZTE5ZWU2ODk2MjZlMzkyYTg2MmU0MzM3YzNh
11
+ NDljMTRiYmQ4YTZjZTJjMmNjZGI5MGI4MzFiN2EwZmE4MzUzNTM=
12
12
  data.tar.gz: !binary |-
13
- ZjI5YTRkNDcyZTBhYzMyYmNkZjlhZGVjZTY4YjlkYTIyOWYyNjI0ZTdjYjQ3
14
- NTZlMWNiMDIwZGQ1NmVhYjdhYjRiMzJmZmY1NjE0NDU5OGU4NDBkYWYzOGMx
15
- NDAyYTU5ZDc0MDM5YzgzNmUwMmYwYmRhOTdmY2Q2NzhiMTgyMDM=
13
+ NzRmNjQ0YmZkNGM2MzUxNjUyYzgwOThjNmNiMDMyMzhjZjdlZWJmYThmMTI5
14
+ ZjZhNDQzNDhkMmU0ZDE5MDBlZjBlMzYzM2VlMmViNGUzZTQwYTQ1YmNiMjkw
15
+ MzdmNTBmOTg2ZDI3YWRkOGUxZDkzMWRlOWQ5Yzc2ODM0MjNiNGI=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- backbone-nested-attributes (0.4.4)
4
+ backbone-nested-attributes (0.5.0)
5
5
  rails (>= 3.2.8)
6
6
 
7
7
  GEM
@@ -153,11 +153,18 @@
153
153
 
154
154
  collection.deletedModels = new Backbone.Collection
155
155
  collection.deletedModels.model = collection.model
156
+ collection.on('add', nestedModelAdded)
156
157
  collection.on('remove', nestedModelRemoved)
157
158
 
158
159
  return collection
159
160
  }
160
161
 
162
+ function nestedModelAdded(model, collection) {
163
+ if (model.get('_destroy')) {
164
+ collection.remove(model)
165
+ }
166
+ }
167
+
161
168
  function nestedModelRemoved(model, collection) {
162
169
  if (!model.isNew()) {
163
170
  model.set({ _destroy: true })
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2013-2014 Vicente Mundim
3
3
  *
4
- * Version: 0.4.4
4
+ * Version: 0.5.0
5
5
  *
6
6
  * MIT License
7
7
  *
@@ -186,11 +186,18 @@
186
186
 
187
187
  collection.deletedModels = new Backbone.Collection
188
188
  collection.deletedModels.model = collection.model
189
+ collection.on('add', nestedModelAdded)
189
190
  collection.on('remove', nestedModelRemoved)
190
191
 
191
192
  return collection
192
193
  }
193
194
 
195
+ function nestedModelAdded(model, collection) {
196
+ if (model.get('_destroy')) {
197
+ collection.remove(model)
198
+ }
199
+ }
200
+
194
201
  function nestedModelRemoved(model, collection) {
195
202
  if (!model.isNew()) {
196
203
  model.set({ _destroy: true })
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backbone-nested-attributes",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "main": "backbone-nested-attributes.js",
5
5
  "description": "Add Rails-like nested attributes support for Backbone.Model.",
6
6
  "license": "MIT",
@@ -1,5 +1,5 @@
1
1
  module Backbone
2
2
  module NestedAttributes
3
- VERSION = "0.4.4"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -312,6 +312,22 @@ describe("Backbone.NestedAttributesModel", function() {
312
312
  })
313
313
  })
314
314
 
315
+ describe('passing a model in a collection with { _destroy: true }', function () {
316
+ beforeEach(function() {
317
+ model = new Post({ title: 'Some Title', comments: [{ body: 'some content' }, { id: '123', body: 'other content', _destroy: true }] })
318
+ })
319
+
320
+ it('do not add the model with { _destroy: true } to the relation collection', function () {
321
+ expect(model.get('comments').length).toBe(1)
322
+ expect(model.get('comments').at(0).get('body')).toBe('some content')
323
+ })
324
+
325
+ it('adds them to the deletedModels collection inside the relation collection', function () {
326
+ expect(model.get('comments').deletedModels.length).toBe(1)
327
+ expect(model.get('comments').deletedModels.at(0).get('body')).toBe('other content')
328
+ })
329
+ })
330
+
315
331
  describe("passing a deleted_<collection> attribute", function() {
316
332
  var comments
317
333
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backbone-nested-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vicente Mundim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.0.6
109
+ rubygems_version: 2.1.11
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Add nested attributes to your Backbone models