22require 'test_components'
33require 'rspec-steps'
44
5- describe "polymorphic relationships" , js : true , skip : true do
5+ describe "polymorphic relationships" , js : true do
66
77 before ( :all ) do
88 require 'pusher'
@@ -173,12 +173,13 @@ def self.build_tables
173173 def compare_to_server ( model , expression , expected_result , load = true )
174174 server_side = eval ( "#{ model . class } .find(#{ model . id } ).#{ expression } " )
175175 expect ( server_side ) . to eq ( expected_result )
176+ be_expected_result = expected_result . is_a? ( Array ) ? contain_exactly ( *expected_result ) : eq ( expected_result )
176177 if load
177178 expect_promise ( "Hyperstack::Model.load { #{ model . class } .find(#{ model . id } ).#{ expression } }" )
178- . to contain_exactly ( * expected_result )
179+ . to be_expected_result
179180 else
180181 wait_for_ajax
181- expect_evaluate_ruby ( "#{ model . class } .find(#{ model . id } ).#{ expression } " ) . to contain_exactly ( * expected_result )
182+ expect_evaluate_ruby ( "#{ model . class } .find(#{ model . id } ).#{ expression } " ) . to be_expected_result
182183 end
183184 end
184185
@@ -216,6 +217,7 @@ def compare_to_server(model, expression, expected_result, load=true)
216217 it 'create server side with broadcast update' do
217218 compare_to_server @imageable1 , 'pictures.collect(&:name)' , [ 'picture11' , 'picture12' ]
218219 Picture . create ( name : 'picture15' , imageable : @imageable1 )
220+ wait_for_ajax
219221 compare_to_server @imageable1 , 'pictures.collect(&:name)' , [ 'picture11' , 'picture12' , 'picture15' ] , false
220222 end
221223
@@ -234,27 +236,25 @@ def compare_to_server(model, expression, expected_result, load=true)
234236
235237 it 'changing belongs to relationship on client' do
236238 # not working yet
237- # compare_to_server @picture11, 'imageable.name', 'imageable1'
238- # compare_to_server @picture21, 'imageable.name', 'imageable2'
239239 compare_to_server @imageable1 , 'pictures.collect(&:name)' , [ 'picture11' , 'picture12' ]
240240 compare_to_server @imageable2 , 'pictures.collect(&:name)' , [ 'picture21' , 'picture22' ]
241-
242- evaluate_ruby do
241+ evaluate_promise do
243242 p = Picture . find ( 1 )
244243 p . imageable = Product . find ( 1 )
245244 p . save
246245 end
247- binding . pry
246+ wait_for_ajax
248247 compare_to_server @imageable1 , 'pictures.collect(&:name)' , [ 'picture12' ] , false
249248 compare_to_server @imageable2 , 'pictures.collect(&:name)' , [ 'picture11' , 'picture21' , 'picture22' ] , false
250249 end
251250
252251 it 'changing belongs to relationship on server' do
252+ # compare_to_server @picture11, 'imageable.name', 'imageable1' # here for debug assist
253+ # compare_to_server @picture11, 'imageable.ss', '123' # here for debug assist
254+
253255 # just debugging here... when id doesn't change we don't realize that data is changing
254256 compare_to_server @imageable1 , 'pictures.collect(&:name)' , [ 'picture11' , 'picture12' ]
255257 compare_to_server @imageable2 , 'pictures.collect(&:name)' , [ 'picture21' , 'picture22' ]
256-
257- wait_for_ajax
258258 p = Picture . find_by_name ( 'picture11' )
259259 p . imageable = @imageable2
260260 p . save
0 commit comments