volt 0.8.15 → 0.8.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +11 -0
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +1 -1
  5. data/Guardfile +2 -3
  6. data/Rakefile +1 -4
  7. data/VERSION +1 -1
  8. data/app/volt/controllers/notices_controller.rb +1 -1
  9. data/app/volt/tasks/live_query/data_store.rb +7 -7
  10. data/app/volt/tasks/live_query/live_query.rb +7 -9
  11. data/app/volt/tasks/live_query/live_query_pool.rb +13 -12
  12. data/app/volt/tasks/live_query/query_tracker.rb +4 -5
  13. data/app/volt/tasks/query_tasks.rb +9 -11
  14. data/app/volt/tasks/store_tasks.rb +4 -4
  15. data/app/volt/tasks/user_tasks.rb +1 -1
  16. data/bin/volt +2 -2
  17. data/lib/volt.rb +3 -7
  18. data/lib/volt/assets/test.rb +1 -2
  19. data/lib/volt/benchmark/benchmark.rb +3 -3
  20. data/lib/volt/boot.rb +1 -1
  21. data/lib/volt/cli.rb +18 -18
  22. data/lib/volt/cli/asset_compile.rb +8 -10
  23. data/lib/volt/cli/generate.rb +9 -11
  24. data/lib/volt/cli/new_gem.rb +51 -51
  25. data/lib/volt/config.rb +2 -3
  26. data/lib/volt/console.rb +1 -1
  27. data/lib/volt/controllers/model_controller.rb +6 -6
  28. data/lib/volt/data_stores/data_store.rb +1 -1
  29. data/lib/volt/data_stores/mongo_driver.rb +1 -1
  30. data/lib/volt/extra_core/array.rb +2 -2
  31. data/lib/volt/extra_core/blank.rb +1 -2
  32. data/lib/volt/extra_core/extra_core.rb +1 -1
  33. data/lib/volt/extra_core/inflector/methods.rb +0 -1
  34. data/lib/volt/extra_core/logger.rb +13 -7
  35. data/lib/volt/extra_core/numeric.rb +1 -1
  36. data/lib/volt/extra_core/string.rb +7 -7
  37. data/lib/volt/extra_core/stringify_keys.rb +5 -5
  38. data/lib/volt/models.rb +2 -2
  39. data/lib/volt/models/array_model.rb +18 -19
  40. data/lib/volt/models/cursor.rb +0 -1
  41. data/lib/volt/models/model.rb +17 -35
  42. data/lib/volt/models/model_hash_behaviour.rb +0 -2
  43. data/lib/volt/models/model_state.rb +1 -1
  44. data/lib/volt/models/model_wrapper.rb +1 -1
  45. data/lib/volt/models/persistors/array_store.rb +26 -13
  46. data/lib/volt/models/persistors/base.rb +1 -1
  47. data/lib/volt/models/persistors/flash.rb +2 -2
  48. data/lib/volt/models/persistors/local_store.rb +2 -3
  49. data/lib/volt/models/persistors/model_store.rb +7 -6
  50. data/lib/volt/models/persistors/params.rb +2 -2
  51. data/lib/volt/models/persistors/query/query_listener.rb +2 -0
  52. data/lib/volt/models/persistors/query/query_listener_pool.rb +1 -1
  53. data/lib/volt/models/persistors/store.rb +1 -2
  54. data/lib/volt/models/persistors/store_state.rb +2 -3
  55. data/lib/volt/models/url.rb +17 -16
  56. data/lib/volt/models/validations.rb +11 -14
  57. data/lib/volt/models/validators/length_validator.rb +3 -3
  58. data/lib/volt/models/validators/presence_validator.rb +2 -2
  59. data/lib/volt/page/bindings/attribute_binding.rb +2 -3
  60. data/lib/volt/page/bindings/base_binding.rb +1 -1
  61. data/lib/volt/page/bindings/each_binding.rb +8 -9
  62. data/lib/volt/page/bindings/event_binding.rb +2 -3
  63. data/lib/volt/page/bindings/template_binding.rb +8 -7
  64. data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +2 -1
  65. data/lib/volt/page/channel.rb +10 -10
  66. data/lib/volt/page/channel_stub.rb +1 -1
  67. data/lib/volt/page/document.rb +0 -1
  68. data/lib/volt/page/document_events.rb +4 -4
  69. data/lib/volt/page/page.rb +26 -19
  70. data/lib/volt/page/string_template_renderer.rb +2 -2
  71. data/lib/volt/page/sub_context.rb +10 -4
  72. data/lib/volt/page/targets/attribute_section.rb +1 -1
  73. data/lib/volt/page/targets/attribute_target.rb +1 -2
  74. data/lib/volt/page/targets/base_section.rb +4 -4
  75. data/lib/volt/page/targets/binding_document/base_node.rb +0 -1
  76. data/lib/volt/page/targets/binding_document/component_node.rb +4 -5
  77. data/lib/volt/page/targets/dom_section.rb +21 -22
  78. data/lib/volt/page/targets/dom_target.rb +1 -1
  79. data/lib/volt/page/targets/dom_template.rb +11 -12
  80. data/lib/volt/page/targets/helpers/comment_searchers.rb +7 -8
  81. data/lib/volt/page/tasks.rb +0 -1
  82. data/lib/volt/page/template_renderer.rb +1 -1
  83. data/lib/volt/page/url_tracker.rb +3 -3
  84. data/lib/volt/reactive/computation.rb +5 -11
  85. data/lib/volt/reactive/dependency.rb +1 -3
  86. data/lib/volt/reactive/eventable.rb +17 -4
  87. data/lib/volt/reactive/hash_dependency.rb +1 -0
  88. data/lib/volt/reactive/reactive_accessors.rb +0 -1
  89. data/lib/volt/reactive/reactive_array.rb +20 -25
  90. data/lib/volt/reactive/reactive_hash.rb +3 -3
  91. data/lib/volt/router/routes.rb +11 -13
  92. data/lib/volt/server.rb +17 -17
  93. data/lib/volt/server/component_handler.rb +2 -2
  94. data/lib/volt/server/component_templates.rb +8 -8
  95. data/lib/volt/server/html_parser/attribute_scope.rb +9 -10
  96. data/lib/volt/server/html_parser/if_view_scope.rb +2 -2
  97. data/lib/volt/server/html_parser/sandlebars_parser.rb +14 -14
  98. data/lib/volt/server/html_parser/textarea_scope.rb +1 -2
  99. data/lib/volt/server/html_parser/view_handler.rb +1 -1
  100. data/lib/volt/server/html_parser/view_parser.rb +1 -1
  101. data/lib/volt/server/html_parser/view_scope.rb +10 -10
  102. data/lib/volt/server/rack/asset_files.rb +15 -16
  103. data/lib/volt/server/rack/component_code.rb +2 -2
  104. data/lib/volt/server/rack/component_html_renderer.rb +0 -1
  105. data/lib/volt/server/rack/component_paths.rb +13 -10
  106. data/lib/volt/server/rack/index_files.rb +4 -4
  107. data/lib/volt/server/rack/opal_files.rb +4 -5
  108. data/lib/volt/server/rack/source_map_server.rb +3 -3
  109. data/lib/volt/server/socket_connection_handler.rb +3 -4
  110. data/lib/volt/server/socket_connection_handler_stub.rb +1 -1
  111. data/lib/volt/spec/setup.rb +3 -3
  112. data/lib/volt/store/mongo.rb +2 -2
  113. data/lib/volt/tasks/task_handler.rb +3 -3
  114. data/lib/volt/utils/generic_counting_pool.rb +2 -2
  115. data/lib/volt/utils/generic_pool.rb +7 -8
  116. data/lib/volt/utils/local_storage.rb +4 -4
  117. data/lib/volt/volt/environment.rb +1 -1
  118. data/spec/apps/file_loading/app/shared/config/dependencies.rb +1 -1
  119. data/spec/apps/kitchen_sink/Gemfile +0 -2
  120. data/spec/apps/kitchen_sink/app/main/config/routes.rb +5 -5
  121. data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +7 -6
  122. data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +3 -4
  123. data/spec/controllers/reactive_accessors_spec.rb +4 -4
  124. data/spec/extra_core/inflector_spec.rb +1 -1
  125. data/spec/extra_core/string_transformation_test_cases.rb +23 -24
  126. data/spec/extra_core/string_transformations_spec.rb +11 -12
  127. data/spec/integration/bindings_spec.rb +15 -15
  128. data/spec/integration/list_spec.rb +12 -13
  129. data/spec/integration/templates_spec.rb +3 -3
  130. data/spec/models/model_spec.rb +74 -80
  131. data/spec/models/persistors/params_spec.rb +2 -2
  132. data/spec/models/persistors/store_spec.rb +4 -4
  133. data/spec/models/validations_spec.rb +14 -23
  134. data/spec/page/bindings/content_binding_spec.rb +7 -8
  135. data/spec/page/bindings/template_binding_spec.rb +22 -24
  136. data/spec/page/sub_context_spec.rb +2 -2
  137. data/spec/reactive/computation_spec.rb +3 -3
  138. data/spec/reactive/reactive_array_spec.rb +12 -12
  139. data/spec/router/routes_spec.rb +45 -48
  140. data/spec/server/html_parser/sandlebars_parser_spec.rb +42 -42
  141. data/spec/server/html_parser/view_parser_spec.rb +132 -153
  142. data/spec/server/rack/asset_files_spec.rb +9 -8
  143. data/spec/server/rack/component_paths_spec.rb +5 -5
  144. data/spec/server/rack/rack_requests_spec.rb +3 -3
  145. data/spec/spec_helper.rb +1 -1
  146. data/spec/tasks/live_query_spec.rb +4 -5
  147. data/spec/tasks/query_tasks.rb +2 -4
  148. data/spec/tasks/query_tracker_spec.rb +29 -29
  149. data/spec/templates/targets/binding_document/component_node_spec.rb +1 -1
  150. data/spec/utils/generic_counting_pool_spec.rb +4 -4
  151. data/spec/utils/generic_pool_spec.rb +12 -12
  152. data/templates/component/config/routes.rb +2 -2
  153. data/templates/component/controllers/main_controller.rb +7 -6
  154. data/templates/newgem/app/newgem/config/dependencies.rb +1 -1
  155. data/templates/newgem/app/newgem/config/routes.rb +1 -1
  156. data/templates/project/app/main/config/routes.rb +2 -2
  157. data/templates/project/app/main/controllers/main_controller.rb +7 -6
  158. data/templates/project/spec/sample_spec.rb +2 -2
  159. data/volt.gemspec +32 -33
  160. metadata +3 -4
  161. data/lib/volt/extra_core/log.rb +0 -56
  162. data/lib/volt/extra_core/try.rb +0 -31
