docbrown/spec/models/badge_achievement_spec.rb
rhymes acb35afe03
Add unique indexes - part 4 (#8059)
* Rubocop unique index cop needs a static list of columns

* Add unique index on organizations secret

* Add unique index on chat_channel_memberships chat_channel_id

* Add unique index to chat_channel slug

* Add unique index to badge_achievements badge_id
2020-05-27 09:29:20 +02:00

30 lines
1,023 B
Ruby

require "rails_helper"
RSpec.describe BadgeAchievement, type: :model do
let_it_be(:achievement) { create(:badge_achievement) }
describe "validations" do
describe "builtin validations" do
subject { achievement }
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:badge) }
it { is_expected.to belong_to(:rewarder).class_name("User").optional }
it { is_expected.to validate_uniqueness_of(:badge_id).scoped_to(:user_id) }
end
end
it "turns rewarding_context_message_markdown into rewarding_context_message HTML" do
expect(achievement.rewarding_context_message).to include("</a>")
end
it "awards credits after create" do
expect(achievement.user.credits.size).to eq(5)
end
it "notifies recipients after commit" do
allow(Notification).to receive(:send_new_badge_achievement_notification)
achievement.run_callbacks(:commit)
expect(Notification).to have_received(:send_new_badge_achievement_notification).with(achievement)
end
end