volt 0.6.5 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/Readme.md +47 -40
  3. data/VERSION +1 -1
  4. data/app/volt/controllers/notices_controller.rb +3 -3
  5. data/app/volt/tasks/live_query/data_store.rb +2 -2
  6. data/app/volt/tasks/live_query/live_query.rb +20 -20
  7. data/app/volt/tasks/live_query/live_query_pool.rb +6 -6
  8. data/app/volt/tasks/live_query/query_tracker.rb +15 -15
  9. data/app/volt/tasks/query_tasks.rb +13 -13
  10. data/app/volt/tasks/store_tasks.rb +7 -7
  11. data/app/volt/views/notices/index.html +17 -18
  12. data/lib/volt/assets/test.rb +2 -2
  13. data/lib/volt/benchmark/benchmark.rb +25 -23
  14. data/lib/volt/cli/asset_compile.rb +11 -0
  15. data/lib/volt/cli/new_gem.rb +16 -16
  16. data/lib/volt/cli.rb +14 -12
  17. data/lib/volt/console.rb +5 -6
  18. data/lib/volt/controllers/model_controller.rb +18 -18
  19. data/lib/volt/extra_core/array.rb +4 -4
  20. data/lib/volt/extra_core/hash.rb +3 -3
  21. data/lib/volt/extra_core/object.rb +6 -6
  22. data/lib/volt/extra_core/string.rb +6 -6
  23. data/lib/volt/extra_core/symbol.rb +5 -5
  24. data/lib/volt/extra_core/time.rb +4 -4
  25. data/lib/volt/extra_core/true_false.rb +6 -6
  26. data/lib/volt/extra_core/try.rb +9 -9
  27. data/lib/volt/models/array_model.rb +26 -26
  28. data/lib/volt/models/model.rb +35 -35
  29. data/lib/volt/models/model_hash_behaviour.rb +15 -15
  30. data/lib/volt/models/model_helpers.rb +8 -8
  31. data/lib/volt/models/model_wrapper.rb +6 -6
  32. data/lib/volt/models/persistors/array_store.rb +36 -36
  33. data/lib/volt/models/persistors/base.rb +6 -6
  34. data/lib/volt/models/persistors/flash.rb +5 -5
  35. data/lib/volt/models/persistors/model_identity_map.rb +2 -2
  36. data/lib/volt/models/persistors/model_store.rb +22 -22
  37. data/lib/volt/models/persistors/params.rb +3 -3
  38. data/lib/volt/models/persistors/query/query_listener.rb +14 -14
  39. data/lib/volt/models/persistors/query/query_listener_pool.rb +2 -2
  40. data/lib/volt/models/persistors/store.rb +8 -8
  41. data/lib/volt/models/persistors/store_factory.rb +2 -2
  42. data/lib/volt/models/url.rb +37 -37
  43. data/lib/volt/page/bindings/attribute_binding.rb +14 -14
  44. data/lib/volt/page/bindings/base_binding.rb +9 -9
  45. data/lib/volt/page/bindings/component_binding.rb +7 -7
  46. data/lib/volt/page/bindings/content_binding.rb +3 -3
  47. data/lib/volt/page/bindings/each_binding.rb +13 -13
  48. data/lib/volt/page/bindings/event_binding.rb +4 -4
  49. data/lib/volt/page/bindings/if_binding.rb +12 -12
  50. data/lib/volt/page/bindings/template_binding.rb +30 -30
  51. data/lib/volt/page/channel.rb +19 -19
  52. data/lib/volt/page/channel_stub.rb +6 -6
  53. data/lib/volt/page/document.rb +2 -2
  54. data/lib/volt/page/document_events.rb +4 -4
  55. data/lib/volt/page/draw_cycle.rb +3 -3
  56. data/lib/volt/page/memory_test.rb +6 -6
  57. data/lib/volt/page/page.rb +19 -19
  58. data/lib/volt/page/reactive_template.rb +9 -9
  59. data/lib/volt/page/sub_context.rb +5 -5
  60. data/lib/volt/page/targets/attribute_section.rb +9 -9
  61. data/lib/volt/page/targets/attribute_target.rb +3 -3
  62. data/lib/volt/page/targets/base_section.rb +2 -2
  63. data/lib/volt/page/targets/binding_document/component_node.rb +23 -23
  64. data/lib/volt/page/targets/binding_document/html_node.rb +2 -2
  65. data/lib/volt/page/targets/dom_section.rb +40 -38
  66. data/lib/volt/page/targets/dom_target.rb +2 -2
  67. data/lib/volt/page/tasks.rb +12 -12
  68. data/lib/volt/page/template_renderer.rb +4 -4
  69. data/lib/volt/page/url_tracker.rb +6 -6
  70. data/lib/volt/reactive/array_extensions.rb +2 -2
  71. data/lib/volt/reactive/destructive_methods.rb +5 -5
  72. data/lib/volt/reactive/event_chain.rb +25 -25
  73. data/lib/volt/reactive/events.rb +33 -33
  74. data/lib/volt/reactive/object_tracker.rb +21 -21
  75. data/lib/volt/reactive/object_tracking.rb +2 -2
  76. data/lib/volt/reactive/reactive_array.rb +57 -57
  77. data/lib/volt/reactive/reactive_tags.rb +16 -16
  78. data/lib/volt/reactive/reactive_value.rb +72 -72
  79. data/lib/volt/reactive/string_extensions.rb +3 -3
  80. data/lib/volt/router/routes.rb +22 -23
  81. data/lib/volt/server/component_handler.rb +5 -5
  82. data/lib/volt/server/component_templates.rb +14 -11
  83. data/lib/volt/server/html_parser/attribute_scope.rb +116 -0
  84. data/lib/volt/server/html_parser/each_scope.rb +18 -0
  85. data/lib/volt/server/html_parser/if_view_scope.rb +71 -0
  86. data/lib/volt/server/html_parser/sandlebars_parser.rb +219 -0
  87. data/lib/volt/server/html_parser/textarea_scope.rb +31 -0
  88. data/lib/volt/server/html_parser/view_handler.rb +82 -0
  89. data/lib/volt/server/html_parser/view_parser.rb +23 -0
  90. data/lib/volt/server/html_parser/view_scope.rb +145 -0
  91. data/lib/volt/server/rack/asset_files.rb +17 -17
  92. data/lib/volt/server/rack/component_paths.rb +18 -18
  93. data/lib/volt/server/rack/index_files.rb +8 -8
  94. data/lib/volt/server/rack/opal_files.rb +11 -11
  95. data/lib/volt/server/socket_connection_handler.rb +13 -13
  96. data/lib/volt/server/socket_connection_handler_stub.rb +2 -2
  97. data/lib/volt/server.rb +18 -18
  98. data/lib/volt/tasks/dispatcher.rb +5 -5
  99. data/lib/volt/utils/ejson.rb +2 -2
  100. data/lib/volt/utils/generic_counting_pool.rb +8 -8
  101. data/lib/volt/utils/generic_pool.rb +16 -16
  102. data/lib/volt/volt/environment.rb +4 -4
  103. data/lib/volt.rb +6 -6
  104. data/spec/integration/test_integration_spec.rb +2 -2
  105. data/spec/models/event_chain_spec.rb +38 -38
  106. data/spec/models/model_spec.rb +128 -128
  107. data/spec/models/old_model_spec.rb +17 -17
  108. data/spec/models/persistors/params_spec.rb +3 -3
  109. data/spec/models/persistors/store_spec.rb +7 -7
  110. data/spec/models/reactive_array_spec.rb +82 -82
  111. data/spec/models/reactive_generator_spec.rb +11 -11
  112. data/spec/models/reactive_tags_spec.rb +6 -6
  113. data/spec/models/reactive_value_spec.rb +70 -70
  114. data/spec/models/store_spec.rb +4 -4
  115. data/spec/models/string_extensions_spec.rb +13 -13
  116. data/spec/page/bindings/content_binding_spec.rb +6 -6
  117. data/spec/page/sub_context_spec.rb +1 -1
  118. data/spec/router/routes_spec.rb +3 -3
  119. data/spec/server/html_parser/sample_page.html +595 -0
  120. data/spec/server/html_parser/sandlebars_parser_spec.rb +192 -0
  121. data/spec/server/html_parser/view_parser_spec.rb +286 -0
  122. data/spec/server/rack/asset_files_spec.rb +6 -6
  123. data/spec/server/rack/component_paths_spec.rb +5 -5
  124. data/spec/spec_helper.rb +4 -5
  125. data/spec/store/mongo_spec.rb +3 -3
  126. data/spec/tasks/live_query_spec.rb +6 -6
  127. data/spec/tasks/query_tasks.rb +4 -4
  128. data/spec/tasks/query_tracker_spec.rb +20 -20
  129. data/spec/templates/targets/binding_document/component_node_spec.rb +4 -4
  130. data/spec/templates/template_binding_spec.rb +28 -28
  131. data/spec/utils/generic_counting_pool_spec.rb +5 -5
  132. data/spec/utils/generic_pool_spec.rb +14 -14
  133. data/templates/newgem/app/newgem/views/index/index.html +1 -2
  134. data/templates/project/app/home/config/dependencies.rb +1 -1
  135. data/templates/project/app/home/controllers/index_controller.rb +1 -1
  136. data/templates/project/app/home/views/index/about.html +4 -6
  137. data/templates/project/app/home/views/index/home.html +4 -5
  138. data/templates/project/app/home/views/index/index.html +8 -9
  139. data/templates/project/spec/spec_helper.rb +1 -1
  140. metadata +17 -8
  141. data/lib/volt/server/binding_setup.rb +0 -2
  142. data/lib/volt/server/if_binding_setup.rb +0 -31
  143. data/lib/volt/server/scope.rb +0 -43
  144. data/lib/volt/server/template_parser.rb +0 -453
  145. data/spec/server/template_parser_spec.rb +0 -50
@@ -2,379 +2,379 @@ require 'volt/models'
2
2
 
3
3
 
4
4
  class TestItem < Model
5
-
5
+
6
6
  end
7
7
 
8
8
  describe Model do
9
-
9
+
10
10
  it "should allow _ methods to be used to store values without predefining them" do
11
11
  a = Model.new
12
12
  a._stash = 'yes'
13
-
13
+
14
14
  expect(a._stash).to eq('yes')
15
15
  end
16
-
16
+
17
17
  it "should update other values off the same model" do
18
18
  a = ReactiveValue.new(Model.new)
19
19
  count = 0
20
20
  a._name.on('changed') { count += 1 }
21
21
  expect(count).to eq(0)
22
-
22
+
23
23
  a._name = 'Bob'
24
24
  expect(count).to eq(1)
25
25
  end
26
-
26
+
27
27
  it "should say unregistered attributes are nil" do
28
28
  a = ReactiveValue.new(Model.new)
29
29
  b = a._missing == nil
30
30
  expect(b.cur).to eq(true)
31
31
  end
32
-
32
+
33
33
  it "should negate nil and false correctly" do
34
34
  a = ReactiveValue.new(Model.new)
35
35
  expect((!a._missing).cur).to eq(true)
36
-
36
+
37
37
  a._mis1 = nil
38
38
  a._false1 = false
39
-
39
+
40
40
  expect((!a._mis1).cur).to eq(true)
41
41
  expect((!a._false1).cur).to eq(true)
42
42
  end
43
-
43
+
44
44
  it "should return a nil model for an underscore value that doesn't exist" do
45
45
  a = Model.new
46
46
  expect(a._something.cur.attributes).to eq(nil)
47
47
  end
48
-
48
+
49
49
  it "should let you bind before something is defined" do
50
50
  a = ReactiveValue.new(Model.new)
51
-
51
+
52
52
  b = a._one + 5
53
53
  expect(b.cur.class).to eq(NoMethodError)
54
-
54
+
55
55
  count = 0
56
56
  b.on('changed') { count += 1 }
57
57
  expect(count).to eq(0)
58
-
58
+
59
59
  a._one = 1
60
60
  expect(count).to eq(1)
61
61
  expect(b.cur).to eq(6)
62
62
  end
63
-
63
+
64
64
  it "should let you access an array element before its defined" do
65
65
  # TODO: ...
66
66
  end
67
-
67
+
68
68
  it "should trigger changed once when a new value is assigned." do
69
69
  a = ReactiveValue.new(Model.new)
70
-
70
+
71
71
  count = 0
72
72
  a._blue.on('changed') { count += 1 }
