object_manager_attribute_date_remove_future_past_spec.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe ObjectManagerAttributeDateRemoveFuturePast, type: :db_migration do
  4. context 'when Date ObjectManager::Attribute exists' do
  5. it 'removes future and past data_option' do
  6. subject = build(:object_manager_attribute_date)
  7. # add data_options manually because the factory doesn't contain them anymore
  8. subject.data_option = subject.data_option.merge(
  9. future: false,
  10. past: false,
  11. )
  12. # mock interfaces to save time
  13. # otherwise we would have to reseed the database
  14. allow(ObjectManager::Attribute).to receive(:where).and_return([subject])
  15. allow(subject).to receive(:save!)
  16. migrate
  17. expect(subject.data_option).not_to include(:past, :future)
  18. end
  19. context 'when incomplete data_option is given' do
  20. it 'adds missing :diff option' do
  21. subject = build(:object_manager_attribute_date)
  22. # add data_options manually because the factory doesn't contain them anymore
  23. subject.data_option = subject.data_option.merge(
  24. future: false,
  25. past: false,
  26. )
  27. # remove diff option as for some attributes
  28. # from older Zammad installations
  29. subject.data_option.delete(:diff)
  30. # mock interfaces to save time
  31. # otherwise we would have to reseed the database
  32. allow(ObjectManager::Attribute).to receive(:where).and_return([subject])
  33. # expect(subject).to receive(:save!)
  34. expect { migrate }.not_to raise_error
  35. end
  36. end
  37. end
  38. end