hyper-mesh 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +7 -2
  4. data/README.md +112 -87
  5. data/Rakefile +6 -1
  6. data/docs/action_cable_quickstart.md +20 -16
  7. data/docs/activerecord_api.md +23 -17
  8. data/docs/authorization-policies.md +45 -35
  9. data/docs/client_side_scoping.md +5 -5
  10. data/docs/configuration_details.md +6 -46
  11. data/docs/pusher_faker_quickstart.md +7 -68
  12. data/docs/pusher_quickstart.md +7 -68
  13. data/docs/simple_poller_quickstart.md +6 -67
  14. data/docs/todo-example.md +2 -2
  15. data/docs/word_game.md +3 -1
  16. data/docs/words-example.md +2 -3
  17. data/examples/action-cable/Gemfile +2 -1
  18. data/examples/action-cable/Gemfile.lock +73 -54
  19. data/examples/action-cable/config/initializers/{hyper_mesh.rb → hyperloop.rb} +1 -1
  20. data/examples/action-cable/config/routes.rb +1 -1
  21. data/hyper-mesh.gemspec +10 -4
  22. data/lib/active_record_base.rb +3 -3
  23. data/{examples/action-cable-production-mode/log/.keep → lib/acts_as_string.rb} +0 -0
  24. data/lib/hyper-mesh.rb +11 -19
  25. data/lib/hyper_mesh/version.rb +3 -0
  26. data/lib/hypermesh/version.rb +1 -1
  27. data/lib/reactive_record/active_record/class_methods.rb +10 -3
  28. data/lib/reactive_record/active_record/instance_methods.rb +8 -0
  29. data/lib/reactive_record/active_record/public_columns_hash.rb +8 -2
  30. data/lib/reactive_record/active_record/reactive_record/collection.rb +0 -1
  31. data/lib/reactive_record/active_record/reactive_record/dummy_value.rb +2 -1
  32. data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +55 -63
  33. data/lib/reactive_record/active_record/reactive_record/operations.rb +51 -0
  34. data/lib/reactive_record/active_record/reactive_record/reactive_set_relationship_helpers.rb +3 -3
  35. data/lib/reactive_record/active_record/reactive_record/while_loading.rb +93 -84
  36. data/lib/reactive_record/broadcast.rb +183 -0
  37. data/lib/reactive_record/permissions.rb +2 -2
  38. data/reactive_record_test_app/Gemfile +6 -2
  39. data/reactive_record_test_app/Gemfile.lock +120 -60
  40. data/reactive_record_test_app/app/assets/javascripts/application.rb +3 -5
  41. data/reactive_record_test_app/app/assets/javascripts/bigdecimal.rb +1 -0
  42. data/reactive_record_test_app/app/assets/javascripts/reactive_record_config.js +2 -2
  43. data/reactive_record_test_app/app/controllers/application_controller.rb +3 -3
  44. data/reactive_record_test_app/app/controllers/home_controller.rb +1 -1
  45. data/reactive_record_test_app/app/models/models.rb.erb +6 -0
  46. data/reactive_record_test_app/config/application.rb +2 -0
  47. data/reactive_record_test_app/config/environments/development.rb +1 -1
  48. data/reactive_record_test_app/config/routes.rb +1 -2
  49. data/reactive_record_test_app/db/seeds.rb +6 -0
  50. data/reactive_record_test_app/script/rails +0 -0
  51. data/reactive_record_test_app/spec-opal/active-record/rendering_spec.rb +11 -2
  52. data/reactive_record_test_app/spec-opal/active-record/save_spec.rb +3 -4
  53. data/reactive_record_test_app/spec-opal/spec_helper.js.rb +1 -1
  54. data/reactive_record_test_app/spec-opal/test_spec.rb +7 -0
  55. data/reactive_record_test_app/spec_dont_run/README.md +7 -0
  56. data/reactive_record_test_app/{spec-opal/active-record → spec_dont_run/active_record_broken}/permissions_spec.rb +0 -0
  57. data/reactive_record_test_app/{spec-opal/active-record → spec_dont_run/active_record_broken}/prerendering_spec.rb +1 -0
  58. data/spec/{synchromesh/aaa-unit_tests/connection_spec.rb → batch1/aaa-unit_tests/connection_movedspec.rb} +0 -0
  59. data/spec/{synchromesh → batch1}/aaa-unit_tests/dummy_value_spec.rb +2 -2
  60. data/spec/{synchromesh → batch1}/column_types/column_type_spec.rb +2 -2
  61. data/spec/{synchromesh → batch1}/crud_access_regulation/broadcast_controls_access_spec.rb +1 -1
  62. data/spec/{synchromesh → batch1}/crud_access_regulation/model_policies_spec.rb +6 -6
  63. data/spec/batch1/misc/access_like_hash_spec.rb +43 -0
  64. data/spec/batch1/misc/while_loading_spec.rb +196 -0
  65. data/spec/{synchromesh → batch1}/policies/regulate_all_broadcasts_spec.rb +12 -12
  66. data/spec/{synchromesh → batch1}/policies/regulate_broadcast_spec.rb +25 -25
  67. data/spec/{synchromesh/integration → batch2}/authorization_spec.rb +8 -7
  68. data/spec/{synchromesh/integration → batch2}/default_scope_spec.rb +2 -2
  69. data/spec/{synchromesh/integration → batch2}/has_many_through_spec.rb +2 -2
  70. data/spec/{synchromesh/integration → batch2}/relationships_spec.rb +3 -3
  71. data/spec/{reactive_record → batch3}/auto_load_itself_spec.rb +1 -1
  72. data/spec/{reactive_record → batch3}/edge_cases_spec.rb +1 -1
  73. data/spec/{reactive_record → batch3}/finder_method_spec.rb +1 -1
  74. data/spec/{reactive_record → batch3}/many_to_many_spec.rb +2 -2
  75. data/spec/{reactive_record → batch3}/pry_rescue_xspec.rb +0 -0
  76. data/{examples/action-cable-production-mode/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css → spec/batch3/readme.txt} +0 -0
  77. data/spec/{reactive_record → batch3}/revert_spec.rb +2 -2
  78. data/spec/{reactive_record → batch3}/save_while_loading_spec.rb +1 -1
  79. data/spec/{reactive_record → batch3}/update_associations_spec.rb +2 -2
  80. data/spec/{reactive_record → batch3}/update_scopes_spec.rb +2 -2
  81. data/spec/{synchromesh/integration → batch4}/saving_during_commit_spec.rb +2 -2
  82. data/spec/{synchromesh/integration → batch4}/scope_spec.rb +30 -2
  83. data/spec/{synchromesh/examples → batch4}/scoped_todos_spec.rb +3 -3
  84. data/spec/{synchromesh/integration → batch4}/synchromesh_spec.rb +2 -2
  85. data/spec/{synchromesh/examples → examples}/dictionary.rb +2 -2
  86. data/spec/{synchromesh/examples → examples}/dictionary_with_client_scopes.rb +2 -2
  87. data/spec/{synchromesh/examples → examples}/random_examples.rb +1 -1
  88. data/spec/{reactive_record/play.rb → play_ground.rb} +0 -0
  89. data/spec/{reactive_record/factory.rb → reactive_record_factory.rb} +0 -0
  90. data/spec/spec_helper.rb +3 -2
  91. data/spec/test_app/Gemfile +8 -3
  92. data/spec/test_app/Gemfile.lock +114 -64
  93. data/spec/test_app/app/views/components.rb +1 -2
  94. data/spec/test_app/config/application.rb +2 -0
  95. data/spec/test_app/config/routes.rb +1 -1
  96. data/spec/{synchromesh/integration/test_components.rb → test_components.rb} +0 -0
  97. metadata +144 -137
  98. data/app/controllers/reactive_record/application_controller.rb +0 -4
  99. data/app/controllers/reactive_record/reactive_record_controller.rb +0 -49
  100. data/config/routes.rb +0 -7
  101. data/examples/action-cable-production-mode/public/assets/application-90043e04e9e784054fd08159fa7aafe5e23d3ffb31584b1bea1e47043c9cfb5a.js +0 -50
  102. data/examples/action-cable-production-mode/public/assets/application-90043e04e9e784054fd08159fa7aafe5e23d3ffb31584b1bea1e47043c9cfb5a.js.gz +0 -0
  103. data/examples/action-cable-production-mode/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz +0 -0
  104. data/examples/action-cable-production-mode/tmp/.keep +0 -0
  105. data/examples/action-cable/log/.keep +0 -0
  106. data/examples/action-cable/tmp/.keep +0 -0
  107. data/examples/pusher-fake/log/.keep +0 -0
  108. data/examples/pusher-fake/tmp/.keep +0 -0
  109. data/examples/pusher/log/.keep +0 -0
  110. data/examples/pusher/tmp/.keep +0 -0
  111. data/examples/simple-poller/log/.keep +0 -0
  112. data/examples/simple-poller/tmp/.keep +0 -0
  113. data/examples/word-game/log/.keep +0 -0
  114. data/examples/word-game/tmp/.keep +0 -0
  115. data/examples/words/log/.keep +0 -0
  116. data/examples/words/tmp/.keep +0 -0
  117. data/lib/reactive_record/version.rb +0 -3
  118. data/lib/sources/hyper-mesh/pusher.js +0 -98
  119. data/lib/synchromesh/action_cable.rb +0 -39
  120. data/lib/synchromesh/client_drivers.rb +0 -357
  121. data/lib/synchromesh/configuration.rb +0 -40
  122. data/lib/synchromesh/connection.rb +0 -170
  123. data/lib/synchromesh/policy.rb +0 -504
  124. data/lib/synchromesh/synchromesh.rb +0 -159
  125. data/lib/synchromesh/synchromesh_controller.rb +0 -162
  126. data/reactive_record_test_app/README.rdoc +0 -261
  127. data/reactive_record_test_app/app/assets/javascripts/components/another_component.rb +0 -24
  128. data/reactive_record_test_app/app/assets/javascripts/components/empty_component.rb +0 -6
  129. data/reactive_record_test_app/app/assets/javascripts/components/todo_item_component.js.rb +0 -16
  130. data/reactive_record_test_app/app/assets/javascripts/components/todos_component.js.rb +0 -42
  131. data/reactive_record_test_app/app/assets/javascripts/components/todos_main_component.rb +0 -49
  132. data/reactive_record_test_app/app/assets/javascripts/react_js_test_only.js +0 -21618
  133. data/reactive_record_test_app/app/assets/javascripts/spec/reactive_record_xspec.js.rb +0 -42
  134. data/reactive_record_test_app/app/controllers/test_controller.rb +0 -7
  135. data/reactive_record_test_app/app/mailers/.gitkeep +0 -0
  136. data/reactive_record_test_app/app/models/models.rb +0 -1
  137. data/reactive_record_test_app/app/policies/application_policy.rb +0 -5
  138. data/reactive_record_test_app/app/views/components.rb +0 -4
  139. data/reactive_record_test_app/app/views/components/test.rb +0 -18
  140. data/reactive_record_test_app/app/views/home/index.html.erb +0 -1
  141. data/reactive_record_test_app/app/views/layouts/application.html.erb +0 -17
  142. data/reactive_record_test_app/config/environments/production.rb +0 -70
  143. data/reactive_record_test_app/config/environments/test.rb +0 -41
  144. data/spec/synchromesh/integration/transports_spec.rb +0 -308
  145. data/spec/synchromesh/policies/auto_connect_spec.rb +0 -60
  146. data/spec/synchromesh/policies/auto_loader_spec.rb +0 -34
  147. data/spec/synchromesh/policies/policy_methods_spec.rb +0 -85
  148. data/spec/synchromesh/policies/regulate_class_connection_spec.rb +0 -50
  149. data/spec/synchromesh/policies/regulate_instance_connection_spec.rb +0 -66
  150. data/spec/test_app/log/.keep +0 -0
