diff --git a/ruby/hyper-model/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb b/ruby/hyper-model/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb index 063f25000..b662fb022 100644 --- a/ruby/hyper-model/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +++ b/ruby/hyper-model/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb @@ -242,7 +242,7 @@ def self.gather_records(records_to_process, force, record_being_saved) end if record.new? || record.changed? || (record == record_being_saved && force) record_index += 1 end - [models, associations, backing_records] + [models.sort_by { |model| model[:id] }, associations, backing_records] end def save_or_validate(save, validate, force, &block) diff --git a/ruby/hyper-model/spec/batch2/relationships_spec.rb b/ruby/hyper-model/spec/batch2/relationships_spec.rb index ff93705cf..a0f83ca11 100644 --- a/ruby/hyper-model/spec/batch2/relationships_spec.rb +++ b/ruby/hyper-model/spec/batch2/relationships_spec.rb @@ -96,9 +96,6 @@ class TestComponent2 < React::Component::Base end it "adding child to a new model on client after render" do - # Hyperloop.configuration do |config| - # #config.transport = :none - # end m = FactoryBot.create(:test_model) m.child_models << FactoryBot.create(:child_model) mount "TestComponent2" do @@ -122,6 +119,30 @@ def self.add_child page.should have_content("parent has 3 children") end + it "preserves the order of children" do + isomorphic do + ChildModel.class_eval do + server_method :do_some_calc do + child_attribute + end + end + TestModel.class_eval do + server_method :do_some_calc do + child_models.collect(&:child_attribute).join(', ') + end + end + end + expect_promise do + parent = TestModel.new + 4.times do |i| + parent.child_models << ChildModel.new(child_attribute: i.to_s) + end + ReactiveRecord.load do + parent.do_some_calc.tap { parent.child_models[3].do_some_calc } + end + end.to eq('0, 1, 2, 3') + end + it "will re-render the count after an item is added or removed from a model" do m1 = FactoryBot.create(:test_model) mount "TestComponent2" do diff --git a/ruby/hyper-model/spec/spec_helper.rb b/ruby/hyper-model/spec/spec_helper.rb index d288f9866..311a7896e 100644 --- a/ruby/hyper-model/spec/spec_helper.rb +++ b/ruby/hyper-model/spec/spec_helper.rb @@ -271,13 +271,13 @@ class ActiveRecord::Base # DatabaseCleaner.start # end - config.after(:each) do |example| - unless example.exception - # Clear session data - Capybara.reset_sessions! - # Rollback transaction - DatabaseCleaner.clean - end + config.after(:each) do # |example| + # unless example.exception + # Clear session data + Capybara.reset_sessions! + # Rollback transaction + DatabaseCleaner.clean + # end end config.after(:all, :js => true) do