Skip to content

Commit 72bf44b

Browse files
committed
worked around Opal 0.11 singleton class issue
1 parent b0d5e65 commit 72bf44b

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

ruby/hyper-model/lib/reactive_record/active_record/reactive_record/collection.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,13 @@ def method_missing(method, *args, &block)
682682
elsif ScopeDescription.find(@target_klass, "_#{method}")
683683
apply_scope("_#{method}", *args).first
684684
else
685+
# create a subclass of the original target class that responds to all
686+
# by returning our collection back
685687
fake_class = Class.new(@target_klass)
686-
fake_class.singleton_class.attr_accessor :all
687-
fake_class.all = self
688+
fake_class.instance_variable_set("@all", self)
689+
# Opal 0.11 does not handle overridding the original @target_klass
690+
# with an accessor, so we define the accessor as a method.
691+
fake_class.define_singleton_method(:all) { @all }
688692
fake_class.send(method, *args, &block)
689693
end
690694
end

ruby/hyper-model/spec/batch1/misc/where_and_class_method_delegation_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def self.with_size(attr, size)
4242
end
4343

4444
it "can take a hash like value" do
45+
client_option raise_on_js_errors: :debug
4546
expect do
4647
ReactiveRecord.load { User.where(surname: "VanDuyn").pluck(:id, :first_name) }
4748
end.on_client_to eq User.where(surname: "VanDuyn").pluck(:id, :first_name)

ruby/hyper-model/spec/batch6/aaa_update_associations_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@
138138
it "and a model in a belongs_to relationship can be destroyed" do
139139
expect do
140140
ReactiveRecord.load do
141-
User.find_by_first_name("Jan").todo_items.collect { |item| item.itself }.first
142-
end.then do | first |
143-
first.destroy.then do |response|
141+
User.find_by_first_name("Jan").todo_items.collect(&:itself).first
142+
end.then do |first|
143+
first.destroy.then do
144144
User.find_by_first_name("Jan").todo_items.all
145145
end.tap { @was_destroyed_already = first.destroyed? }
146146
end
147-
end.on_client_to
148-
# added to check that issue #119 got fixed. Item is not
147+
end.on_client_to be_empty
148+
# added following to check that issue #119 got fixed. Item is not
149149
# considered destroyed until we get the status back from server
150150
# that it was destroyed
151151
expect { @was_destroyed_already }.on_client_to be_falsy

0 commit comments

Comments
 (0)