@@ -2,13 +2,13 @@ require 'spec_helper'
2
2
  require 'volt/models'
3
3
 
4
4
  describe Volt::Persistors::Params do
5
- it "should stay as params classes when used" do
5
+ it 'should stay as params classes when used' do
6
6
  a = Volt::Model.new({}, persistor: Volt::Persistors::Params)
7
7
  expect(a._test.class).to eq(Volt::Model)
8
8
 
9
9
  expect(a._test._cool.persistor.class).to eq(Volt::Persistors::Params)
10
10
 
11
- a._items << {name: 'Test'}
11
+ a._items << { name: 'Test' }
12
12
 
13
13
  expect(a._items.persistor.class).to eq(Volt::Persistors::Params)
14
14
  expect(a._items[0].persistor.class).to eq(Volt::Persistors::Params)
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'volt/models'
3
3
 
4
4
  describe Volt::Persistors::Store do
5
- it "should tell the persistor when the model has changed" do
5
+ it 'should tell the persistor when the model has changed' do
6
6
  persistor = double('volt/persistor')
7
7
  persistor_instance = double('volt/persistor instance')
8
8
  expect(persistor_instance).to receive(:loaded)
@@ -15,15 +15,15 @@ describe Volt::Persistors::Store do
15
15
  @model._attr = 'yes'
16
16
  end
17
17
 
18
- it "should tell the persistor when something is added to an array model" do
18
+ it 'should tell the persistor when something is added to an array model' do
19
19
  persistor = double('volt/persistor')
20
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 = Volt::ArrayModel.new([1,2,3], persistor: persistor)
24
+ @model = Volt::ArrayModel.new([1, 2, 3], persistor: persistor)
25
25
 
26
- expect(persistor_instance).to receive(:added).with(4,3)
26
+ expect(persistor_instance).to receive(:added).with(4, 3)
27
27
 
28
28
  @model << 4
29
29
  end
@@ -2,23 +2,20 @@ require 'volt/models'
2
2
 
3
3
  class TestModel < Volt::Model
4
4
  validate :_name, length: 4
5
- validate :_description, length: {message: 'needs to be longer', length: 50}
5
+ validate :_description, length: { message: 'needs to be longer', length: 50 }
6
6
  validate :_username, presence: true
7
7
  end
8
8
 
9
-
10
9
  describe Volt::Model do
11
- it "should validate the name" do
10
+ it 'should validate the name' do
12
11
  expect(TestModel.new.errors).to eq(
13
- {
14
- :_name => ["must be at least 4 characters"],
15
- :_description => ["needs to be longer"],
16
- :_username => ["must be specified"]
17
- }
12
+ _name: ['must be at least 4 characters'],
13
+ _description: ['needs to be longer'],
14
+ _username: ['must be specified']
18
15
  )
19
16
  end
20
17
 
21
- it "should show marked validations once they are marked" do
18
+ it 'should show marked validations once they are marked' do
22
19
  model = TestModel.new
23
20
 
24
21
  expect(model.marked_errors).to eq({})
@@ -26,13 +23,11 @@ describe Volt::Model do
26
23
  model.mark_field!(:_name)
27
24
 
28
25
  expect(model.marked_errors).to eq(
29
- {
30
- :_name => ["must be at least 4 characters"]
31
- }
26
+ _name: ['must be at least 4 characters']
32
27
  )
33
28
  end
34
29
 
35
- it "should show all fields in marked errors once saved" do
30
+ it 'should show all fields in marked errors once saved' do
36
31
  model = TestModel.new
37
32
 
38
33
  expect(model.marked_errors).to eq({})
@@ -42,8 +37,8 @@ describe Volt::Model do
42
37
  expect(model.marked_errors.keys).to eq([:_name, :_description, :_username])
