Skip to content

Commit a2cf2c1

Browse files
committed
closes #97
1 parent b6d1747 commit a2cf2c1

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

ruby/hyper-model/lib/reactive_record/broadcast.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ module ReactiveRecord
22
class Broadcast
33

44
def self.after_commit(operation, model)
5+
# Calling public_columns_hash once insures all policies are loaded
6+
# before the first broadcast.
7+
@public_columns_hash ||= ActiveRecord::Base.public_columns_hash
58
Hyperstack::InternalPolicy.regulate_broadcast(model) do |data|
69
if !Hyperstack.on_server? && Hyperstack::Connection.root_path
7-
send_to_server(operation, data) rescue nil # server no longer running so ignore
10+
send_to_server(operation, data) rescue nil # fails if server no longer running so ignore
811
else
912
SendPacket.run(data, operation: operation)
1013
end

ruby/hyper-model/spec/batch3/edge_cases_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
size_window(:small, :portrait)
3939
end
4040

41+
it "will load all the policies before the first broadcast" do
42+
expect(defined? SomeModelPolicy).to be_falsy
43+
User.create(name: 'Fred')
44+
expect(defined? SomeModelPolicy).to be_truthy
45+
end
46+
47+
4148
it "prerenders a belongs to relationship" do
4249
# must be first otherwise check for ajax fails because of race condition
4350
# with previous test

ruby/hyper-model/spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class ActiveRecord::Base
288288

289289
config.before(:all) do
290290
# reset this variable so if any specs are setting up models locally
291-
# the correct has gets sent to the client.
291+
# the correct hash gets sent to the client.
292292
ActiveRecord::Base.instance_variable_set('@public_columns_hash', nil)
293293
class ActiveRecord::Base
294294
class << self
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class SomeModel < ApplicationRecord
2+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class SomeModelPolicy
2+
end

0 commit comments

Comments
 (0)