discourse-subscriptions/spec/services/discourse_donations/rewards_spec.rb

54 lines
1.6 KiB
Ruby
Raw Normal View History

2019-08-27 06:04:02 -04:00
# frozen_string_literal: true
require 'rails_helper'
module DiscourseDonations
RSpec.describe DiscourseDonations::Rewards do
2017-04-20 22:08:52 -04:00
let(:grp) { Fabricate(:group) }
let(:user) { Fabricate(:user) }
subject { described_class.new(user) }
it 'adds the user to a group' do
Group.expects(:find_by_name).with(grp.name).returns(grp)
grp.expects(:add).with(user)
2017-04-23 22:49:36 -04:00
subject.expects(:log_group_add).once
2017-04-23 21:44:55 -04:00
subject.add_to_group(grp.name)
2017-04-21 00:26:53 -04:00
end
it 'does not add the user to a group' do
Group.expects(:find_by_name).with(grp.name).returns(nil)
2017-04-23 21:44:55 -04:00
grp.expects(:add).never
2017-04-23 22:49:36 -04:00
subject.expects(:log_group_add).never
2017-04-23 21:44:55 -04:00
expect(subject.add_to_group(grp.name)).to be_falsy
end
2017-04-23 22:49:36 -04:00
it 'logs the group add' do
GroupActionLogger.any_instance.expects(:log_add_user_to_group)
subject.add_to_group(grp.name)
end
describe '.grant_badge' do
let(:badge) { Fabricate(:badge) }
before { SiteSetting.stubs(:enable_badges).returns(true) }
it 'grants the user a badge' do
BadgeGranter.expects(:grant).with(badge, user)
subject.grant_badge(badge.name)
end
it 'does not grant the user a badge when the badge does not exist' do
Badge.stubs(:find_by_name).returns(nil)
BadgeGranter.expects(:grant).never
expect(subject.grant_badge('does not exist')).to be_falsy
end
2017-04-23 21:44:55 -04:00
it 'does not grant the user a badge when badges are disabled' do
SiteSetting.stubs(:enable_badges).returns(false)
BadgeGranter.expects(:grant).never
subject.grant_badge(badge.name)
end
2017-04-23 21:44:55 -04:00
end
end
end