diff options
Diffstat (limited to 'spec/support/shared_examples/services/users')
-rw-r--r-- | spec/support/shared_examples/services/users/dismiss_user_callout_service_shared_examples.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/support/shared_examples/services/users/dismiss_user_callout_service_shared_examples.rb b/spec/support/shared_examples/services/users/dismiss_user_callout_service_shared_examples.rb new file mode 100644 index 00000000000..09820593cdb --- /dev/null +++ b/spec/support/shared_examples/services/users/dismiss_user_callout_service_shared_examples.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +RSpec.shared_examples_for 'dismissing user callout' do |model| + it 'creates a new user callout' do + expect { execute }.to change { model.count }.by(1) + end + + it 'returns a user callout' do + expect(execute).to be_an_instance_of(model) + end + + it 'sets the dismissed_at attribute to current time' do + freeze_time do + expect(execute).to have_attributes(dismissed_at: Time.current) + end + end + + it 'updates an existing callout dismissed_at time' do + freeze_time do + old_time = 1.day.ago + new_time = Time.current + attributes = params.merge(dismissed_at: old_time, user: user) + existing_callout = create("#{model.name.split('::').last.underscore}".to_sym, attributes) + + expect { execute }.to change { existing_callout.reload.dismissed_at }.from(old_time).to(new_time) + end + end + + it 'does not update an invalid record with dismissed_at time', :aggregate_failures do + callout = described_class.new( + container: nil, current_user: user, params: { feature_name: nil } + ).execute + + expect(callout.dismissed_at).to be_nil + expect(callout).to be_invalid + end +end |