73
-
73
+
74
74
  a._blue = 'one'
75
75
  expect(count).to eq(1)
76
76
  a._blue = 'two'
77
77
  expect(count).to eq(2)
78
78
  end
79
-
79
+
80
80
  it "should not call changed on other attributes" do
81
81
  a = ReactiveValue.new(Model.new)
82
-
82
+
83
83
  count = 0
84
84
  a._blue.on('changed') { count += 1 }
85
85
  expect(count).to eq(0)
86
-
86
+
87
87
  a._green = 'one'
88
88
  expect(count).to eq(0)
89
-
89
+
90
90
  a._blue = 'two'
91
91
  expect(count).to eq(1)
92
-
92
+
93
93
  end
94
-
94
+
95
95
  it "should call change through arguments" do
96
96
  a = ReactiveValue.new(Model.new)
97
97
  a._one = 1
98
98
  a._two = 2
99
-
99
+
100
100
  c = a._one + a._two
101
-
101
+
102
102
  count = 0
103
103
  c.on('changed') { count += 1}
104
104
  expect(count).to eq(0)
105
-
105
+
106
106
  a._two = 5
107
107
  expect(count).to eq(1)
108
-
109
- expect(c.cur).to eq(6)
108
+
109
+ expect(c.cur).to eq(6)
110
110
  end
111
-
111
+
112
112
  it "should store reactive values in arrays and trigger updates when those values change" do
113
113
  a = ReactiveValue.new(Model.new)
114
114
  b = ReactiveValue.new('blue')
115
115
  a._one = 1
116
116
  a._items << 0
117
-
117
+
118
118
  count_1 = 0
119
119
  a._items[1].on('changed') { count_1 += 1 }
120
120
  expect(count_1).to eq(0)
121
-
121
+
122
122
  a._items << b
123
123
  expect(count_1).to eq(1)
124
-
124
+
125
125
  b.cur = 'update'
126
126
  expect(count_1).to eq(2)
127
-
127
+
128
128
  count_2 = 0
129
129
  a._items[2].on('changed') { count_2 += 1 }
130
130
  expect(count_2).to eq(0)
131
-
131
+
132
132
  a._items << a._one
133
133
  expect(count_2).to eq(1)
134
-
134
+
135
135
  a._one = 'updated'
136
136
  expect(count_1).to eq(2)
137
137
  expect(count_2).to eq(2)
138
138
  end
139
-
139
+
140
140
  it "should let you register events before it expands" do
141
141
  a = ReactiveValue.new(Model.new)
142
142
  count = 0
143
143
  a._something.on('changed') { count += 1 }
144
144
  expect(count).to eq(0)
145
-
145
+
146
146
  a._something = 20
147
147
  expect(count).to eq(1)
148
148
  end
149
-
149
+
150
150
  it "should trigger changed through concat" do
151
151
  model = ReactiveValue.new(Model.new)
152
-
152
+
153
153
  concat = model._one + model._two
154
-
154
+
155
155
  count = 0
156
156
  concat.on('changed') { count += 1 }
157
157
  expect(count).to eq(0)
158
-
158
+
159
159
  model._one = 'one'
160
160
  expect(count).to eq(1)
161
-
161
+
162
162
  model._two = 'two'
163
163
  expect(count).to eq(2)
164
-
164
+
165
165
  expect(concat.cur).to eq('onetwo')
166
166
  end
167
-
167
+
168
168
  it "should allow a reactive value to be assigned as a value in a model" do
169
169
  model = ReactiveValue.new(Model.new)
170
-
170
+
171
171
  model._items << {_name: 'One'}
172
172
  model._items << {_name: 'Two'}
173
-
173
+
174
174
  current = model._items[model._index]
175
-
175
+
176
176
  model._current_item = current
177
177
  end
178
-
178
+
179
179
  it "should trigger changed for any indicies after a deleted index" do
180
180
  model = ReactiveValue.new(Model.new)
181
-
181
+
182
182
  model._items << {_name: 'One'}
183
183
  model._items << {_name: 'Two'}
184
184
  model._items << {_name: 'Three'}
185
-
185
+
186
186
  count = 0
187
187
  model._items[2].on('changed') { count += 1 }
188
188
  expect(count).to eq(0)
