object_manager_attribute_date_remove_future_past_spec.rb 1.5 KB

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