2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2014-04-16 09:12:06 -04:00
|
|
|
|
|
|
|
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
|
2018-05-21 23:40:50 -04:00
|
|
|
get "/badges.json"
|
2014-04-16 09:12:06 -04:00
|
|
|
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response.status).to eq(200)
|
2014-04-16 09:12:06 -04:00
|
|
|
parsed = JSON.parse(response.body)
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(parsed["badges"].length).to eq(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
|
2018-05-21 23:40:50 -04:00
|
|
|
get "/badges/#{badge.id}.json"
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response.status).to eq(200)
|
2014-04-16 10:56:11 -04:00
|
|
|
parsed = JSON.parse(response.body)
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(parsed["badge"]).to be_present
|
2014-04-16 10:56:11 -04:00
|
|
|
end
|
2014-06-14 03:55:06 -04:00
|
|
|
|
|
|
|
it "should mark the notification as viewed" do
|
2018-05-21 23:40:50 -04:00
|
|
|
sign_in(user)
|
2014-06-14 03:55:06 -04:00
|
|
|
user_badge = BadgeGranter.grant(badge, user)
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(user_badge.notification.read).to eq(false)
|
2018-05-21 23:40:50 -04:00
|
|
|
get "/badges/#{badge.id}.json"
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(user_badge.notification.reload.read).to eq(true)
|
2014-06-14 03:55:06 -04:00
|
|
|
end
|
2017-08-08 16:21:42 -04:00
|
|
|
|
|
|
|
it 'renders rss feed of a badge' do
|
2018-05-21 23:40:50 -04:00
|
|
|
get "/badges/#{badge.id}.rss"
|
2017-08-08 16:21:42 -04:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.content_type).to eq('application/rss+xml')
|
|
|
|
end
|
2014-04-16 10:56:11 -04:00
|
|
|
end
|
2014-04-16 09:12:06 -04:00
|
|
|
end
|