diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/models/award_emoji_spec.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/models/award_emoji_spec.rb')
-rw-r--r-- | spec/models/award_emoji_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/models/award_emoji_spec.rb b/spec/models/award_emoji_spec.rb index f268408c095..ebd1441f901 100644 --- a/spec/models/award_emoji_spec.rb +++ b/spec/models/award_emoji_spec.rb @@ -119,6 +119,36 @@ RSpec.describe AwardEmoji do end end + describe 'bumping updated at' do + let(:note) { create(:note_on_issue) } + let(:award_emoji) { build(:award_emoji, user: build(:user), awardable: note) } + + it 'calls bump_updated_at on the note when saved' do + expect(note).to receive(:bump_updated_at) + + award_emoji.save! + end + + it 'calls bump_updated_at on the note when destroyed' do + expect(note).to receive(:bump_updated_at) + + award_emoji.destroy! + end + + context 'on another awardable' do + let(:issue) { create(:issue) } + let(:award_emoji) { build(:award_emoji, user: build(:user), awardable: issue) } + + it 'does not error out when saved' do + expect { award_emoji.save! }.not_to raise_error + end + + it 'does not error out when destroy' do + expect { award_emoji.destroy! }.not_to raise_error + end + end + end + describe '.award_counts_for_user' do let(:user) { create(:user) } @@ -141,4 +171,43 @@ RSpec.describe AwardEmoji do expect(awards).to eq('thumbsup' => 2) end end + + describe 'updating upvotes_count' do + context 'on an issue' do + let(:issue) { create(:issue) } + let(:upvote) { build(:award_emoji, :upvote, user: build(:user), awardable: issue) } + let(:downvote) { build(:award_emoji, :downvote, user: build(:user), awardable: issue) } + + it 'updates upvotes_count on the issue when saved' do + expect(issue).to receive(:update_column).with(:upvotes_count, 1).once + + upvote.save! + downvote.save! + end + + it 'updates upvotes_count on the issue when destroyed' do + expect(issue).to receive(:update_column).with(:upvotes_count, 0).once + + upvote.destroy! + downvote.destroy! + end + end + + context 'on another awardable' do + let(:merge_request) { create(:merge_request) } + let(:award_emoji) { build(:award_emoji, user: build(:user), awardable: merge_request) } + + it 'does not update upvotes_count on the merge_request when saved' do + expect(merge_request).not_to receive(:update_column) + + award_emoji.save! + end + + it 'does not update upvotes_count on the merge_request when destroyed' do + expect(merge_request).not_to receive(:update_column) + + award_emoji.destroy! + end + end + end end |