volt 0.8.14 → 0.8.15
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Readme.md +8 -2
- data/VERSION +1 -1
- data/app/volt/controllers/notices_controller.rb +1 -1
- data/app/volt/models/user.rb +2 -2
- data/app/volt/tasks/live_query/live_query_pool.rb +1 -1
- data/app/volt/tasks/query_tasks.rb +1 -1
- data/app/volt/tasks/store_tasks.rb +1 -1
- data/app/volt/tasks/user_tasks.rb +2 -2
- data/lib/volt/boot.rb +2 -2
- data/lib/volt/cli/asset_compile.rb +31 -27
- data/lib/volt/cli.rb +64 -65
- data/lib/volt/config.rb +25 -23
- data/lib/volt/console.rb +17 -16
- data/lib/volt/controllers/model_controller.rb +82 -80
- data/lib/volt/data_stores/data_store.rb +2 -2
- data/lib/volt/data_stores/mongo_driver.rb +2 -2
- data/lib/volt/extra_core/inflections.rb +2 -2
- data/lib/volt/extra_core/inflector/inflections.rb +185 -183
- data/lib/volt/extra_core/inflector/methods.rb +50 -48
- data/lib/volt/extra_core/string.rb +2 -2
- data/lib/volt/models/array_model.rb +93 -92
- data/lib/volt/models/cursor.rb +3 -2
- data/lib/volt/models/model.rb +248 -251
- data/lib/volt/models/model_hash_behaviour.rb +44 -44
- data/lib/volt/models/model_helpers.rb +38 -36
- data/lib/volt/models/model_state.rb +16 -17
- data/lib/volt/models/model_wrapper.rb +25 -24
- data/lib/volt/models/persistors/array_store.rb +145 -143
- data/lib/volt/models/persistors/base.rb +18 -16
- data/lib/volt/models/persistors/flash.rb +24 -22
- data/lib/volt/models/persistors/local_store.rb +46 -44
- data/lib/volt/models/persistors/model_identity_map.rb +10 -8
- data/lib/volt/models/persistors/model_store.rb +76 -76
- data/lib/volt/models/persistors/params.rb +19 -17
- data/lib/volt/models/persistors/query/query_listener.rb +65 -63
- data/lib/volt/models/persistors/query/query_listener_pool.rb +12 -10
- data/lib/volt/models/persistors/store.rb +28 -28
- data/lib/volt/models/persistors/store_factory.rb +12 -10
- data/lib/volt/models/persistors/store_state.rb +33 -31
- data/lib/volt/models/url.rb +96 -104
- data/lib/volt/models/validations.rb +56 -54
- data/lib/volt/models/validators/length_validator.rb +24 -22
- data/lib/volt/models/validators/presence_validator.rb +14 -12
- data/lib/volt/page/bindings/attribute_binding.rb +106 -106
- data/lib/volt/page/bindings/base_binding.rb +23 -21
- data/lib/volt/page/bindings/component_binding.rb +3 -1
- data/lib/volt/page/bindings/content_binding.rb +34 -34
- data/lib/volt/page/bindings/each_binding.rb +113 -113
- data/lib/volt/page/bindings/event_binding.rb +38 -34
- data/lib/volt/page/bindings/if_binding.rb +56 -54
- data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +24 -22
- data/lib/volt/page/bindings/template_binding.rb +182 -185
- data/lib/volt/page/channel.rb +79 -77
- data/lib/volt/page/channel_stub.rb +29 -27
- data/lib/volt/page/document.rb +6 -5
- data/lib/volt/page/document_events.rb +54 -52
- data/lib/volt/page/page.rb +139 -138
- data/lib/volt/page/string_template_renderer.rb +36 -36
- data/lib/volt/page/sub_context.rb +26 -25
- data/lib/volt/page/targets/attribute_section.rb +27 -25
- data/lib/volt/page/targets/attribute_target.rb +7 -6
- data/lib/volt/page/targets/base_section.rb +27 -26
- data/lib/volt/page/targets/binding_document/base_node.rb +3 -1
- data/lib/volt/page/targets/binding_document/component_node.rb +85 -82
- data/lib/volt/page/targets/binding_document/html_node.rb +11 -9
- data/lib/volt/page/targets/dom_section.rb +78 -77
- data/lib/volt/page/targets/dom_target.rb +8 -6
- data/lib/volt/page/targets/dom_template.rb +90 -88
- data/lib/volt/page/targets/helpers/comment_searchers.rb +51 -49
- data/lib/volt/page/tasks.rb +59 -57
- data/lib/volt/page/template_renderer.rb +17 -14
- data/lib/volt/page/url_tracker.rb +26 -24
- data/lib/volt/reactive/computation.rb +87 -88
- data/lib/volt/reactive/dependency.rb +30 -28
- data/lib/volt/reactive/eventable.rb +64 -62
- data/lib/volt/reactive/hash_dependency.rb +25 -23
- data/lib/volt/reactive/reactive_accessors.rb +34 -32
- data/lib/volt/reactive/reactive_array.rb +162 -162
- data/lib/volt/reactive/reactive_hash.rb +37 -35
- data/lib/volt/router/routes.rb +99 -101
- data/lib/volt/server/component_handler.rb +20 -21
- data/lib/volt/server/component_templates.rb +72 -70
- data/lib/volt/server/html_parser/attribute_scope.rb +109 -99
- data/lib/volt/server/html_parser/each_scope.rb +17 -16
- data/lib/volt/server/html_parser/if_view_scope.rb +51 -49
- data/lib/volt/server/html_parser/sandlebars_parser.rb +184 -177
- data/lib/volt/server/html_parser/textarea_scope.rb +24 -22
- data/lib/volt/server/html_parser/view_handler.rb +66 -65
- data/lib/volt/server/html_parser/view_parser.rb +23 -21
- data/lib/volt/server/html_parser/view_scope.rb +142 -141
- data/lib/volt/server/rack/asset_files.rb +81 -79
- data/lib/volt/server/rack/component_code.rb +17 -15
- data/lib/volt/server/rack/component_html_renderer.rb +14 -12
- data/lib/volt/server/rack/component_paths.rb +72 -71
- data/lib/volt/server/rack/index_files.rb +36 -39
- data/lib/volt/server/rack/opal_files.rb +43 -41
- data/lib/volt/server/rack/source_map_server.rb +23 -21
- data/lib/volt/server/socket_connection_handler.rb +46 -45
- data/lib/volt/server/socket_connection_handler_stub.rb +21 -19
- data/lib/volt/server.rb +60 -58
- data/lib/volt/spec/setup.rb +3 -3
- data/lib/volt/tasks/dispatcher.rb +24 -23
- data/lib/volt/tasks/task_handler.rb +35 -33
- data/lib/volt/utils/ejson.rb +8 -6
- data/lib/volt/utils/generic_counting_pool.rb +33 -31
- data/lib/volt/utils/generic_pool.rb +73 -70
- data/lib/volt/utils/local_storage.rb +42 -38
- data/lib/volt/volt/environment.rb +1 -1
- data/lib/volt.rb +44 -42
- data/spec/apps/kitchen_sink/app/main/assets/css/todos.css +28 -0
- data/spec/apps/kitchen_sink/app/main/config/routes.rb +1 -0
- data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +2 -2
- data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +17 -0
- data/spec/apps/kitchen_sink/app/main/views/main/main.html +1 -0
- data/spec/apps/kitchen_sink/app/main/views/todos/index.html +24 -0
- data/spec/apps/kitchen_sink/config.ru +1 -1
- data/spec/controllers/reactive_accessors_spec.rb +5 -5
- data/spec/extra_core/inflector_spec.rb +2 -2
- data/spec/integration/list_spec.rb +68 -0
- data/spec/models/model_spec.rb +57 -57
- data/spec/models/persistors/params_spec.rb +6 -6
- data/spec/models/persistors/store_spec.rb +7 -7
- data/spec/models/validations_spec.rb +3 -3
- data/spec/page/bindings/content_binding_spec.rb +7 -7
- data/spec/page/bindings/template_binding_spec.rb +4 -5
- data/spec/page/sub_context_spec.rb +2 -2
- data/spec/reactive/computation_spec.rb +10 -10
- data/spec/reactive/dependency_spec.rb +2 -2
- data/spec/reactive/eventable_spec.rb +4 -4
- data/spec/reactive/reactive_array_spec.rb +13 -13
- data/spec/router/routes_spec.rb +5 -5
- data/spec/server/html_parser/sandlebars_parser_spec.rb +9 -9
- data/spec/server/html_parser/view_parser_spec.rb +27 -27
- data/spec/server/rack/asset_files_spec.rb +5 -5
- data/spec/server/rack/component_paths_spec.rb +2 -2
- data/spec/tasks/live_query_spec.rb +2 -2
- data/spec/tasks/query_tasks.rb +1 -1
- data/spec/tasks/query_tracker_spec.rb +1 -1
- data/spec/templates/targets/binding_document/component_node_spec.rb +2 -2
- data/spec/utils/generic_counting_pool_spec.rb +2 -2
- data/spec/utils/generic_pool_spec.rb +2 -2
- data/templates/component/controllers/main_controller.rb +1 -1
- data/templates/model/model.rb.tt +2 -2
- data/templates/newgem/app/newgem/controllers/main_controller.rb.tt +2 -2
- data/templates/project/app/main/controllers/main_controller.rb +1 -1
- data/templates/project/config.ru +1 -1
- metadata +10 -3
- data/app/volt/assets/js/vertxbus.js +0 -216
data/spec/models/model_spec.rb
CHANGED
|
@@ -2,45 +2,45 @@ require 'spec_helper'
|
|
|
2
2
|
require 'volt/models'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class TestItem < Model
|
|
5
|
+
class TestItem < Volt::Model
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
class Item < Model
|
|
8
|
+
class Item < Volt::Model
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
describe Model do
|
|
12
|
+
describe Volt::Model do
|
|
13
13
|
|
|
14
14
|
it "should allow _ methods to be used to store values without predefining them" do
|
|
15
|
-
a = Model.new
|
|
15
|
+
a = Volt::Model.new
|
|
16
16
|
a._stash = 'yes'
|
|
17
17
|
|
|
18
18
|
expect(a._stash).to eq('yes')
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "should update other values off the same model" do
|
|
22
|
-
a = Model.new
|
|
22
|
+
a = Volt::Model.new
|
|
23
23
|
|
|
24
24
|
values = []
|
|
25
25
|
-> { values << a._name }.watch!
|
|
26
26
|
|
|
27
27
|
expect(values).to eq([nil])
|
|
28
|
-
Computation.flush!
|
|
28
|
+
Volt::Computation.flush!
|
|
29
29
|
|
|
30
30
|
a._name = 'Bob'
|
|
31
31
|
|
|
32
|
-
Computation.flush!
|
|
32
|
+
Volt::Computation.flush!
|
|
33
33
|
expect(values).to eq([nil, 'Bob'])
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "should say unregistered attributes are nil" do
|
|
37
|
-
a = Model.new
|
|
37
|
+
a = Volt::Model.new
|
|
38
38
|
b = a._missing == nil
|
|
39
39
|
expect(b).to eq(true)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it "should negate nil and false correctly" do
|
|
43
|
-
a = Model.new
|
|
43
|
+
a = Volt::Model.new
|
|
44
44
|
expect((!a._missing)).to eq(true)
|
|
45
45
|
|
|
46
46
|
a._mis1 = nil
|
|
@@ -51,29 +51,29 @@ describe Model do
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "should return a nil model for an underscore value that doesn't exist" do
|
|
54
|
-
a = Model.new
|
|
54
|
+
a = Volt::Model.new
|
|
55
55
|
expect(a._something.attributes).to eq(nil)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
it "should trigger changed once when a new value is assigned." do
|
|
60
|
-
a = Model.new
|
|
60
|
+
a = Volt::Model.new
|
|
61
61
|
|
|
62
62
|
count = 0
|
|
63
63
|
-> { a._blue ; count += 1 }.watch!
|
|
64
64
|
expect(count).to eq(1)
|
|
65
65
|
|
|
66
66
|
a._blue = 'one'
|
|
67
|
-
Computation.flush!
|
|
67
|
+
Volt::Computation.flush!
|
|
68
68
|
expect(count).to eq(2)
|
|
69
69
|
|
|
70
70
|
a._blue = 'two'
|
|
71
|
-
Computation.flush!
|
|
71
|
+
Volt::Computation.flush!
|
|
72
72
|
expect(count).to eq(3)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it "should not trigger changed on other attributes" do
|
|
76
|
-
a = Model.new
|
|
76
|
+
a = Volt::Model.new
|
|
77
77
|
|
|
78
78
|
blue_count = 0
|
|
79
79
|
green_count = 0
|
|
@@ -85,18 +85,18 @@ describe Model do
|
|
|
85
85
|
expect(green_count).to eq(1)
|
|
86
86
|
|
|
87
87
|
a._green = 'one'
|
|
88
|
-
Computation.flush!
|
|
88
|
+
Volt::Computation.flush!
|
|
89
89
|
expect(blue_count).to eq(1)
|
|
90
90
|
expect(green_count).to eq(2)
|
|
91
91
|
|
|
92
92
|
a._blue = 'two'
|
|
93
|
-
Computation.flush!
|
|
93
|
+
Volt::Computation.flush!
|
|
94
94
|
expect(blue_count).to eq(2)
|
|
95
95
|
expect(green_count).to eq(2)
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
it "should call change through arguments" do
|
|
99
|
-
a = Model.new
|
|
99
|
+
a = Volt::Model.new
|
|
100
100
|
a._one = 1
|
|
101
101
|
a._two = 2
|
|
102
102
|
a._three = 3
|
|
@@ -108,20 +108,20 @@ describe Model do
|
|
|
108
108
|
expect(count).to eq(1)
|
|
109
109
|
|
|
110
110
|
a._two = 5
|
|
111
|
-
Computation.flush!
|
|
111
|
+
Volt::Computation.flush!
|
|
112
112
|
expect(count).to eq(2)
|
|
113
113
|
|
|
114
114
|
a._one = 6
|
|
115
|
-
Computation.flush!
|
|
115
|
+
Volt::Computation.flush!
|
|
116
116
|
expect(count).to eq(3)
|
|
117
117
|
|
|
118
118
|
a._three = 7
|
|
119
|
-
Computation.flush!
|
|
119
|
+
Volt::Computation.flush!
|
|
120
120
|
expect(count).to eq(3)
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
it 'should update through a normal array' do
|
|
124
|
-
model = Model.new
|
|
124
|
+
model = Volt::Model.new
|
|
125
125
|
array = []
|
|
126
126
|
array << model
|
|
127
127
|
|
|
@@ -132,14 +132,14 @@ describe Model do
|
|
|
132
132
|
expect(values).to eq([nil])
|
|
133
133
|
|
|
134
134
|
model._prop = 'one'
|
|
135
|
-
Computation.flush!
|
|
135
|
+
Volt::Computation.flush!
|
|
136
136
|
|
|
137
137
|
expect(values).to eq([nil, 'one'])
|
|
138
138
|
|
|
139
139
|
end
|
|
140
140
|
|
|
141
141
|
it "should trigger changed for any indicies after a deleted index" do
|
|
142
|
-
model = Model.new
|
|
142
|
+
model = Volt::Model.new
|
|
143
143
|
|
|
144
144
|
model._items << {_name: 'One'}
|
|
145
145
|
model._items << {_name: 'Two'}
|
|
@@ -150,12 +150,12 @@ describe Model do
|
|
|
150
150
|
expect(count).to eq(1)
|
|
151
151
|
|
|
152
152
|
model._items.delete_at(1)
|
|
153
|
-
Computation.flush!
|
|
153
|
+
Volt::Computation.flush!
|
|
154
154
|
expect(count).to eq(2)
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
it "should change the size and length when an item gets added" do
|
|
158
|
-
model = Model.new
|
|
158
|
+
model = Volt::Model.new
|
|
159
159
|
|
|
160
160
|
model._items << {_name: 'One'}
|
|
161
161
|
size = model._items.size
|
|
@@ -169,14 +169,14 @@ describe Model do
|
|
|
169
169
|
expect(count_length).to eq(1)
|
|
170
170
|
|
|
171
171
|
model._items << {_name: 'Two'}
|
|
172
|
-
Computation.flush!
|
|
172
|
+
Volt::Computation.flush!
|
|
173
173
|
|
|
174
174
|
expect(count_size).to eq(2)
|
|
175
175
|
expect(count_length).to eq(2)
|
|
176
176
|
end
|
|
177
177
|
|
|
178
178
|
it "should add doubly nested arrays" do
|
|
179
|
-
model = Model.new
|
|
179
|
+
model = Volt::Model.new
|
|
180
180
|
|
|
181
181
|
model._items << {name: 'Cool', lists: []}
|
|
182
182
|
model._items[0]._lists << {name: 'worked'}
|
|
@@ -184,61 +184,61 @@ describe Model do
|
|
|
184
184
|
end
|
|
185
185
|
|
|
186
186
|
it "should make pushed subarrays into ArrayModels" do
|
|
187
|
-
model = Model.new
|
|
187
|
+
model = Volt::Model.new
|
|
188
188
|
|
|
189
189
|
model._items << {_name: 'Test', _lists: []}
|
|
190
|
-
expect(model._items[0]._lists.class).to eq(ArrayModel)
|
|
190
|
+
expect(model._items[0]._lists.class).to eq(Volt::ArrayModel)
|
|
191
191
|
end
|
|
192
192
|
|
|
193
193
|
it "should make assigned subarrays into ArrayModels" do
|
|
194
|
-
model = Model.new
|
|
194
|
+
model = Volt::Model.new
|
|
195
195
|
|
|
196
196
|
model._item._name = 'Test'
|
|
197
197
|
model._item._lists = []
|
|
198
|
-
expect(model._item._lists.class).to eq(ArrayModel)
|
|
198
|
+
expect(model._item._lists.class).to eq(Volt::ArrayModel)
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
it "should call changed when a the reference to a submodel is assigned to another value" do
|
|
202
|
-
a = Model.new
|
|
202
|
+
a = Volt::Model.new
|
|
203
203
|
|
|
204
204
|
count = 0
|
|
205
205
|
-> { a._blue && a._blue.respond_to?(:green) && a._blue._green ; count += 1 }.watch!
|
|
206
206
|
expect(count).to eq(1)
|
|
207
207
|
|
|
208
208
|
a._blue._green = 5
|
|
209
|
-
Computation.flush!
|
|
209
|
+
Volt::Computation.flush!
|
|
210
210
|
|
|
211
211
|
# TODO: Should equal 2
|
|
212
212
|
expect(count).to eq(2)
|
|
213
213
|
|
|
214
214
|
a._blue = 22
|
|
215
|
-
Computation.flush!
|
|
215
|
+
Volt::Computation.flush!
|
|
216
216
|
expect(count).to eq(3)
|
|
217
217
|
|
|
218
218
|
a._blue = {green: 50}
|
|
219
219
|
expect(a._blue._green).to eq(50)
|
|
220
|
-
Computation.flush!
|
|
220
|
+
Volt::Computation.flush!
|
|
221
221
|
expect(count).to eq(4)
|
|
222
222
|
end
|
|
223
223
|
|
|
224
224
|
it "should trigger changed when a value is deleted" do
|
|
225
|
-
a = Model.new
|
|
225
|
+
a = Volt::Model.new
|
|
226
226
|
|
|
227
227
|
count = 0
|
|
228
228
|
-> { a._blue ; count += 1 }.watch!
|
|
229
229
|
expect(count).to eq(1)
|
|
230
230
|
|
|
231
231
|
a._blue = 1
|
|
232
|
-
Computation.flush!
|
|
232
|
+
Volt::Computation.flush!
|
|
233
233
|
expect(count).to eq(2)
|
|
234
234
|
|
|
235
235
|
a.delete(:blue)
|
|
236
|
-
Computation.flush!
|
|
236
|
+
Volt::Computation.flush!
|
|
237
237
|
expect(count).to eq(3)
|
|
238
238
|
end
|
|
239
239
|
|
|
240
240
|
it "should let you append nested hashes" do
|
|
241
|
-
a = Model.new
|
|
241
|
+
a = Volt::Model.new
|
|
242
242
|
|
|
243
243
|
a._items << {name: {text: 'Name'}}
|
|
244
244
|
|
|
@@ -247,7 +247,7 @@ describe Model do
|
|
|
247
247
|
|
|
248
248
|
|
|
249
249
|
it "should not call added too many times" do
|
|
250
|
-
a = Model.new
|
|
250
|
+
a = Volt::Model.new
|
|
251
251
|
a._lists << 1
|
|
252
252
|
|
|
253
253
|
count = 0
|
|
@@ -259,7 +259,7 @@ describe Model do
|
|
|
259
259
|
end
|
|
260
260
|
|
|
261
261
|
it "should propigate to different branches" do
|
|
262
|
-
a = Model.new
|
|
262
|
+
a = Volt::Model.new
|
|
263
263
|
count = 0
|
|
264
264
|
-> do
|
|
265
265
|
count += 1
|
|
@@ -268,13 +268,13 @@ describe Model do
|
|
|
268
268
|
expect(count).to eq(1)
|
|
269
269
|
|
|
270
270
|
a._new_item._name = 'Testing'
|
|
271
|
-
Computation.flush!
|
|
271
|
+
Volt::Computation.flush!
|
|
272
272
|
expect(count).to eq(2)
|
|
273
273
|
end
|
|
274
274
|
|
|
275
275
|
describe "paths" do
|
|
276
276
|
it "should store the path" do
|
|
277
|
-
a = Model.new
|
|
277
|
+
a = Volt::Model.new
|
|
278
278
|
expect(a._test.path).to eq([:test])
|
|
279
279
|
a._test = {_name: 'Yes'}
|
|
280
280
|
expect(a._test.path).to eq([:test])
|
|
@@ -285,7 +285,7 @@ describe Model do
|
|
|
285
285
|
end
|
|
286
286
|
|
|
287
287
|
it "should store the paths when assigned" do
|
|
288
|
-
a = Model.new
|
|
288
|
+
a = Volt::Model.new
|
|
289
289
|
|
|
290
290
|
a._items = [{_name: 'Cool'}]
|
|
291
291
|
|
|
@@ -294,7 +294,7 @@ describe Model do
|
|
|
294
294
|
end
|
|
295
295
|
|
|
296
296
|
it "should handle nested paths" do
|
|
297
|
-
a = Model.new
|
|
297
|
+
a = Volt::Model.new
|
|
298
298
|
|
|
299
299
|
a._items << {name: 'Cool', lists: [{name: 'One'}, {name: 'Two'}]}
|
|
300
300
|
|
|
@@ -303,7 +303,7 @@ describe Model do
|
|
|
303
303
|
end
|
|
304
304
|
|
|
305
305
|
it "should trigger added when added" do
|
|
306
|
-
a = Model.new
|
|
306
|
+
a = Volt::Model.new
|
|
307
307
|
count = 0
|
|
308
308
|
b = a._items
|
|
309
309
|
|
|
@@ -318,7 +318,7 @@ describe Model do
|
|
|
318
318
|
end
|
|
319
319
|
|
|
320
320
|
it "should trigger on false assign" do
|
|
321
|
-
a = Model.new
|
|
321
|
+
a = Volt::Model.new
|
|
322
322
|
count = 0
|
|
323
323
|
|
|
324
324
|
-> { count += 1 ; a._complete }.watch!
|
|
@@ -326,16 +326,16 @@ describe Model do
|
|
|
326
326
|
expect(count).to eq(1)
|
|
327
327
|
|
|
328
328
|
a._complete = true
|
|
329
|
-
Computation.flush!
|
|
329
|
+
Volt::Computation.flush!
|
|
330
330
|
expect(count).to eq(2)
|
|
331
331
|
|
|
332
332
|
a._complete = false
|
|
333
|
-
Computation.flush!
|
|
333
|
+
Volt::Computation.flush!
|
|
334
334
|
expect(count).to eq(3)
|
|
335
335
|
end
|
|
336
336
|
|
|
337
337
|
it "should delete from an ArrayModel" do
|
|
338
|
-
array = ArrayModel.new([])
|
|
338
|
+
array = Volt::ArrayModel.new([])
|
|
339
339
|
|
|
340
340
|
array << {name: 'One'}
|
|
341
341
|
array << {name: 'Two'}
|
|
@@ -351,7 +351,7 @@ describe Model do
|
|
|
351
351
|
end
|
|
352
352
|
|
|
353
353
|
it "should compare true" do
|
|
354
|
-
a = Model.new({_name: 'Cool'})
|
|
354
|
+
a = Volt::Model.new({_name: 'Cool'})
|
|
355
355
|
expect(a == a).to eq(true)
|
|
356
356
|
end
|
|
357
357
|
|
|
@@ -361,7 +361,7 @@ describe Model do
|
|
|
361
361
|
end
|
|
362
362
|
|
|
363
363
|
it "should convert to a hash, and unwrap all of the way down" do
|
|
364
|
-
a = Model.new
|
|
364
|
+
a = Volt::Model.new
|
|
365
365
|
a._items << {name: 'Test1', other: {time: 'Now'}}
|
|
366
366
|
a._items << {name: 'Test2', other: {time: 'Later'}}
|
|
367
367
|
|
|
@@ -381,7 +381,7 @@ describe Model do
|
|
|
381
381
|
|
|
382
382
|
describe "model paths" do
|
|
383
383
|
before do
|
|
384
|
-
@model = Model.new
|
|
384
|
+
@model = Volt::Model.new
|
|
385
385
|
end
|
|
386
386
|
|
|
387
387
|
it "should set the model path" do
|
|
@@ -410,19 +410,19 @@ describe Model do
|
|
|
410
410
|
|
|
411
411
|
describe "persistors" do
|
|
412
412
|
it "should setup a new instance of the persistor with self" do
|
|
413
|
-
persistor = double('persistor')
|
|
413
|
+
persistor = double('volt/persistor')
|
|
414
414
|
expect(persistor).to receive(:new)
|
|
415
|
-
@model = Model.new(nil, persistor: persistor)
|
|
415
|
+
@model = Volt::Model.new(nil, persistor: persistor)
|
|
416
416
|
end
|
|
417
417
|
end
|
|
418
418
|
|
|
419
419
|
if RUBY_PLATFORM != 'opal'
|
|
420
420
|
describe "class loading" do
|
|
421
421
|
it 'should load classes for models' do
|
|
422
|
-
$page = Page.new
|
|
422
|
+
$page = Volt::Page.new
|
|
423
423
|
$page.add_model('Item')
|
|
424
424
|
|
|
425
|
-
@model = Model.new
|
|
425
|
+
@model = Volt::Model.new
|
|
426
426
|
|
|
427
427
|
# Should return a buffer of the right type
|
|
428
428
|
expect(@model._items.buffer.class).to eq(Item)
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'volt/models'
|
|
3
3
|
|
|
4
|
-
describe Persistors::Params do
|
|
4
|
+
describe Volt::Persistors::Params do
|
|
5
5
|
it "should stay as params classes when used" do
|
|
6
|
-
a = Model.new({}, persistor: Persistors::Params)
|
|
7
|
-
expect(a._test.class).to eq(Model)
|
|
6
|
+
a = Volt::Model.new({}, persistor: Volt::Persistors::Params)
|
|
7
|
+
expect(a._test.class).to eq(Volt::Model)
|
|
8
8
|
|
|
9
|
-
expect(a._test._cool.persistor.class).to eq(Persistors::Params)
|
|
9
|
+
expect(a._test._cool.persistor.class).to eq(Volt::Persistors::Params)
|
|
10
10
|
|
|
11
11
|
a._items << {name: 'Test'}
|
|
12
12
|
|
|
13
|
-
expect(a._items.persistor.class).to eq(Persistors::Params)
|
|
14
|
-
expect(a._items[0].persistor.class).to eq(Persistors::Params)
|
|
13
|
+
expect(a._items.persistor.class).to eq(Volt::Persistors::Params)
|
|
14
|
+
expect(a._items[0].persistor.class).to eq(Volt::Persistors::Params)
|
|
15
15
|
expect(a._items[0]._name.class).to eq(String)
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'volt/models'
|
|
3
3
|
|
|
4
|
-
describe Persistors::Store do
|
|
4
|
+
describe Volt::Persistors::Store do
|
|
5
5
|
it "should tell the persistor when the model has changed" do
|
|
6
|
-
persistor = double('persistor')
|
|
7
|
-
persistor_instance = double('persistor instance')
|
|
6
|
+
persistor = double('volt/persistor')
|
|
7
|
+
persistor_instance = double('volt/persistor instance')
|
|
8
8
|
expect(persistor_instance).to receive(:loaded)
|
|
9
9
|
expect(persistor).to receive(:new).and_return(persistor_instance)
|
|
10
10
|
|
|
11
|
-
@model = Model.new(nil, persistor: persistor)
|
|
11
|
+
@model = Volt::Model.new(nil, persistor: persistor)
|
|
12
12
|
|
|
13
13
|
expect(persistor_instance).to receive(:changed)
|
|
14
14
|
|
|
@@ -16,12 +16,12 @@ describe Persistors::Store do
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "should tell the persistor when something is added to an array model" do
|
|
19
|
-
persistor = double('persistor')
|
|
20
|
-
persistor_instance = double('persistor instance')
|
|
19
|
+
persistor = double('volt/persistor')
|
|
20
|
+
persistor_instance = double('volt/persistor instance')
|
|
21
21
|
expect(persistor_instance).to receive(:loaded)
|
|
22
22
|
expect(persistor).to receive(:new).and_return(persistor_instance)
|
|
23
23
|
|
|
24
|
-
@model = ArrayModel.new([1,2,3], persistor: persistor)
|
|
24
|
+
@model = Volt::ArrayModel.new([1,2,3], persistor: persistor)
|
|
25
25
|
|
|
26
26
|
expect(persistor_instance).to receive(:added).with(4,3)
|
|
27
27
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
require 'volt/models'
|
|
2
2
|
|
|
3
|
-
class TestModel < Model
|
|
3
|
+
class TestModel < Volt::Model
|
|
4
4
|
validate :_name, length: 4
|
|
5
5
|
validate :_description, length: {message: 'needs to be longer', length: 50}
|
|
6
6
|
validate :_username, presence: true
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
describe Model do
|
|
10
|
+
describe Volt::Model do
|
|
11
11
|
it "should validate the name" do
|
|
12
12
|
expect(TestModel.new.errors).to eq(
|
|
13
13
|
{
|
|
@@ -73,4 +73,4 @@ describe Model do
|
|
|
73
73
|
)
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
|
-
end
|
|
76
|
+
end
|
|
@@ -5,18 +5,18 @@ require 'volt/page/targets/dom_section'
|
|
|
5
5
|
require 'volt/page/template_renderer'
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
describe ContentBinding do
|
|
8
|
+
describe Volt::ContentBinding do
|
|
9
9
|
it "should render the content in a content binding" do
|
|
10
|
-
dom = AttributeTarget.new(0)
|
|
10
|
+
dom = Volt::AttributeTarget.new(0)
|
|
11
11
|
context = {:name => 'jimmy'}
|
|
12
|
-
binding = ContentBinding.new(nil, dom, context, 0, Proc.new { self[:name] })
|
|
12
|
+
binding = Volt::ContentBinding.new(nil, dom, context, 0, Proc.new { self[:name] })
|
|
13
13
|
|
|
14
14
|
expect(dom.to_html).to eq('jimmy')
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "should render with a template" do
|
|
18
18
|
context = {:name => 'jimmy'}
|
|
19
|
-
binding = lambda {|page, target, context, id| ContentBinding.new(page, target, context, id, Proc.new { self[:name] }) }
|
|
19
|
+
binding = lambda {|page, target, context, id| Volt::ContentBinding.new(page, target, context, id, Proc.new { self[:name] }) }
|
|
20
20
|
|
|
21
21
|
templates = {
|
|
22
22
|
'main/main' => {
|
|
@@ -25,12 +25,12 @@ describe ContentBinding do
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
page = double('page')
|
|
28
|
+
page = double('volt/page')
|
|
29
29
|
expect(page).to receive(:templates).and_return(templates)
|
|
30
30
|
|
|
31
|
-
dom = AttributeTarget.new(0)
|
|
31
|
+
dom = Volt::AttributeTarget.new(0)
|
|
32
32
|
|
|
33
|
-
TemplateRenderer.new(page, dom, context, 'main', 'main/main')
|
|
33
|
+
Volt::TemplateRenderer.new(page, dom, context, 'main', 'main/main')
|
|
34
34
|
|
|
35
35
|
expect(dom.to_html).to eq('hello jimmy')
|
|
36
36
|
end
|
|
@@ -3,18 +3,17 @@ require 'volt/page/bindings/template_binding'
|
|
|
3
3
|
|
|
4
4
|
# Setup page stub
|
|
5
5
|
|
|
6
|
-
class Page
|
|
6
|
+
class Volt::Page
|
|
7
7
|
attr_accessor :templates
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
describe TemplateBinding do
|
|
10
|
+
describe Volt::TemplateBinding do
|
|
12
11
|
before do
|
|
13
|
-
@page = double('page')
|
|
12
|
+
@page = double('volt/page')
|
|
14
13
|
expect(@page).to receive(:templates).at_least(1).times { @templates }
|
|
15
14
|
|
|
16
15
|
# TODO: We should decouple things so we don't need to allocate
|
|
17
|
-
@template_binding = TemplateBinding.allocate
|
|
16
|
+
@template_binding = Volt::TemplateBinding.allocate
|
|
18
17
|
@template_binding.instance_variable_set('@page', @page)
|
|
19
18
|
@template_binding.setup_path('main/main/main')
|
|
20
19
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require 'volt/page/sub_context'
|
|
2
2
|
|
|
3
|
-
describe SubContext do
|
|
3
|
+
describe Volt::SubContext do
|
|
4
4
|
it "should respond_to correctly on locals" do
|
|
5
|
-
sub_context = SubContext.new({:name => 'Name'})
|
|
5
|
+
sub_context = Volt::SubContext.new({:name => 'Name'})
|
|
6
6
|
|
|
7
7
|
expect(sub_context.respond_to?(:name)).to eq(true)
|
|
8
8
|
expect(sub_context.respond_to?(:missing)).to eq(false)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Computation do
|
|
3
|
+
describe Volt::Computation do
|
|
4
4
|
it 'should trigger again when a dependent changes' do
|
|
5
|
-
a = ReactiveHash.new
|
|
5
|
+
a = Volt::ReactiveHash.new
|
|
6
6
|
|
|
7
7
|
values = []
|
|
8
8
|
|
|
@@ -11,16 +11,16 @@ describe Computation do
|
|
|
11
11
|
expect(values).to eq([nil])
|
|
12
12
|
|
|
13
13
|
a[0] = 'one'
|
|
14
|
-
Computation.flush!
|
|
14
|
+
Volt::Computation.flush!
|
|
15
15
|
expect(values).to eq([nil, 'one'])
|
|
16
16
|
|
|
17
17
|
a[0] = 'two'
|
|
18
|
-
Computation.flush!
|
|
18
|
+
Volt::Computation.flush!
|
|
19
19
|
expect(values).to eq([nil, 'one', 'two'])
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it 'should not trigger after the computation is stopped' do
|
|
23
|
-
a = ReactiveHash.new
|
|
23
|
+
a = Volt::ReactiveHash.new
|
|
24
24
|
|
|
25
25
|
values = []
|
|
26
26
|
computation = -> { values << a[0] }.watch!
|
|
@@ -28,18 +28,18 @@ describe Computation do
|
|
|
28
28
|
expect(values).to eq([nil])
|
|
29
29
|
|
|
30
30
|
a[0] = 'one'
|
|
31
|
-
Computation.flush!
|
|
31
|
+
Volt::Computation.flush!
|
|
32
32
|
expect(values).to eq([nil, 'one'])
|
|
33
33
|
|
|
34
34
|
computation.stop
|
|
35
35
|
|
|
36
36
|
a[0] = 'two'
|
|
37
|
-
Computation.flush!
|
|
37
|
+
Volt::Computation.flush!
|
|
38
38
|
expect(values).to eq([nil, 'one'])
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it 'should support nested watches' do
|
|
42
|
-
a = ReactiveHash.new
|
|
42
|
+
a = Volt::ReactiveHash.new
|
|
43
43
|
|
|
44
44
|
values = []
|
|
45
45
|
-> do
|
|
@@ -53,11 +53,11 @@ describe Computation do
|
|
|
53
53
|
expect(values).to eq([nil,nil])
|
|
54
54
|
|
|
55
55
|
a[1] = 'inner'
|
|
56
|
-
Computation.flush!
|
|
56
|
+
Volt::Computation.flush!
|
|
57
57
|
expect(values).to eq([nil,nil,'inner'])
|
|
58
58
|
|
|
59
59
|
a[0] = 'outer'
|
|
60
|
-
Computation.flush!
|
|
60
|
+
Volt::Computation.flush!
|
|
61
61
|
expect(values).to eq([nil,nil,'inner','outer','inner'])
|
|
62
62
|
end
|
|
63
63
|
end
|
|
@@ -2,14 +2,14 @@ require 'spec_helper'
|
|
|
2
2
|
require 'volt/reactive/eventable'
|
|
3
3
|
|
|
4
4
|
class TestEventable
|
|
5
|
-
include Eventable
|
|
5
|
+
include Volt::Eventable
|
|
6
6
|
|
|
7
7
|
def trigger_works_event!
|
|
8
8
|
trigger!('works', 20)
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
describe Eventable do
|
|
12
|
+
describe Volt::Eventable do
|
|
13
13
|
it 'should allow events to be bound with on' do
|
|
14
14
|
test_eventable = TestEventable.new
|
|
15
15
|
|
|
@@ -32,7 +32,7 @@ describe Eventable do
|
|
|
32
32
|
count += 1
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
expect(listener.class).to eq(Listener)
|
|
35
|
+
expect(listener.class).to eq(Volt::Listener)
|
|
36
36
|
|
|
37
37
|
expect(count).to eq(0)
|
|
38
38
|
test_eventable.trigger_works_event!
|
|
@@ -45,4 +45,4 @@ describe Eventable do
|
|
|
45
45
|
test_eventable.trigger_works_event!
|
|
46
46
|
expect(count).to eq(2)
|
|
47
47
|
end
|
|
48
|
-
end
|
|
48
|
+
end
|