Slightly faster badge system specs. (Shaves off ~100ms)

This commit is contained in:
Vikhyat Korrapati 2014-04-16 16:04:27 +05:30
parent 4c0f85650e
commit de23caa871
4 changed files with 5 additions and 18 deletions

View File

@ -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

View File

@ -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) }

View File

@ -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 }

View File

@ -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)) }