diff --git a/Changelog.md b/Changelog.md index fd7f2826b..eece68961 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ ## Bug fixes * Fix mention autocomplete when pasting the username [#6510](https://github.com/diaspora/diaspora/pull/6510) +* Use and update updated\_at for notifications [#6573](https://github.com/diaspora/diaspora/pull/6573) ## Features diff --git a/app/models/notification.rb b/app/models/notification.rb index 5fd5117f2..4cec79128 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -64,6 +64,8 @@ private begin n.actors = n.actors | [actor] n.unread = true + # Explicitly touch the notification to update updated_at whenever new actor is inserted in notification. + n.touch n.save! rescue ActiveRecord::RecordNotUnique nil diff --git a/app/views/notifications/_notification.haml b/app/views/notifications/_notification.haml index b4bf4e90f..651c2291b 100644 --- a/app/views/notifications/_notification.haml +++ b/app/views/notifications/_notification.haml @@ -10,4 +10,4 @@ .media-body = notification_message_for(note) %div - = timeago(note.created_at) + = timeago(note.updated_at) diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 7568f8e12..2e79d431d 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -46,7 +46,7 @@ describe NotificationsController, :type => :controller do describe '#index' do before do @post = FactoryGirl.create(:status_message) - FactoryGirl.create(:notification, :recipient => alice, :target => @post) + @notification = FactoryGirl.create(:notification, recipient: alice, target: @post) end it 'succeeds' do @@ -56,8 +56,15 @@ describe NotificationsController, :type => :controller do end it 'succeeds for notification dropdown' do + Timecop.travel(6.seconds.ago) do + @notification.touch + end get :index, :format => :json expect(response).to be_success + note_html = JSON.parse(response.body)[0]["also_commented"]["note_html"] + note_html = Nokogiri::HTML(note_html) + timeago_content = note_html.css("time")[0]["data-time-ago"] + expect(timeago_content).to include(@notification.updated_at.iso8601) expect(response.body).to match(/note_html/) end @@ -84,7 +91,6 @@ describe NotificationsController, :type => :controller do it "should not provide a contacts menu for standard notifications" do FactoryGirl.create(:notification, :recipient => alice, :target => @post) get :index, "per_page" => 5 - expect(Nokogiri(response.body).css('.aspect_membership')).to be_empty end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 1881aec22..b7bd65f71 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -97,8 +97,10 @@ describe Notification, :type => :model do p = FactoryGirl.build(:status_message, :author => @user.person) person2 = FactoryGirl.build(:person) notification = Notification.notify(@user, FactoryGirl.build(:like, :author => @person, :target => p), @person) + earlier_updated_at = notification.updated_at notification2 = Notification.notify(@user, FactoryGirl.build(:like, :author => person2, :target => p), person2) expect(notification.id).to eq(notification2.id) + expect(earlier_updated_at).to_not eq(notification.reload.updated_at) end end @@ -107,8 +109,10 @@ describe Notification, :type => :model do p = FactoryGirl.build(:status_message, :author => @user.person) person2 = FactoryGirl.build(:person) notification = Notification.notify(@user, FactoryGirl.build(:comment, :author => @person, :post => p), @person) + earlier_updated_at = notification.updated_at notification2 = Notification.notify(@user, FactoryGirl.build(:comment, :author => person2, :post => p), person2) expect(notification.id).to eq(notification2.id) + expect(earlier_updated_at).to_not eq(notification.reload.updated_at) end end