43
38
  end
44
39
 
45
- describe "length" do
46
- it "should allow custom errors on length" do
40
+ describe 'length' do
41
+ it 'should allow custom errors on length' do
47
42
  model = TestModel.new
48
43
 
49
44
  expect(model.marked_errors).to eq({})
@@ -51,15 +46,13 @@ describe Volt::Model do
51
46
  model.mark_field!(:_description)
52
47
 
53
48
  expect(model.marked_errors).to eq(
54
- {
55
- :_description => ["needs to be longer"]
56
- }
49
+ _description: ['needs to be longer']
57
50
  )
58
51
  end
59
52
  end
60
53
 
61
- describe "presence" do
62
- it "should validate presence" do
54
+ describe 'presence' do
55
+ it 'should validate presence' do
63
56
  model = TestModel.new
64
57
 
65
58
  expect(model.marked_errors).to eq({})
@@ -67,9 +60,7 @@ describe Volt::Model do
67
60
  model.mark_field!(:_username)
68
61
 
69
62
  expect(model.marked_errors).to eq(
70
- {
71
- :_username => ["must be specified"]
72
- }
63
+ _username: ['must be specified']
73
64
  )
74
65
  end
75
66
  end
@@ -4,24 +4,23 @@ require 'volt/page/targets/attribute_target'
4
4
  require 'volt/page/targets/dom_section'
5
5
  require 'volt/page/template_renderer'
6
6
 
7
-
8
7
  describe Volt::ContentBinding do
9
- it "should render the content in a content binding" do
8
+ it 'should render the content in a content binding' do
10
9
  dom = Volt::AttributeTarget.new(0)
11
- context = {:name => 'jimmy'}
12
- binding = Volt::ContentBinding.new(nil, dom, context, 0, Proc.new { self[:name] })
10
+ context = { name: 'jimmy' }
11
+ binding = Volt::ContentBinding.new(nil, dom, context, 0, proc { self[:name] })
13
12
 
14
13
  expect(dom.to_html).to eq('jimmy')
15
14
  end
16
15
 
17
- it "should render with a template" do
18
- context = {:name => 'jimmy'}
19
- binding = lambda {|page, target, context, id| Volt::ContentBinding.new(page, target, context, id, Proc.new { self[:name] }) }
16
+ it 'should render with a template' do
17
+ context = { name: 'jimmy' }
18
+ binding = lambda { |page, target, context, id| Volt::ContentBinding.new(page, target, context, id, proc { self[:name] }) }
20
19
 
21
20
  templates = {
22
21
  'main/main' => {
23
22
  'html' => 'hello <!-- $1 --><!-- $/1 -->',
24
- 'bindings' => {1 => [binding]}
23
+ 'bindings' => { 1 => [binding] }
25
24
  }
26
25
  }
27
26
 
@@ -26,28 +26,27 @@ describe Volt::TemplateBinding do
26
26
  $page = nil
27
27
  end
28
28
 
29
- it "should lookup nested controller action" do
29
+ it 'should lookup nested controller action' do
30
30
  @templates = {
31
31
  'main/main/blog/nav' => '',
32
- 'main/comments/new/body' => '',
32
+ 'main/comments/new/body' => ''
33
33
  }
34
34
 
35
35
  result = @template_binding.path_for_template('comments/new').last
36
- expect(result).to eq(['main', 'comments_controller', 'new'])
36
+ expect(result).to eq(%w(main comments_controller new))
37
37
  end
38
38
 
39
- it "it should not look in the local component/controller for a specified controller/action" do
39
+ it 'it should not look in the local component/controller for a specified controller/action' do
40
40
  @templates = {
41
41
  'main/comments/new/body' => ''
42
42
  }
43
43
 
44
44
  path, result = @template_binding.path_for_template('comments/new')
45
45
  expect(path).to eq('main/comments/new/body')
46
- expect(result).to eq(['main', 'comments_controller', 'new'])
46
+ expect(result).to eq(%w(main comments_controller new))
47
47
  end
48
48
 
