has_group_relation_definition_examples.rb 1.3 KB

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