@@ -27,7 +27,7 @@ describe "simple record update and save" do
27
27
  mitch = User.find_by_email("mitch@catprint.com")
28
28
  mitch.first_name = "Mitchell"
29
29
  expect(mitch.first_name).to eq("Mitchell")
30
- end
30
+ end # TODO this was broken
31
31
 
32
32
  it "and the attribute will be marked as changed"do
33
33
  expect(User.find_by_email("mitch@catprint.com")).to be_changed
@@ -40,7 +40,7 @@ describe "simple record update and save" do
40
40
 
41
41
  it "after saving changed? will be false" do
42
42
  expect(User.find_by_email("mitch@catprint.com")).not_to be_changed
43
- end
43
+ end # TODO this was broken
44
44
 
45
45
  it "after saving saving? will be false" do
46
46
  expect(User.find_by_email("mitch@catprint.com")).not_to be_saving
@@ -53,7 +53,7 @@ describe "simple record update and save" do
53
53
  end.then do |first_name|
54
54
  expect(first_name).to eq("Mitchell")
55
55
  end
56
- end
56
+ end # TODO this was broken
57
57
 
58
58
  it "after saving within the block saving? will be false" do
59
59
  mitchell = User.find_by_email("mitch@catprint.com")
@@ -121,5 +121,4 @@ describe "simple record update and save" do
121
121
  expect(mitch).to be_changed