49
-
50
- it "should handle a tripple lookup" do
49
+ it 'should handle a tripple lookup' do
51
50
  @templates = {
52
51
  'main/comments/new/errors' => '',
53
52
  'comments/new/errors/body' => ''
@@ -58,54 +57,53 @@ describe Volt::TemplateBinding do
58
57
  expect(result).to eq(nil)
59
58
  end
60
59
 
61
- it "should handle a tripple lookup to controllers" do
60
+ it 'should handle a tripple lookup to controllers' do
62
61
  @templates = {
63
62
  'comments/new/errors/body' => ''
64
63
  }
65
64
 
66
65
  path, result = @template_binding.path_for_template('comments/new/errors')
67
66
  expect(path).to eq('comments/new/errors/body')
68
- expect(result).to eq(['comments', 'new_controller', 'errors'])
67
+ expect(result).to eq(%w(comments new_controller errors))
69
68
  end
70
69
 
71
-
72
- it "should find a matching component" do
70
+ it 'should find a matching component' do
73
71
  @templates = {
74
72
  'comments/new/index/body' => ''
75
73
  }
76
74
 
77
75
  path, result = @template_binding.path_for_template('comments/new')
78
76
  expect(path).to eq('comments/new/index/body')
79
- expect(result).to eq(['comments', 'new_controller', 'index'])
77
+ expect(result).to eq(%w(comments new_controller index))
80
78
  end
81
79
 
82
- it "should lookup sub-templates within its own file" do
80
+ it 'should lookup sub-templates within its own file' do
83
81
  @templates = {
84
82
  'main/main/blog/nav' => '',
85
- 'main/main/main/nav' => '',
83
+ 'main/main/main/nav' => ''
86
84
  }
87
85
 
88
86
  expect(@template_binding.path_for_template('nav').first).to eq('main/main/main/nav')
89
87
  end
90
88
 
91
- it "should lookup sub-templates within another local view" do
89
+ it 'should lookup sub-templates within another local view' do
92
90
  @templates = {
93
91
  'main/main/blog/nav' => '',
94
- 'main/main/main/nav' => '',
92
+ 'main/main/main/nav' => ''
95
93
  }
96
94
 
97
95
  expect(@template_binding.path_for_template('blog/nav').first).to eq('main/main/blog/nav')
98
96
  end
99
97
 
100
- it "should lookup in another view" do
98
+ it 'should lookup in another view' do
101
99
  @templates = {
102
- 'main/main/nav/body' => '',
100
+ 'main/main/nav/body' => ''
103
101
  }
104
102
 
105
103
  expect(@template_binding.path_for_template('nav').first).to eq('main/main/nav/body')
106
104
  end
107
105
 
108
- it "should lookup in a controller" do
106
+ it 'should lookup in a controller' do
109
107
  @templates = {
110
108
  'main/nav/index/body' => ''
111
109
  }
@@ -113,7 +111,7 @@ describe Volt::TemplateBinding do
113
111
  expect(@template_binding.path_for_template('nav').first).to eq('main/nav/index/body')
114
112
  end
115
113
 
116
- it "should lookup in a controller/view" do
114
+ it 'should lookup in a controller/view' do
117
115
  @templates = {
118
116
  'main/blog/nav/body' => ''
119
117
  }
@@ -121,7 +119,7 @@ describe Volt::TemplateBinding do
121
119
  expect(@template_binding.path_for_template('blog/nav').first).to eq('main/blog/nav/body')
122
120
  end
123
121
 
124
- it "should lookup in a controller" do
122
+ it 'should lookup in a controller' do
125
123
  @templates = {
126
124
  'main/nav/index/body' => ''
127
125
  }
@@ -129,7 +127,7 @@ describe Volt::TemplateBinding do
129
127
  expect(@template_binding.path_for_template('nav').first).to eq('main/nav/index/body')
130
128
  end
131
129
 
132
- it "should lookup in a component" do
130
+ it 'should lookup in a component' do
133
131
  @templates = {
134
132
  'nav/main/index/body' => ''
135
133
  }
@@ -137,7 +135,7 @@ describe Volt::TemplateBinding do
137
135
  expect(@template_binding.path_for_template('nav').first).to eq('nav/main/index/body')
138
136
  end
139
137
 
140
- it "should lookup in a component/controller/view" do
138
+ it 'should lookup in a component/controller/view' do
141
139
  @templates = {
142
140
  'nav/main/main/body' => '',
143
141
  'auth/login/new/body' => ''
@@ -146,7 +144,7 @@ describe Volt::TemplateBinding do
146
144
  expect(@template_binding.path_for_template('auth/login/new').first).to eq('auth/login/new/body')
147
145
  end
148
146
 
149
- it "should let you force a sub template" do
147
+ it 'should let you force a sub template' do
150
148
  @templates = {
151
149
  'nav/main/index/title' => '',
152
150
  'auth/login/new/title' => ''
@@ -1,8 +1,8 @@
1
1
  require 'volt/page/sub_context'
2
2
 
3
3
  describe Volt::SubContext do
4
- it "should respond_to correctly on locals" do
5
- sub_context = Volt::SubContext.new({:name => 'Name'})
4
+ it 'should respond_to correctly on locals' do
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)
@@ -50,14 +50,14 @@ describe Volt::Computation do
50
50
  end.watch!
51
51
  end.watch!
52
52
 
53
- expect(values).to eq([nil,nil])
53
+ expect(values).to eq([nil, nil])
54
54
 
55
55
  a[1] = 'inner'
56
56
  Volt::Computation.flush!
57
- expect(values).to eq([nil,nil,'inner'])
57
+ expect(values).to eq([nil, nil, 'inner'])
58
58
 
59
59
  a[0] = 'outer'
60
60
  Volt::Computation.flush!
61
- expect(values).to eq([nil,nil,'inner','outer','inner'])
61
+ expect(values).to eq([nil, nil, 'inner', 'outer', 'inner'])
62
62
  end
63
63
  end
@@ -2,13 +2,13 @@ require 'spec_helper'
2
2
  require 'volt/reactive/reactive_array'
3
3
 
4
4
  describe Volt::ReactiveArray do
5
- describe "cells" do
5
+ describe 'cells' do
6
6
  it 'should track dependencies for cells' do
7
7
  a = Volt::ReactiveArray.new
8
8
 
9
9
  count = 0
10
10
  values = []
11
- -> { values << a[0] ; count += 1 }.watch!
11
+ -> { values << a[0]; count += 1 }.watch!
12
12
 
13
13
  a[0] = 5
14
14
 
@@ -24,7 +24,7 @@ describe Volt::ReactiveArray do
24
24
  end
25
25
 
26
26
  it 'should trigger changed on the last cell when appending' do
27
- a = Volt::ReactiveArray.new([1,2,3])
27
+ a = Volt::ReactiveArray.new([1, 2, 3])
28
28
 
29
29
  values = []
30
30
  -> { values << a[3] }.watch!
@@ -39,7 +39,7 @@ describe Volt::ReactiveArray do
39
39
  end
40
40
 
41
41
  it 'should trigger changes for each cell after index after insert' do
42
- a = Volt::ReactiveArray.new([1,2,3])
42
+ a = Volt::ReactiveArray.new([1, 2, 3])
43
43
 
44
44
  values_at_2 = []
45
45
  values_at_3 = []
@@ -52,18 +52,18 @@ describe Volt::ReactiveArray do
52
52
  expect(values_at_3).to eq([nil])
53
53
  expect(values_at_4).to eq([nil])
54
54
 
55
- a.insert(2,1.3,1.7)
55
+ a.insert(2, 1.3, 1.7)
56
56
 
57
57
  Volt::Computation.flush!
58
58
 
59
- expect(values_at_2).to eq([3,1.3])
60
- expect(values_at_3).to eq([nil,1.7])
61
- expect(values_at_4).to eq([nil,3])
59
+ expect(values_at_2).to eq([3, 1.3])
60
+ expect(values_at_3).to eq([nil, 1.7])
61
+ expect(values_at_4).to eq([nil, 3])
62
62
 
63
63
  end
64
64
  end
65
65
 
66
- describe "size dependencies" do
66
+ describe 'size dependencies' do
67
67
  it 'pushing should trigger changed for size' do
68
68
  array = Volt::ReactiveArray.new
69
69
  count = 0
@@ -76,11 +76,11 @@ describe Volt::ReactiveArray do
76
76
  array << 5
77
77
 
78
78
  Volt::Computation.flush!
79
- expect(size_values).to eq([0,1])
79
+ expect(size_values).to eq([0, 1])
80
80
  end
81
81
 
82
82
  it 'should trigger a size change when deleting' do
83
- array = Volt::ReactiveArray.new([1,2,3])
83
+ array = Volt::ReactiveArray.new([1, 2, 3])
84
84
 
85
85
  size_values = []
86
86
  -> { size_values << array.size }.watch!
@@ -91,7 +91,7 @@ describe Volt::ReactiveArray do
91
91
 
92
92
  expect(size_values).to eq([3])
93
93
  Volt::Computation.flush!
94
- expect(size_values).to eq([3,2])
94
+ expect(size_values).to eq([3, 2])
95
95
  end
96
96
  end
97
97
  end
@@ -7,17 +7,17 @@ def routes(&block)
7
7
  end
8
8
 
9
9
  describe Volt::Routes do
10
- it "should setup direct routes" do
10
+ it 'should setup direct routes' do
11
11
  routes do
12
12
  get '/', _view: 'index'
13
13
  get '/page1', _view: 'first_page'
14
14
  end
15
15
 
16
16
  direct_routes = @routes.instance_variable_get(:@direct_routes)
17
- expect(direct_routes).to eq({"/" => {:_view => "index"}, "/page1" => {:_view => "first_page"}})
17
+ expect(direct_routes).to eq('/' => { _view: 'index' }, '/page1' => { _view: 'first_page' })
18
18
  end
19
19
 
20
- it "should setup indiect routes" do
20
+ it 'should setup indiect routes' do
21
21
  routes do
22
22
  get '/blog/{{ _id }}/edit', _view: 'blog/edit'
23
23
  get '/blog/{{ _id }}', _view: 'blog/show'
@@ -25,22 +25,20 @@ describe Volt::Routes do
25
25
 
26
26
  indirect_routes = @routes.instance_variable_get(:@indirect_routes)
27
27
  expect(indirect_routes).to eq(
28
- {
29
- "blog" => {
30
- "*" => {
31
- "edit" => {
32
- nil => {:_view => "blog/edit", :_id => 1}
33
- },
34
- nil => {:_view => "blog/show", :_id => 1}
35
- }
28
+ 'blog' => {
29
+ '*' => {
30
+ 'edit' => {
31
+ nil => { _view: 'blog/edit', _id: 1 }
32
+ },
33
+ nil => { _view: 'blog/show', _id: 1 }
36
34
  }
37
35
  }
38
36
  )
39
37
  end
40
38
 
41
- it "should match routes" do
39
+ it 'should match routes' do
42
40
  routes do
43
- get "/blog", _view: 'blog'
41
+ get '/blog', _view: 'blog'
44
42
  get '/blog/{{ _id }}', _view: 'blog/show'
45
43
  get '/blog/{{ _id }}/draft', _view: 'blog/draft', _action: 'draft'
46
44
  get '/blog/{{ _id }}/edit', _view: 'blog/edit'
@@ -49,31 +47,31 @@ describe Volt::Routes do
49
47
  end
50
48
 
51
49
  params = @routes.url_to_params('/blog')
52
- expect(params).to eq({:_view => "blog"})
50
+ expect(params).to eq(_view: 'blog')
53
51
 
54
52
  params = @routes.url_to_params('/blog/55/edit')
55
- expect(params).to eq({:_view => "blog/edit", :_id => "55"})
53
+ expect(params).to eq(_view: 'blog/edit', _id: '55')
56
54
 
57
55
  params = @routes.url_to_params('/blog/55')
58
- expect(params).to eq({:_view => "blog/show", :_id => "55"})
56
+ expect(params).to eq(_view: 'blog/show', _id: '55')
59
57
 
60
58
  params = @routes.url_to_params('/blog/tags/good')
61
- expect(params).to eq({:_view => "blog/tag", :_tag => "good"})
59
+ expect(params).to eq(_view: 'blog/tag', _tag: 'good')
62
60
 
63
61
  params = @routes.url_to_params('/blog/55/draft')
64
- expect(params).to eq({:_view => "blog/draft", :_id => "55", :_action => "draft"})
62
+ expect(params).to eq(_view: 'blog/draft', _id: '55', _action: 'draft')
65
63
 
66
64
  params = @routes.url_to_params('/login/jim/user/10')
67
- expect(params).to eq({:_view => "login", :_action => "user", :_name => "jim", :_id => "10"})
65
+ expect(params).to eq(_view: 'login', _action: 'user', _name: 'jim', _id: '10')
68
66
 
69
67
  params = @routes.url_to_params('/login/cool')
70
68
  expect(params).to eq(false)
71
69
 
72
70
  end
73
71
 
74
- it "should setup param matchers" do
72
+ it 'should setup param matchers' do
75
73
  routes do
76
- get "/blog", _view: 'blog'
74
+ get '/blog', _view: 'blog'
77
75
  get '/blog/{{ _id }}', _view: 'blog/show'
78
76
  get '/blog/{{ _id }}/edit', _view: 'blog/edit'
79
77
  get '/blog/tags/{{ _tag }}', _view: 'blog/tag'
@@ -81,68 +79,67 @@ describe Volt::Routes do
81
79
  end
82
80
 
83
81
  param_matches = @routes.instance_variable_get(:@param_matches)
84
- expect(param_matches.map {|v| v[0] }).to eq([
85
- {:_view => "blog"},
86
- {:_view => "blog/show", :_id => nil},
87
- {:_view => "blog/edit", :_id => nil},
88
- {:_view => "blog/tag", :_tag => nil},
89
- {:_view => "login", :_action => "user",:_name => nil, :_id => nil}
82
+ expect(param_matches.map { |v| v[0] }).to eq([
83
+ { _view: 'blog' },
84
+ { _view: 'blog/show', _id: nil },
85
+ { _view: 'blog/edit', _id: nil },
86
+ { _view: 'blog/tag', _tag: nil },
87
+ { _view: 'login', _action: 'user', _name: nil, _id: nil }
90
88
  ])
91
89
 
92
90
  end
93
91
 
94
- it "should go from params to url" do
92
+ it 'should go from params to url' do
95
93
  routes do
96
- get "/blog", _view: 'blog'
94
+ get '/blog', _view: 'blog'
97
95
  get '/blog/{{ _id }}', _view: 'blog/show'
98
96
  get '/blog/{{ _id }}/edit', _view: 'blog/edit'
99
97
  get '/blog/tags/{{ _tag }}', _view: 'blog/tag'
100
98
  get '/login/{{ _name }}/user/{{ _id }}', _view: 'login', _action: 'user'
101
99
  end
102
100
 
103
- url, params = @routes.params_to_url({view: 'blog/show', id: '55'})
101
+ url, params = @routes.params_to_url(view: 'blog/show', id: '55')
104
102
  expect(url).to eq('/blog/55')
105
103
  expect(params).to eq({})
106
104
 
107
-
108
- url, params = @routes.params_to_url({view: 'blog/edit', id: '100'})
105
+ url, params = @routes.params_to_url(view: 'blog/edit', id: '100')
109
106
  expect(url).to eq('/blog/100/edit')
110
107
  expect(params).to eq({})
111
108
 
112
- url, params = @routes.params_to_url({view: 'blog/edit', id: '100', other: 'should_pass'})
109
+ url, params = @routes.params_to_url(view: 'blog/edit', id: '100', other: 'should_pass')
113
110
  expect(url).to eq('/blog/100/edit')
114
- expect(params).to eq({_other: 'should_pass'})
111
+ expect(params).to eq(_other: 'should_pass')
115
112
  end
116
113
 
117
- it "should test that params match a param matcher" do
114
+ it 'should test that params match a param matcher' do
118
115
  routes = Volt::Routes.new
119
- match, params = routes.send(:check_params_match, {_view: 'blog', _id: '55'}, {_view: 'blog', _id: nil})
116
+ match, params = routes.send(:check_params_match, { _view: 'blog', _id: '55' }, _view: 'blog', _id: nil)
120
117
  expect(match).to eq(true)
121
- expect(params).to eq({_id: '55'})
118
+ expect(params).to eq(_id: '55')
122
119
 
123
- match, params = routes.send(:check_params_match, {_view: 'blog', _id: '55'}, {_view: 'blog', _id: '20'})
120
+ match, params = routes.send(:check_params_match, { _view: 'blog', _id: '55' }, _view: 'blog', _id: '20')
124
121
  expect(match).to eq(false)
125
122
 
126
- match, params = routes.send(:check_params_match, {_view: 'blog', _name: {_title: 'Mr', _name: 'Bob'}, _id: '55'}, {_view: 'blog', _id: nil, _name: {_title: 'Mr', _name: nil}})
123
+ match, params = routes.send(:check_params_match, { _view: 'blog', _name: { _title: 'Mr', _name: 'Bob' }, _id: '55' }, _view: 'blog', _id: nil, _name: { _title: 'Mr', _name: nil })
127
124
  expect(match).to eq(true)
128
- expect(params).to eq({_id: '55'})
125
+ expect(params).to eq(_id: '55')
129
126
 
130
127
  # Check with an extra value _name._name
131
- match, params = routes.send(:check_params_match, {_view: 'blog', _name: {_title: 'Mr', _name: 'Bob'}, _id: '55'}, {_view: 'blog', _id: nil, _name: {_title: 'Mr'}})
128
+ match, params = routes.send(:check_params_match, { _view: 'blog', _name: { _title: 'Mr', _name: 'Bob' }, _id: '55' }, _view: 'blog', _id: nil, _name: { _title: 'Mr' })
132
129
  expect(match).to eq(true)
133
- expect(params).to eq({_id: '55'})
130
+ expect(params).to eq(_id: '55')
134
131
 
135
- match, params = routes.send(:check_params_match, {_view: 'blog', _name: {_title: 'Mr', _name: 'Bob'}, _id: '55'}, {_view: 'blog', _id: nil, _name: {_title: 'Phd'}})
132
+ match, params = routes.send(:check_params_match, { _view: 'blog', _name: { _title: 'Mr', _name: 'Bob' }, _id: '55' }, _view: 'blog', _id: nil, _name: { _title: 'Phd' })
136
133
  expect(match).to eq(false)
137
134
 
138
135
  # Check to make sure extra values in the params pass it.
139
- match, params = routes.send(:check_params_match, {_view: 'blog', _id: '55', _extra: 'some value'}, {_view: 'blog', _id: '55'})
136
+ match, params = routes.send(:check_params_match, { _view: 'blog', _id: '55', _extra: 'some value' }, _view: 'blog', _id: '55')
140
137
  expect(match).to eq(true)
141
- expect(params).to eq({_extra: 'some value'})
138
+ expect(params).to eq(_extra: 'some value')
142
139
 
143
140
  end
144
141
 
145
- it "should match routes" do
142
+ it 'should match routes' do
146
143
  params = Volt::Model.new({}, persistor: Volt::Persistors::Params)
147
144
  params._controller = 'blog'
148
145
  params._index = '5'
@@ -154,10 +151,10 @@ describe Volt::Routes do
154
151
 
155
152
  path, cleaned_params = @routes.params_to_url(params.to_h)
156
153
  expect(path).to eq('/blog')
157
- expect(cleaned_params).to eq({_index: '5'})
154
+ expect(cleaned_params).to eq(_index: '5')
158
155
  end
159
156
 
160
- it "should handle routes with bindings in them" do
157
+ it 'should handle routes with bindings in them' do
161
158
  params = Volt::Model.new({}, persistor: Volt::Persistors::Params)
162
159
 
163
160
  routes do