1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- # Requires: let!(:group_relation_instance) { ... }
- RSpec.shared_examples 'HasGroupRelationDefinition' do
- let(:group_relation_model_key) { group_relation_instance.model_name.element }
- context 'relation creation' do
- it 'refreshes updated_at of related instances' do
- group = create(:group)
- travel 1.minute
- expect do
- described_class.create!(
- group_relation_model_key => group_relation_instance,
- group: group
- )
- end.to change {
- group.reload.updated_at
- }.and change {
- group_relation_instance.reload.updated_at
- }
- end
- end
- context 'related instance deletion' do
- it 'refreshes updated_at of group instance' do
- group = create(:group)
- described_class.create!(
- group_relation_model_key => group_relation_instance,
- group: group
- )
- travel 1.minute
- expect do
- group.destroy
- end.to change {
- group_relation_instance.reload.updated_at
- }
- end
- it 'refreshes updated_at of relation instance' do
- group = create(:group)
- described_class.create!(
- group_relation_model_key => group_relation_instance,
- group: group
- )
- travel 1.minute
- expect do
- group_relation_instance.destroy
- end.to change {
- group.reload.updated_at
- }
- end
- end
- end
|