mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:41:25 +08:00
FIX: Avoid marking notifications as seen in readonly mode.
This commit is contained in:
@ -33,7 +33,8 @@ end
|
||||
describe NotificationsController do
|
||||
context 'when logged in' do
|
||||
context 'as normal user' do
|
||||
let!(:user) { sign_in(Fabricate(:user)) }
|
||||
fab!(:user) { sign_in(Fabricate(:user)) }
|
||||
fab!(:notification) { Fabricate(:notification, user: user) }
|
||||
|
||||
describe '#index' do
|
||||
it 'should succeed for recent' do
|
||||
@ -47,7 +48,6 @@ describe NotificationsController do
|
||||
end
|
||||
|
||||
it 'should mark notifications as viewed' do
|
||||
Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
get "/notifications.json", params: { recent: true }
|
||||
@ -56,7 +56,6 @@ describe NotificationsController do
|
||||
end
|
||||
|
||||
it 'should not mark notifications as viewed if silent param is present' do
|
||||
Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
get "/notifications", params: { recent: true, silent: true }
|
||||
@ -64,6 +63,17 @@ describe NotificationsController do
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
end
|
||||
|
||||
it 'should not mark notifications as viewed in readonly mode' do
|
||||
Discourse.received_redis_readonly!
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
get "/notifications", params: { recent: true, silent: true }
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
ensure
|
||||
Discourse.clear_redis_readonly!
|
||||
end
|
||||
|
||||
context 'when username params is not valid' do
|
||||
it 'should raise the right error' do
|
||||
get "/notifications.json", params: { username: 'somedude' }
|
||||
@ -78,7 +88,6 @@ describe NotificationsController do
|
||||
end
|
||||
|
||||
it "can update a single notification" do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
notification2 = Fabricate(:notification, user: user)
|
||||
put "/notifications/mark-read.json", params: { id: notification.id }
|
||||
expect(response.status).to eq(200)
|
||||
@ -91,7 +100,6 @@ describe NotificationsController do
|
||||
end
|
||||
|
||||
it "updates the `read` status" do
|
||||
Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
put "/notifications/mark-read.json"
|
||||
@ -120,7 +128,7 @@ describe NotificationsController do
|
||||
end
|
||||
|
||||
context 'as admin' do
|
||||
let!(:admin) { sign_in(Fabricate(:admin)) }
|
||||
fab!(:admin) { sign_in(Fabricate(:admin)) }
|
||||
|
||||
describe '#create' do
|
||||
it "can create notification" do
|
||||
|
Reference in New Issue
Block a user