122
122
  end
123
123
  end
124
-
125
124
  end
@@ -2,13 +2,13 @@ require 'opal'
2
2
  require 'opal-rspec'
3
3
  require 'reactive_record_config'
4
4
  require 'react' #_js_test_only'
5
+ require 'hyper-operation'
5
6
  require 'hyper-mesh'
6
7
  require 'jquery'
7
8
  require 'opal-jquery'
8
9
  require 'jquery.cookie'
9
10
  require 'models'
10
11
 
11
-
12
12
  Document.ready? do
13
13
  `$.cookie('acting_user', null, { path: '/' })`
14
14
  Opal::RSpec::Runner.autorun rescue nil
@@ -0,0 +1,7 @@
1
+
2
+ require 'spec_helper'
3
+ describe "a tests" do
4
+ it "can pass" do
5
+ expect(true).to be(true)
6
+ end
7
+ end
@@ -24,3 +24,10 @@ the server updates properly, is the way to go.
24
24
 
25
25
  Consult the existing specs in the spec/reactive_record directory and compare them to the
26
26
  old style files stored in `reactive_record_test_app/test/spec_dont_run/moved_to_main_spec_dir`.
27
+
28
+
29
+ Note: Permissions is superceeded by a different set of tests in the main test spec directory
30
+ however the old tests are there in case somebody has a chance to go through and make sure
31
+ everything is covered.
32
+
33
+ Note: Prerendering has not been formally tested... Probably should be its just a bit difficult.
@@ -8,6 +8,7 @@ describe "prerendering" do
8
8
  expect(User.find_by_email("mitch@catprint.com").id).not_to eq(1)
9
9
  end
10
10
 
11
+ # THIS IS FAILING BECAUSE WE ARE TRYING TO GRAB BROwSER DURING PRERENDERING
11
12
  async "preloaded the records" do
12
13
  `window.ClientSidePrerenderDataInterface.ReactiveRecordInitialData = undefined` rescue nil
13
14
  container = Element[Document.body].append('<div></div>').children.last
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
- require 'synchromesh/integration/test_components'
3
- require 'reactive_record/factory'
2
+ require 'test_components'
3
+ require 'reactive_record_factory'
4
4
  require 'rspec-steps'
5
5
 
6
6
  RSpec::Steps.steps 'DummyValue', js: true do
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'synchromesh/integration/test_components'
2
+ require 'test_components'
3
3
  require 'rspec-steps'
4
4
 
5
5
  describe "column types on client", js: true do
@@ -59,7 +59,7 @@ describe "column types on client", js: true do
59
59
  Pusher.secret = "MY_TEST_SECRET"
60
60
  require "pusher-fake/support/base"
61
61
 
62
- HyperMesh.configuration do |config|
62
+ Hyperloop.configuration do |config|
63
63
  config.transport = :pusher
64
64
  config.channel_prefix = "synchromesh"
65
65
  config.opts = {app_id: Pusher.app_id, key: Pusher.key, secret: Pusher.secret}.merge(PusherFake.configuration.web_options)
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'synchromesh/integration/test_components'
2
+ require 'test_components'
3
3
 
4
4
  describe "regulate access allowed" do
5
5
 
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'synchromesh/integration/test_components'
2
+ require 'test_components'
3
3
 
4
4
  describe "regulate access allowed" do
5
5
 
@@ -14,7 +14,7 @@ describe "regulate access allowed" do
14
14
  after(:each) do
15
15
  class ActiveRecord::Base
16
16
  def view_permitted?(attribute)
17
- HyperMesh::InternalPolicy.accessible_attributes_for(self, acting_user).include? attribute.to_sym
17
+ Hyperloop::InternalPolicy.accessible_attributes_for(self, acting_user).include? attribute.to_sym
18
18
  end
19
19
  [:create, :update, :destroy].each do |access|
20
20
  define_method("#{access}_permitted?".to_sym) { false }
@@ -22,7 +22,7 @@ describe "regulate access allowed" do
22
22
  end
23
23
  end
24
24
 
25
- HyperMesh::InternalClassPolicy::CHANGE_POLICIES.each do |policy|
25
+ Hyperloop::InternalClassPolicy::CHANGE_POLICIES.each do |policy|
26
26
 
27
27
  it "will define a basic allow_#{policy} policy" do
28
28
  stub_const 'DummyModelPolicy', Class.new
@@ -60,7 +60,7 @@ describe "regulate access allowed" do
60
60
  DummyModelPolicy.class_eval do
61
61
  send("allow_change") { "called change" }
62
62
  end
63
- HyperMesh::InternalClassPolicy::CHANGE_POLICIES.each do |policy|
63
+ Hyperloop::InternalClassPolicy::CHANGE_POLICIES.each do |policy|
64
64
  DummyModel.new.send("#{policy}_permitted?").should eq("called change")
65
65
  end
66
66
  end
@@ -70,7 +70,7 @@ describe "regulate access allowed" do
70
70
  ApplicationPolicy.class_eval do
71
71
  send("allow_change", DummyModel) { "called change" }
72
72
  end
73
- HyperMesh::InternalClassPolicy::CHANGE_POLICIES.each do |policy|
73
+ Hyperloop::InternalClassPolicy::CHANGE_POLICIES.each do |policy|
74
74
  DummyModel.new.send("#{policy}_permitted?").should eq("called change")
75
75
  end
76
76
  end
@@ -84,7 +84,7 @@ describe "regulate access allowed" do
84
84
  FooModel.class_eval do
85
85
  self.table_name = 'test_models'
86
86
  end
87
- HyperMesh::InternalClassPolicy::CHANGE_POLICIES.each do |policy|
87
+ Hyperloop::InternalClassPolicy::CHANGE_POLICIES.each do |policy|
88
88
  DummyModel.new.send("#{policy}_permitted?").should eq("called change on DummyModel")
89
89
  FooModel.new.send("#{policy}_permitted?").should eq("called change on FooModel")
90
90
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'test_components'
3
+ require 'rspec-steps'
4
+
5
+
6
+ RSpec::Steps.steps "access like a hash", js: true do
7
+
8
+ before(:step) do
9
+ # spec_helper resets the policy system after each test so we have to setup
10
+ # before each test
11
+ stub_const 'TestApplication', Class.new
12
+ stub_const 'TestApplicationPolicy', Class.new
13
+ TestApplicationPolicy.class_eval do
14
+ always_allow_connection
15
+ regulate_all_broadcasts { |policy| policy.send_all }
16
+ allow_change(to: :all, on: [:create, :update, :destroy]) { true }
17
+ end
18
+ size_window(:small, :portrait)
19
+ FactoryGirl.create(:user, first_name: 'Lily', last_name: 'DaDog')
20
+ end
21
+
22
+ it "can access attributes using the [] operator" do
23
+ expect_promise do
24
+ HyperMesh.load do
25
+ User.find_by_first_name('Lily')
26
+ end.then do |lily|
27
+ lily[:first_name]
28
+ end
29
+ end.to eq('Lily')
30
+ end
31
+
32
+ it "can update attributes using the []= operator" do
33
+ expect_promise do
34
+ HyperMesh.load do
35
+ User.find_by_first_name('Lily')
36
+ end.then do |lily|
37
+ lily[:last_name] = 'DerDog'
38
+ lily.save
39
+ end
40
+ end.to be_truthy
41
+ expect(User.find_by_first_name('Lily')[:last_name]).to eq('DerDog')
42
+ end
43
+ end
@@ -0,0 +1,196 @@
1
+ require 'spec_helper'
2
+ require 'test_components'
3
+ require 'rspec-steps'
4
+
5
+
6
+ describe "while loading", js: true do
7
+
8
+ before(:all) do
9
+ class ReactiveRecord::Operations::Fetch < Hyperloop::ServerOp
10
+ def self.semaphore
11
+ @semaphore ||= Mutex.new
12
+ end
13
+ validate { self.class.semaphore.synchronize { true } }
14
+ end
15
+ require 'pusher'
16
+ require 'pusher-fake'
17
+ Pusher.app_id = "MY_TEST_ID"
18
+ Pusher.key = "MY_TEST_KEY"
19
+ Pusher.secret = "MY_TEST_SECRET"
20
+ require "pusher-fake/support/base"
21
+
22
+ Hyperloop.configuration do |config|
23
+ config.transport = :pusher
24
+ config.channel_prefix = "synchromesh"
25
+ config.opts = {app_id: Pusher.app_id, key: Pusher.key, secret: Pusher.secret}.merge(PusherFake.configuration.web_options)
26
+ end
27
+ end
28
+ before(:each) do
29
+ # spec_helper resets the policy system after each test so we have to setup
30
+ # before each test
31
+ stub_const 'TestApplication', Class.new
32
+ stub_const 'TestApplicationPolicy', Class.new
33
+ TestApplicationPolicy.class_eval do
34
+ always_allow_connection
35
+ regulate_all_broadcasts { |policy| policy.send_all }
36
+ allow_change(to: :all, on: [:create, :update, :destroy]) { true }
37
+ end
38
+ size_window(:small, :portrait)
39
+ FactoryGirl.create(:user, first_name: 'Lily', last_name: 'DaDog')
40
+
41
+ end
42
+
43
+ it "will display the while loading message" do
44
+ ReactiveRecord::Operations::Fetch.semaphore.synchronize do
45
+ mount "WhileLoadingTester", {}, no_wait: true do
46
+ class MyNestedGuy < Hyperloop::Component
47
+ render(SPAN) do
48
+ User.find_by_first_name('Lily').last_name
49
+ end
50
+ end
51
+ class WhileLoadingTester < Hyperloop::Component
52
+ render do
53
+ DIV do
54
+ MyNestedGuy {}
55
+ end.while_loading do
56
+ SPAN { 'loading...' }
57
+ end
58
+ end
59
+ end
60
+ end
61
+ expect(page).to have_content('loading...')
62
+ expect(page).not_to have_content('DaDog', wait: 0)
63
+ end
64
+ expect(page).to have_content('DaDog')
65
+ expect(page).not_to have_content('loading...', wait: 0)
66
+ end
67
+
68
+ it "loading and loaded blocks can return strings" do
69
+ ReactiveRecord::Operations::Fetch.semaphore.synchronize do
70
+ mount "WhileLoadingTester", {}, no_wait: true do
71
+ class WhileLoadingTester < Hyperloop::Component
72
+ render do
73
+ DIV do
74
+ User.find_by_first_name('Lily').last_name
75
+ end.while_loading do
76
+ 'loading...'
77
+ end
78
+ end
79
+ end
80
+ end
81
+ expect(page).to have_content('loading...')
82
+ expect(page).not_to have_content('DaDog', wait: 0)
83
+ sleep 1
84
+ end
85
+ expect(page).to have_content('DaDog')
86
+ expect(page).not_to have_content('loading...', wait: 0)
87
+ sleep 1
88
+ end
89
+
90
+ it "The inner most while_loading will display only" do
91
+ ReactiveRecord::Operations::Fetch.semaphore.synchronize do
92
+ mount "WhileLoadingTester", {}, no_wait: true do
93
+ class MyNestedGuy < Hyperloop::Component
94
+ render do
95
+ DIV { User.find_by_first_name('Lily').last_name }
96
+ .while_loading { SPAN { 'loading...' } }
97
+ end
98
+ end
99
+ class WhileLoadingTester < Hyperloop::Component
100
+ render do
101
+ DIV do
102
+ MyNestedGuy {}
103
+ end.while_loading do
104
+ SPAN { 'i should not display' }
105
+ end
106
+ end
107
+ end
108
+ end
109
+ expect(page).to have_content('loading...')
110
+ expect(page).not_to have_content('DaDog', wait: 0)
111
+ end
112
+ expect(page).to have_content('DaDog')
113
+ expect(page).not_to have_content('loading...', wait: 0)
114
+ end
115
+
116
+ it "while loading can take a string param instead of a block" do
117
+ ReactiveRecord::Operations::Fetch.semaphore.synchronize do
118
+ mount "WhileLoadingTester", {}, no_wait: true do
119
+ class WhileLoadingTester < Hyperloop::Component
120
+ render do
121
+ DIV do
122
+ User.find_by_first_name('Lily').last_name
123
+ end
124
+ .while_loading 'loading...'
125
+ end
126
+ end
127
+ end
128
+ expect(page).to have_content('loading...')
129
+ expect(page).not_to have_content('DaDog', wait: 0)
130
+ end
131
+ expect(page).to have_content('DaDog')
132
+ expect(page).not_to have_content('loading...', wait: 0)
133
+ end
134
+
135
+ it "while loading can take an element param instead of a block" do
136
+ ReactiveRecord::Operations::Fetch.semaphore.synchronize do
137
+ mount "WhileLoadingTester", {}, no_wait: true do
138
+ class WhileLoadingTester < Hyperloop::Component
139
+ render do
140
+ DIV do
141
+ User.find_by_first_name('Lily').last_name
142
+ end
143
+ .while_loading(DIV { 'loading...' })
144
+ end
145
+ end
146
+ end
147
+ expect(page).to have_content('loading...')
148
+ expect(page).not_to have_content('DaDog', wait: 0)
149
+ end
150
+ expect(page).to have_content('DaDog')
151
+ expect(page).not_to have_content('loading...', wait: 0)
152
+ end
153
+
154
+ it "will display the while loading message" do
155
+ isomorphic do
156
+ class FetchNow < Hyperloop::ServerOp
157
+ dispatch_to { TestApplication }
158
+ end
159
+ end
160
+ mount "WhileLoadingTester", {}, no_wait: true do
161
+ class MyNestedGuy < Hyperloop::Component
162
+ state fetch: false, scope: :shared
163
+ FetchNow.on_dispatch { mutate.fetch(true) }
164
+ render(SPAN) do
165
+ if state.fetch
166
+ User.find_by_first_name('Lily').last_name
167
+ else
168
+ 'no fetch yet chet'
169
+ end
170
+ end
171
+ end
172
+ class WhileLoadingTester < Hyperloop::Component
173
+ render do
174
+ DIV do
175
+ MyNestedGuy {}
176
+ end.while_loading do
177
+ SPAN { 'loading...' }
178
+ end
179
+ end
180
+ end
181
+ end
182
+ expect(page).to have_content('no fetch yet chet')
183
+ expect(page).not_to have_content('loading...', wait: 0)
184
+ expect(page).not_to have_content('DaDog', wait: 0)
185
+ ReactiveRecord::Operations::Fetch.semaphore.synchronize do
186
+ FetchNow.run
187
+ expect(page).to have_content('loading...')
188
+ expect(page).not_to have_content('DaDog', wait: 0)
189
+ expect(page).not_to have_content('no fetch yet chet', wait: 0)
190
+ end
191
+ expect(page).to have_content('DaDog')
192
+ expect(page).not_to have_content('loading...', wait: 0)
193
+ expect(page).not_to have_content('no fetch yet chet', wait: 0)
194
+ end
195
+
196
+ end
@@ -31,8 +31,8 @@ describe "regulate_all_broadcasts" do
31
31
  end
