mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
Slightly faster badge system specs. (Shaves off ~100ms)
This commit is contained in:
parent
4c0f85650e
commit
de23caa871
@ -5,9 +5,7 @@ describe UserBadgesController do
|
||||
let(:badge) { Fabricate(:badge) }
|
||||
|
||||
context 'index' do
|
||||
before do
|
||||
@user_badge = BadgeGranter.grant(badge, user)
|
||||
end
|
||||
let!(:user_badge) { UserBadge.create(badge: badge, user: user, granted_by: Discourse.system_user, granted_at: Time.now) }
|
||||
|
||||
it 'requires username to be specified' do
|
||||
expect { xhr :get, :index }.to raise_error
|
||||
@ -62,21 +60,19 @@ describe UserBadgesController do
|
||||
end
|
||||
|
||||
context 'destroy' do
|
||||
before do
|
||||
@user_badge = BadgeGranter.grant(badge, user)
|
||||
end
|
||||
let!(:user_badge) { UserBadge.create(badge: badge, user: user, granted_by: Discourse.system_user, granted_at: Time.now) }
|
||||
|
||||
it 'checks that the user is authorized to revoke a badge' do
|
||||
xhr :delete, :destroy, id: @user_badge.id
|
||||
xhr :delete, :destroy, id: user_badge.id
|
||||
response.status.should == 403
|
||||
end
|
||||
|
||||
it 'revokes the badge' do
|
||||
log_in :admin
|
||||
StaffActionLogger.any_instance.expects(:log_badge_revoke).once
|
||||
xhr :delete, :destroy, id: @user_badge.id
|
||||
xhr :delete, :destroy, id: user_badge.id
|
||||
response.status.should == 200
|
||||
UserBadge.where(id: @user_badge.id).first.should be_nil
|
||||
UserBadge.where(id: user_badge.id).first.should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,9 +3,6 @@ require_dependency 'badge'
|
||||
|
||||
describe Badge do
|
||||
|
||||
it { should belong_to :badge_type }
|
||||
it { should have_many(:user_badges).dependent(:destroy) }
|
||||
|
||||
context 'validations' do
|
||||
before(:each) { Fabricate(:badge) }
|
||||
|
||||
|
@ -3,8 +3,6 @@ require_dependency 'badge_type'
|
||||
|
||||
describe BadgeType do
|
||||
|
||||
it { should have_many :badges }
|
||||
|
||||
it { should validate_presence_of :name }
|
||||
it { should validate_uniqueness_of :name }
|
||||
it { should validate_presence_of :color_hexcode }
|
||||
|
@ -3,10 +3,6 @@ require_dependency 'user_badge'
|
||||
|
||||
describe UserBadge do
|
||||
|
||||
it { should belong_to :badge }
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :granted_by }
|
||||
|
||||
context 'validations' do
|
||||
before(:each) { BadgeGranter.grant(Fabricate(:badge), Fabricate(:user)) }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user