2014-04-16 09:12:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe BadgesController do
|
|
|
|
let!(:badge) { Fabricate(:badge) }
|
2014-06-14 03:55:06 -04:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.enable_badges = true
|
|
|
|
end
|
2014-04-16 09:12:06 -04:00
|
|
|
|
|
|
|
context 'index' do
|
|
|
|
it 'should return a list of all badges' do
|
2014-04-25 14:25:29 -04:00
|
|
|
get :index, format: :json
|
2014-04-16 09:12:06 -04:00
|
|
|
|
|
|
|
response.status.should == 200
|
|
|
|
parsed = JSON.parse(response.body)
|
2014-05-04 14:15:38 -04:00
|
|
|
parsed["badges"].length.should == Badge.count
|
2014-04-16 09:12:06 -04:00
|
|
|
end
|
|
|
|
end
|
2014-04-16 10:56:11 -04:00
|
|
|
|
|
|
|
context 'show' do
|
|
|
|
it "should return a badge" do
|
2014-04-25 14:25:29 -04:00
|
|
|
get :show, id: badge.id, format: :json
|
2014-04-16 10:56:11 -04:00
|
|
|
response.status.should == 200
|
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
parsed["badge"].should be_present
|
|
|
|
end
|
2014-06-14 03:55:06 -04:00
|
|
|
|
|
|
|
it "should mark the notification as viewed" do
|
|
|
|
log_in_user(user)
|
|
|
|
user_badge = BadgeGranter.grant(badge, user)
|
|
|
|
user_badge.notification.read.should == false
|
|
|
|
get :show, id: badge.id, format: :json
|
|
|
|
user_badge.notification.reload.read.should == true
|
|
|
|
end
|
2014-04-16 10:56:11 -04:00
|
|
|
end
|
2014-04-16 09:12:06 -04:00
|
|
|
end
|