From 23ebe91d32b418e4cdfcf60bf3a49d16a0e59d8b Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 1 Jul 2021 13:56:23 +1000 Subject: [PATCH] Spec current version tracking of order cycles The paper_trail gem doesn't quite work as expected with our implementation. We need some more code or an additional gem: https://github.com/westonganger/paper_trail-association_tracking --- spec/models/order_cycle_spec.rb | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb index 1031a53c6b..3a9fd7006f 100644 --- a/spec/models/order_cycle_spec.rb +++ b/spec/models/order_cycle_spec.rb @@ -497,6 +497,51 @@ describe OrderCycle do end end + describe "version tracking", versioning: true do + let!(:oc) { create(:order_cycle, name: "Original") } + + it "remembers old versions" do + expect { + oc.update!(name: "New name") + }.to change { + oc.versions.count + }.by(1) + + expect(oc.versions.last.reify.name).to eq "Original" + end + + # Needs additional gem: + # https://github.com/westonganger/paper_trail-association_tracking + xit "records versions when adding schedules" do + pending "seems broken with current version" + + expect { + # Creating a schedule associates it automatically: + create(:schedule) + expect(oc.schedules.count).to eq 1 + }.to change { + oc.versions.count + }.by(1) + end + + it "records associated schedules" do + schedule = create(:schedule) + expect(oc.reload.schedules).to eq [schedule] + oc.update!(name: "New name") + + expect(oc.versions.last.custom_data).to eq "[#{schedule.id}]" + end + + it "remembers schedules of the previous version" do + schedule = create(:schedule) + expect(oc.reload.schedules).to eq [schedule] + oc.update!(name: "New name", schedules: []) + + pending "gathering schedule ids before save" + expect(oc.versions.last.custom_data).to eq "[#{schedule.id}]" + end + end + def core_exchange_attributes(exchange) exterior_attribute_keys = %w(id order_cycle_id created_at updated_at) exchange.attributes.