has_group_relation_definition_examples.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Requires: let!(:group_relation_instance) { ... }
  3. RSpec.shared_examples 'HasGroupRelationDefinition' do
  4. let(:group_relation_model_key) { group_relation_instance.model_name.element }
  5. context 'relation creation' do
  6. it 'refreshes updated_at of related instances' do
  7. group = create(:group)
  8. travel 1.minute
  9. expect do
  10. described_class.create!(
  11. group_relation_model_key => group_relation_instance,
  12. group: group
  13. )
  14. end.to change {
  15. group.reload.updated_at
  16. }.and change {
  17. group_relation_instance.reload.updated_at
  18. }
  19. end
  20. end
  21. context 'related instance deletion' do
  22. it 'refreshes updated_at of group instance' do
  23. group = create(:group)
  24. described_class.create!(
  25. group_relation_model_key => group_relation_instance,
  26. group: group
  27. )
  28. travel 1.minute
  29. expect do
  30. group.destroy
  31. end.to change {
  32. group_relation_instance.reload.updated_at
  33. }
  34. end
  35. it 'refreshes updated_at of relation instance' do
  36. group = create(:group)
  37. described_class.create!(
  38. group_relation_model_key => group_relation_instance,
  39. group: group
  40. )
  41. travel 1.minute
  42. expect do
  43. group_relation_instance.destroy
  44. end.to change {
  45. group.reload.updated_at
  46. }
  47. end
  48. end
  49. end