32
32
  attr_accessor :attrA, :attrB, :attrC, :attrD, :attrE
33
33
  end
34
- allow_any_instance_of(HyperMesh::InternalPolicy).to receive(:id).and_return(:unique_broadcast_id)
35
- allow(HyperMesh::Connection).to receive(:active).and_return(['Application', 'AnotherApplication', 'Class1', 'Class2'])
34
+ allow_any_instance_of(Hyperloop::InternalPolicy).to receive(:id).and_return(:unique_broadcast_id)
35
+ allow(Hyperloop::Connection).to receive(:active).and_return(['Application', 'AnotherApplication', 'Class1', 'Class2'])
36
36
  end
37
37
 
38
38
  it "will broadcast to a single channel" do
@@ -43,7 +43,7 @@ describe "regulate_all_broadcasts" do
43
43
  end
44
44
  end
45
45
  model = TestModel1.new(attr1: 1, attr2: 2, attr3: 3, attr4: 4, attr5: 5)
46
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
46
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
47
47
  {
48
48
  broadcast_id: :unique_broadcast_id,
49
49
  channel: 'Application',
@@ -69,7 +69,7 @@ describe "regulate_all_broadcasts" do
69
69
  end
70
70
  end
71
71
  model = TestModel1.new(attr1: 1, attr2: 2, attr3: 3, attr4: 4, attr5: 5)
72
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
72
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
73
73
  {
74
74
  broadcast_id: :unique_broadcast_id,
75
75
  channel: 'Application',
@@ -103,7 +103,7 @@ describe "regulate_all_broadcasts" do
103
103
  end
104
104
  end
105
105
  model = TestModel1.new(attr1: 1, attr2: 2, attr3: 3, attr4: 4, attr5: 5)
106
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
106
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
107
107
  {
108
108
  broadcast_id: :unique_broadcast_id,
109
109
  channel: 'Application',
@@ -139,7 +139,7 @@ describe "regulate_all_broadcasts" do
139
139
  end
140
140
  end
141
141
  model = TestModel1.new(attr1: 1, attr2: 2, attr3: 3, attr4: 4, attr5: 5)
142
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
142
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
143
143
  {
144
144
  broadcast_id: :unique_broadcast_id,
145
145
  channel: 'AnotherApplication',
@@ -175,7 +175,7 @@ describe "regulate_all_broadcasts" do
175
175
  end
176
176
  end
177
177
  model = TestModel1.new(attr1: 1, attr2: 2, attr3: 3, attr4: 4, attr5: 5)
178
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
178
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
179
179
  {
180
180
  broadcast_id: :unique_broadcast_id,
181
181
  channel: 'AnotherApplication',
@@ -212,7 +212,7 @@ describe "regulate_all_broadcasts" do
212
212
  end
213
213
  end
214
214
  model = TestModel1.new(attr1: 1, attr2: 2, attr3: 3, attr4: 4, attr5: 5)
215
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
215
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
216
216
  {
217
217
  broadcast_id: :unique_broadcast_id,
218
218
  channel: 'AnotherApplication',
@@ -241,7 +241,7 @@ describe "regulate_all_broadcasts" do
241
241
  end
242
242
  end
243
243
  model = TestModel1.new(attr1: 1, attr2: 2, attr3: 3, attr4: 4, attr5: 5)
244
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
244
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
245
245
  {
246
246
  broadcast_id: :unique_broadcast_id,
247
247
  channel: 'Application',
@@ -261,7 +261,7 @@ describe "regulate_all_broadcasts" do
261
261
  end
262
262
  end
263
263
  model = TestModel1.new(attr1: 1)
264
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
264
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
265
265
  {
266
266
  broadcast_id: :unique_broadcast_id,
267
267
  channel: 'Application',
@@ -272,7 +272,7 @@ describe "regulate_all_broadcasts" do
272
272
  }
273
273
  )
274
274
  model = TestModel2.new(attrA: "A")
275
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
275
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
276
276
  {
277
277
  broadcast_id: :unique_broadcast_id,
278
278
  channel: 'Application',
@@ -293,7 +293,7 @@ describe "regulate_all_broadcasts" do
293
293
  end
294
294
  end
295
295
  model = TestModel1.new(attr1: 1, attr2: 2, attr3: 3, attr4: 4, attr5: 5)
296
- expect { |b| HyperMesh::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
296
+ expect { |b| Hyperloop::InternalPolicy.regulate_broadcast(model, &b) }.to yield_successive_args(
297
297
  {
298
298
  broadcast_id: :unique_broadcast_id,
299
299
  channel: 'Class1',