add_history_source_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe AddHistorySource, db_strategy: :reset, type: :db_migration do
  4. before do
  5. ActiveRecord::Migration.remove_column :histories, :sourceable_id
  6. ActiveRecord::Migration.remove_column :histories, :sourceable_type
  7. ActiveRecord::Migration.remove_column :histories, :sourceable_name
  8. History.reset_column_information
  9. end
  10. describe 'migrate SQL table' do
  11. it 'does add the column' do
  12. migrate
  13. expect(History.column_names).to include('sourceable_id', 'sourceable_type', 'sourceable_name')
  14. end
  15. end
  16. describe 'migrate time_trigger_performed history entries' do
  17. let(:trigger) { create(:trigger) }
  18. let(:history_entry) do
  19. create(:history,
  20. history_type: 'time_trigger_performed',
  21. value_from: 'reminder_reached',
  22. value_to: trigger.name,
  23. related_history_object: trigger)
  24. end
  25. let(:initial_attributes) { history_entry.attributes }
  26. let(:converted_old_attributes) do
  27. history_entry.attributes.merge(
  28. 'sourceable_type' => 'Trigger',
  29. 'sourceable_id' => trigger.id,
  30. 'sourceable_name' => trigger.name,
  31. 'related_history_object_id' => nil,
  32. 'related_o_id' => nil,
  33. 'value_to' => nil
  34. )
  35. end
  36. it 'migrates the entry' do
  37. expect { migrate }
  38. .to change { history_entry.reload.attributes }
  39. .from(initial_attributes)
  40. .to(converted_old_attributes)
  41. end
  42. end
  43. end