189
-
189
+
190
190
  model._items.delete_at(1)
191
191
  expect(count).to eq(1)
192
192
  end
193
-
193
+
194
194
  it "should change the size and length when an item gets added" do
195
195
  model = ReactiveValue.new(Model.new)
196
-
196
+
197
197
  model._items << {_name: 'One'}
198
198
  size = model._items.size
199
199
  length = model._items.length
200
-
200
+
201
201
  count_size = 0
202
202
  count_length = 0
203
203
  size.on('changed') { count_size += 1 }
204
204
  length.on('changed') { count_length += 1 }
205
205
  expect(count_size).to eq(0)
206
206
  expect(count_length).to eq(0)
207
-
207
+
208
208
  model._items << {_name: 'Two'}
209
209
  expect(count_size).to eq(1)
210
210
  expect(count_length).to eq(1)
211
211
  end
212
-
212
+
213
213
  it "should add doubly nested arrays" do
214
214
  model = ReactiveValue.new(Model.new)
215
-
215
+
216
216
  model._items << {_name: 'Cool', _lists: []}
217
217
  model._items[0]._lists << {_name: 'worked'}
218
218
  expect(model._items[0]._lists[0]._name.cur).to eq('worked')
219
219
  end
220
-
220
+
221
221
  it "should make pushed subarrays into ArrayModels" do
222
222
  model = ReactiveValue.new(Model.new)
223
-
223
+
224
224
  model._items << {_name: 'Test', _lists: []}
225
225
  expect(model._items[0]._lists.cur.class).to eq(ArrayModel)
226
226
  end
227
-
227
+
228
228
  it "should make assigned subarrays into ArrayModels" do
229
229
  model = ReactiveValue.new(Model.new)
230
-
230
+
231
231
  model._item._name = 'Test'
232
232
  model._item._lists = []
233
- expect(model._item._lists.cur.class).to eq(ArrayModel)
233
+ expect(model._item._lists.cur.class).to eq(ArrayModel)
234
234
  end
235
-
235
+
236
236
  it "should call changed when a the reference to a submodel is assigned to another value" do
237
237
  a = ReactiveValue.new(Model.new)
238
-
238
+
239
239
  count = 0
240
240
  a._blue._green.on('changed') { count += 1 }
241
241
  expect(count).to eq(0)
242
-
242
+
243
243
  a._blue._green = 5
244
244
  expect(count).to eq(1)
245
-
245
+
246
246
  a._blue = 22
247
247
  expect(count).to eq(2)
248
248
  end
249
-
249
+
250
250
  it "should trigger changed when a value is deleted" do
251
251
  a = ReactiveValue.new(Model.new)
252
-
252
+
253
253
  count = 0
254
254
  a._blue.on('changed') { count += 1 }
255
255
  expect(count).to eq(0)
256
-
256
+
257
257
  a._blue = 1
258
258
  expect(count).to eq(1)
259
-
259
+
260
260
  a.delete(:_blue)
261
261
  expect(count).to eq(2)
262
262
  end
263
-
263
+
264
264
  it "should not trigger a change if the new value is exactly the same" do
265
-
265
+
266
266
  end
267
-
267
+
268
268
  it "should let you append nested hashes" do
269
269
  a = Model.new
270
270
  # TODO: Fails
271
271
  # a._items << {_name: {_text: 'Name'}}
272
272
  end
273
-
273
+
274
274
  it "should work" do
275
275
  store = ReactiveValue.new(Model.new)
276
276
  # params = ReactiveValue.new(Params.new)
277
277
  index = ReactiveValue.new(0)
278
-
278
+
279
279
  a = store._todo_lists
280
280
  store._current_todo = a#[index]
281
-
281
+
282
282
  added_count = 0
283
283
  changed_count = 0
284
284
  # store._todo_lists.on('added') { added_count += 1 }
285
285
  store._current_todo.on('changed') { changed_count += 1 }
286
286
  # expect(added_count).to eq(0)
287
287
  expect(changed_count).to eq(0)
288
-
288
+
289
289
  a.cur = 1000
290
290
  # store._todo_lists << {_name: 'List 1', _todos: []}
291
-
292
-
291
+
292
+
293
293
  # store._todo_lists[0]._todos << {_name: 'Todo 1'}
294
-
294
+
295
295
  # expect(added_count).to eq(1)
296
296
  # expect(changed_count).to eq(1)
297
297
  end
298
-
298
+
299
299
  it "should handle a basic todo list with no setup" do
300
300
  store = ReactiveValue.new(Model.new)
301
301
  params = ReactiveValue.new(Model.new({}, persistor: Persistors::Params))
302
-
302
+
303
303
  a = store._todo_lists
304
304
  store._current_todo = store._todo_lists[params._index.or(0).to_i]
305
-
305
+
306
306
  added_count = 0
307
307
  changed_count = 0
308
308
  store._todo_lists.on('added') { added_count += 1 }
309
309
  store._current_todo.on('changed') { changed_count += 1 }
310
310
  expect(added_count).to eq(0)
311
311
  expect(changed_count).to eq(0)
312
-
312
+
313
313
  store._todo_lists << {_name: 'List 1', _todos: []}
314
314
  store._todo_lists[0]._todos << {_name: 'Todo 1'}
315
-
315
+
316
316
  expect(added_count).to eq(1)
317
317
  # expect(changed_count).to eq(1)
318
318
  end
319
-
319
+
320
320
  it "should not call added too many times" do
321
321
  a = ReactiveValue.new(Model.new)
322
322
  a._list << 1
323
323
  ac = a._current_list = a._list[0]
324
-
324
+
325
325
  count = 0
326
326
  passed_count = 0
327
327
  a._list.on('added') { count += 1 }
328
328
  a._current_list.on('added') { passed_count += 1 }
329
329
  expect(count).to eq(0)
330
330
  expect(passed_count).to eq(0)
331
-
331
+
332
332
  a._list << 2
333
333
  expect(count).to eq(1)
334
334
  expect(passed_count).to eq(0)
335
335
  end
336
-
336
+
337
337
  it "should propigate to different branches" do
338
338
  a = ReactiveValue.new(Model.new)
339
339
  count = 0
340
340
  # a._new_item = {}
341
341
  a._new_item._name.on('changed') { count += 1 }
342
342
  expect(count).to eq(0)
343
-
343
+
344
344
  a._new_item._name = 'Testing'
345
345
  # expect(count).to eq(1)
346
346
  end
347
-
347
+
348
348
  describe "paths" do
349
349
  it "should store the path" do
350
350
  a = Model.new
351
351
  expect(a._test.path).to eq([:_test])
352
352
  a._test = {_name: 'Yes'}
353
353
  expect(a._test.path).to eq([:_test])
354
-
354
+
355
355
  a._items << {_name: 'Yes'}
356
356
  expect(a._items.path).to eq([:_items])
357
357
  expect(a._items[0].path).to eq([:_items, :[]])
358
358
  end
359
-
359
+
360
360
  it "should store the paths when assigned" do
361
361
  a = Model.new
362
-
362
+
363
363
  a._items = [{_name: 'Cool'}]
364
-
364
+
365
365
  expect(a._items.path).to eq([:_items])
366
366
  expect(a._items[0].path).to eq([:_items, :[]])
367
367
  end
368
-
368
+
369
369
  it "should handle nested paths" do
370
370
  a = Model.new
371
-
371
+
372
372
  a._items << {_name: 'Cool', _lists: [{_name: 'One'}, {_name: 'Two'}]}
373
-
373
+
374
374
  expect(a._items[0]._lists.path).to eq([:_items, :[], :_lists])
375
375
  expect(a._items[0]._lists[1].path).to eq([:_items, :[], :_lists, :[]])
376
376
  end
377
-
377
+
378
378
  it "should trigger added when added" do
379
379
  a = ReactiveValue.new(Model.new)
380
380
  count = 0
@@ -382,31 +382,31 @@ describe Model do
382
382
 
383
383
  b.on('added') { count += 1 }
384
384
  expect(count).to eq(0)
385
-
385
+
386
386
  c = b.cur
387
387
  c << {_name: 'one'}
388
388
 
389
389
  # TODO: Without fetching this again, this fails.
390
390
  c = b.cur
391
-
391
+
392
392
  c << {_name: 'two'}
393
-
393
+
394
394
  expect(count).to eq(2)
395
395
  end
396
396
  end
