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