Skip to content

Commit 96b2a5a

Browse files
committed
wip regression from last refactor fixed
1 parent 3ba519e commit 96b2a5a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ def find_inverse(model) # private
177177
def klass(model = nil)
178178
@klass ||= Object.const_get(@klass_name) if @klass_name
179179
raise "model is not correct class" if @klass && model && model.class != @klass
180-
debugger unless @klass || model
181180
raise "no model supplied for polymorphic relationship" unless @klass || model
182181
@klass || model.class
183182
end
@@ -193,7 +192,7 @@ def remove_member(member, owner)
193192
end
194193

195194
def add_member(member, owner)
196-
owner.attributes[attribute] ||= Collection.new(owner_class, owner, assoc)
195+
owner.attributes[attribute] ||= ReactiveRecord::Collection.new(owner_class, owner, self)
197196
owner.attributes[attribute] << member
198197
end
199198
end

ruby/hyper-model/spec/batch7/poly_assoc_spec.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'test_components'
33
require 'rspec-steps'
44

5-
describe "polymorphic relationships", js: true, skip: 'wip' do
5+
describe "polymorphic relationships", js: true, skip: true do
66

77
before(:all) do
88
require 'pusher'
@@ -175,10 +175,10 @@ def compare_to_server(model, expression, expected_result, load=true)
175175
expect(server_side).to eq(expected_result)
176176
if load
177177
expect_promise("Hyperstack::Model.load { #{model.class}.find(#{model.id}).#{expression} }")
178-
.to eq(expected_result)
178+
.to contain_exactly(*expected_result)
179179
else
180180
wait_for_ajax
181-
expect_evaluate_ruby("#{model.class}.find(#{model.id}).#{expression}").to eq(expected_result)
181+
expect_evaluate_ruby("#{model.class}.find(#{model.id}).#{expression}").to contain_exactly(*expected_result)
182182
end
183183
end
184184

@@ -234,21 +234,26 @@ def compare_to_server(model, expression, expected_result, load=true)
234234

235235
it 'changing belongs to relationship on client' do
236236
# not working yet
237-
compare_to_server @picture11, 'imageable.name', 'imageable1'
238-
compare_to_server @picture21, 'imageable.name', 'imageable2'
239-
evaluate_promise do
237+
# compare_to_server @picture11, 'imageable.name', 'imageable1'
238+
# compare_to_server @picture21, 'imageable.name', 'imageable2'
239+
compare_to_server @imageable1, 'pictures.collect(&:name)', ['picture11', 'picture12']
240+
compare_to_server @imageable2, 'pictures.collect(&:name)', ['picture21', 'picture22']
241+
242+
evaluate_ruby do
240243
p = Picture.find(1)
241244
p.imageable = Product.find(1)
242245
p.save
243246
end
247+
binding.pry
244248
compare_to_server @imageable1, 'pictures.collect(&:name)', ['picture12'], false
245-
compare_to_server @imageable2, 'pictures.collect(&:name)', ['picture21', 'picture22', 'picture11'], false
249+
compare_to_server @imageable2, 'pictures.collect(&:name)', ['picture11', 'picture21', 'picture22'], false
246250
end
247251

248252
it 'changing belongs to relationship on server' do
249253
# just debugging here... when id doesn't change we don't realize that data is changing
250254
compare_to_server @imageable1, 'pictures.collect(&:name)', ['picture11', 'picture12']
251255
compare_to_server @imageable2, 'pictures.collect(&:name)', ['picture21', 'picture22']
256+
252257
wait_for_ajax
253258
p = Picture.find_by_name('picture11')
254259
p.imageable = @imageable2

0 commit comments

Comments
 (0)