397
-
397
+
398
398
  it "should trigger on false assign" do
399
399
  a = ReactiveValue.new(Model.new)
400
-
400
+
401
401
  count1 = 0
402
402
  count2 = 0
403
-
403
+
404
404
  b = a._complete
405
405
  c = a._complete
406
406
  b.on('changed') { count1 += 1 }
407
407
  c.on('changed') { count2 += 1 }
408
408
  expect(count1).to eq(0)
409
-
409
+
410
410
  b._complete = true
411
411
  expect(count1).to eq(1)
412
412
  expect(count2).to eq(1)
@@ -414,83 +414,83 @@ describe Model do
414
414
  b._complete = false
415
415
  expect(count1).to eq(2)
416
416
  expect(count2).to eq(2)
417
-
417
+
418
418
  end
419
-
419
+
420
420
  it "should delete from an ArrayModel" do
421
421
  array = ArrayModel.new([])
422
-
422
+
423
423
  array << {_name: 'One'}
424
424
  array << {_name: 'Two'}
425
425
  array << {_name: 'Three'}
426
-
426
+
427
427
  expect(array.size).to eq(3)
428
428
 
429
429
  expect(array.index(array[0])).to eq(0)
430
-
430
+
431
431
  array.delete(array[0])
432
432
  expect(array.size).to eq(2)
433
433
  expect(array[0]._name).to eq('Two')
434
434
  end
435
-
435
+
436
436
  it "should compare true" do
437
437
  a = Model.new({_name: 'Cool'})
438
438
  expect(a == a).to eq(true)
439
439
  end
440
-
440
+
441
441
  it "should do index" do
442
442
  a = [{name: 'One'}, {name: 'Two'}, {name: 'Three'}]
443
443
  expect(a.index(a[1])).to eq(1)
444
444
  end
445
-
445
+
446
446
  it "should convert to a hash, and unwrap all of the way down" do
447
447
  a = Model.new
448
448
  a._items << {_name: 'Test1', _other: {_time: 'Now'}}
449
449
  a._items << {_name: 'Test2', _other: {_time: 'Later'}}
450
-
450
+
451
451
  item1 = a._items[0].to_h.cur
452
452
  expect(item1[:_name]).to eq('Test1')
453
453
  expect(item1[:_other][:_time]).to eq('Now')
454
-
454
+
455
455
  all_items = a._items.to_a.cur
456
-
456
+
457
457
  a = [
458
458
  {:_name => "Test1", :_other => {:_time => "Now"}},
459
459
  {:_name => "Test2", :_other => {:_time => "Later"}}
460
460
  ]
461
461
  expect(all_items).to eq(a)
462
462
  end
463
-
464
-
463
+
464
+
465
465
  describe "model paths" do
466
466
  before do
467
- @model = ReactiveValue.new(Model.new)
467
+ @model = ReactiveValue.new(Model.new)
468
468
  end
469
-
469
+
470
470
  it "should set the model path" do
471
471
  @model._object._name = 'Test'
472
472
  expect(@model._object.path.cur).to eq([:_object])
473
473
  end
474
-
474
+
475
475
  it "should set the model path for a sub array" do
476
476
  @model._items << {_name: 'Bob'}
477
477
  expect(@model._items.path.cur).to eq([:_items])
478
478
  expect(@model._items[0].path.cur).to eq([:_items, :[]])
479
479
  end
480
-
480
+
481
481
  it "should set the model path for sub sub arrays" do
482
482
  @model._lists << {_name: 'List 1', _items: []}
483
483
  expect(@model._lists[0]._items.path.cur).to eq([:_lists, :[], :_items])
484
484
  end
485
-
485
+
486
486
  it "should update the path when added from a model instance to a collection" do
487
487
  test_item = TestItem.new
488
-
488
+
489
489
  @model._items << test_item
490
490
  expect(@model._items[0].path).to eq([:_items, :[]])
491
491
  end
492
492
  end
493
-
493
+
494
494
  describe "persistors" do
495
495
  it "should setup a new instance of the persistor with self" do
496
496
  persistor = double('persistor')
@@ -498,4 +498,4 @@ describe Model do
498
498
  @model = Model.new(nil, persistor: persistor)
499
499
  end
500
500
  end
501
- end
501
+ end