mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 12:53:46 +08:00
80a80ef2bd
This change refactors the code a bit so that a plugin could easily replace which badge is awarded when completing the discobot new user tutorial and advanced tutorial. By adding a static method and putting the BADGE_NAME constant inside of that method we can simply call that method now instead of the constant. A plugin could then `class_eval` that method and replace it with whatever badge name they choose. This is way cleaner than having the plugin change the frozen constant! eeek.
29 lines
746 B
Ruby
29 lines
746 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Jobs::DiscourseNarrativeBot::GrantBadges do
|
|
let(:user) { Fabricate(:user) }
|
|
let(:other_user) { Fabricate(:user) }
|
|
|
|
before do
|
|
DiscourseNarrativeBot::Store.set(user.id, completed: [
|
|
DiscourseNarrativeBot::NewUserNarrative.to_s,
|
|
DiscourseNarrativeBot::AdvancedUserNarrative.to_s
|
|
])
|
|
end
|
|
|
|
it 'should grant the right badges' do
|
|
described_class.new.execute_onceoff({})
|
|
|
|
expect(user.badges.count).to eq(2)
|
|
|
|
expect(user.badges.map(&:name)).to contain_exactly(
|
|
DiscourseNarrativeBot::NewUserNarrative.badge_name,
|
|
DiscourseNarrativeBot::AdvancedUserNarrative.badge_name,
|
|
)
|
|
|
|
expect(other_user.badges.count).to eq(0)
|
|
end
|
|
end
|