mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
regression, unable to edit posts
This commit is contained in:
parent
9d24a00f2e
commit
5a6c34fb8a
2 changed files with 31 additions and 10 deletions
|
@ -195,7 +195,7 @@ class PostAlerter
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_notify_edit?(notification, opts)
|
def should_notify_edit?(notification, opts)
|
||||||
return existing_notification.data_hash["display_username"] != opts[:display_username]
|
return notification.data_hash["display_username"] != opts[:display_username]
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_notify_like?(user, notification)
|
def should_notify_like?(user, notification)
|
||||||
|
|
|
@ -24,20 +24,41 @@ describe PostAlerter do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'edits' do
|
||||||
|
it 'notifies correctly on edits' do
|
||||||
|
|
||||||
|
ActiveRecord::Base.observers.enable :all
|
||||||
|
|
||||||
|
post = Fabricate(:post, raw: 'I love waffles')
|
||||||
|
|
||||||
|
admin = Fabricate(:admin)
|
||||||
|
post.revise(admin, {raw: 'I made a revision'})
|
||||||
|
|
||||||
|
# skip this notification cause we already notified on a similar edit
|
||||||
|
Timecop.freeze(2.hours.from_now) do
|
||||||
|
post.revise(admin, {raw: 'I made another revision'})
|
||||||
|
end
|
||||||
|
|
||||||
|
post.revise(Fabricate(:admin), {raw: 'I made a revision'})
|
||||||
|
|
||||||
|
Timecop.freeze(4.hours.from_now) do
|
||||||
|
post.revise(admin, {raw: 'I made another revision'})
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(Notification.count(post_number: 1, topic_id: post.topic_id)).to eq(3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'likes' do
|
context 'likes' do
|
||||||
it 'notifies on likes correctly' do
|
it 'notifies on likes correctly' do
|
||||||
ActiveRecord::Base.observers.enable :all
|
ActiveRecord::Base.observers.enable :all
|
||||||
|
|
||||||
post = Fabricate(:post, raw: 'I love waffles')
|
post = Fabricate(:post, raw: 'I love waffles')
|
||||||
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
||||||
|
PostAction.act(Fabricate(:admin), post, PostActionType.types[:like])
|
||||||
|
|
||||||
admin = Fabricate(:admin)
|
# one like
|
||||||
post.revise(admin, {raw: 'I made a revision'})
|
expect(Notification.count(post_number: 1, topic_id: post.topic_id)).to eq(1)
|
||||||
|
|
||||||
PostAction.act(admin, post, PostActionType.types[:like])
|
|
||||||
|
|
||||||
# one like and one edit notification
|
|
||||||
expect(Notification.count(post_number: 1, topic_id: post.topic_id)).to eq(2)
|
|
||||||
|
|
||||||
|
|
||||||
post.user.user_option.update_columns(like_notification_frequency:
|
post.user.user_option.update_columns(like_notification_frequency:
|
||||||
|
@ -46,7 +67,7 @@ describe PostAlerter do
|
||||||
admin2 = Fabricate(:admin)
|
admin2 = Fabricate(:admin)
|
||||||
PostAction.act(admin2, post, PostActionType.types[:like])
|
PostAction.act(admin2, post, PostActionType.types[:like])
|
||||||
# two likes one edit
|
# two likes one edit
|
||||||
expect(Notification.count(post_number: 1, topic_id: post.topic_id)).to eq(3)
|
expect(Notification.count(post_number: 1, topic_id: post.topic_id)).to eq(2)
|
||||||
|
|
||||||
post.user.user_option.update_columns(like_notification_frequency:
|
post.user.user_option.update_columns(like_notification_frequency:
|
||||||
UserOption.like_notification_frequency_type[:first_time_and_daily])
|
UserOption.like_notification_frequency_type[:first_time_and_daily])
|
||||||
|
@ -61,7 +82,7 @@ describe PostAlerter do
|
||||||
end
|
end
|
||||||
|
|
||||||
# first happend within the same day, no need to notify
|
# first happend within the same day, no need to notify
|
||||||
expect(Notification.count(post_number: 1, topic_id: post.topic_id)).to eq(4)
|
expect(Notification.count(post_number: 1, topic_id: post.topic_id)).to eq(3)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue