Do not change notification timestamp when making it read or unread.
Marking a notification as unread resets the timeago stamp causing the times to look wrong. It can be reproduced by marking an old notification as unread. Using the update_column instead of update_attribute will not touch the updated_at attribute, and thus will not affect the updated time ago in the view. Fixes #6798. closes #6821
This commit is contained in:
parent
4cd2f1d9c1
commit
1773e3e35d
4 changed files with 20 additions and 4 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
* Fix back to top button not appearing on Webkit browsers [#6782](https://github.com/diaspora/diaspora/pull/6782)
|
* Fix back to top button not appearing on Webkit browsers [#6782](https://github.com/diaspora/diaspora/pull/6782)
|
||||||
|
* Don't reset the notification timestamp when marking them as read [#6821](https://github.com/diaspora/diaspora/pull/6821)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class Notification < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_read_state( read_state )
|
def set_read_state( read_state )
|
||||||
self.update_attributes( :unread => !read_state )
|
update_column(:unread, !read_state)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mail_job
|
def mail_job
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,19 @@ describe NotificationsController, :type => :controller do
|
||||||
get :update, "id" => note.id, :set_unread => "true", :format => :json
|
get :update, "id" => note.id, :set_unread => "true", :format => :json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "marks a notification as unread without timestamping" do
|
||||||
|
note = Timecop.travel(1.hour.ago) do
|
||||||
|
FactoryGirl.create(:notification, recipient: alice, unread: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
get :update, "id" => note.id, :set_unread => "true", :format => :json
|
||||||
|
expect(response).to be_success
|
||||||
|
|
||||||
|
updated_note = Notification.find(note.id)
|
||||||
|
expect(updated_note.unread).to eq(true)
|
||||||
|
expect(updated_note.updated_at.iso8601).to eq(note.updated_at.iso8601)
|
||||||
|
end
|
||||||
|
|
||||||
it 'only lets you read your own notifications' do
|
it 'only lets you read your own notifications' do
|
||||||
user2 = bob
|
user2 = bob
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,15 +41,17 @@ describe Notification, :type => :model do
|
||||||
describe 'set_read_state method' do
|
describe 'set_read_state method' do
|
||||||
it "should set an unread notification to read" do
|
it "should set an unread notification to read" do
|
||||||
@note.unread = true
|
@note.unread = true
|
||||||
|
@note.save
|
||||||
@note.set_read_state( true )
|
@note.set_read_state( true )
|
||||||
expect(@note.unread).to eq(false)
|
expect(@note.unread).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set an read notification to unread" do
|
it "should set an read notification to unread" do
|
||||||
@note.unread = false
|
@note.unread = false
|
||||||
|
@note.save
|
||||||
@note.set_read_state( false )
|
@note.set_read_state( false )
|
||||||
expect(@note.unread).to eq(true)
|
expect(@note.unread).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue