From f9e8e7a041d6ecea96e228b243edea01f57555bf Mon Sep 17 00:00:00 2001 From: Dennis Collinson & Michael Sofaer Date: Mon, 27 Jun 2011 19:10:45 -0700 Subject: [PATCH] notifications tests pass --- .pairs | 1 + app/controllers/notifications_controller.rb | 8 +++----- app/views/notifications/index.html.haml | 4 ++-- public/javascripts/widgets/notifications-badge.js | 14 +++++++------- spec/controllers/notifications_controller_spec.rb | 12 +++++++----- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.pairs b/.pairs index 75c6e9227..620e7e58e 100644 --- a/.pairs +++ b/.pairs @@ -7,6 +7,7 @@ pairs: sm: Sarah Mei; sarah mjs: Michael Sofaer; michael jd: Jeff Dickey; dickeytk + dc: Dennis Collinson email: prefix: pair domain: joindiaspora.com diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index e033828f5..a6929f09c 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -18,7 +18,7 @@ class NotificationsController < VannaController def index(opts=params) @aspect = :notification conditions = {:recipient_id => current_user.id} - page = params[:page] || 1 + page = opts[:page] || 1 notifications = WillPaginate::Collection.create(page, 25, Notification.where(conditions).count ) do |pager| result = Notification.find(:all, :conditions => conditions, @@ -34,9 +34,7 @@ class NotificationsController < VannaController n[:actors] = n.actors n[:translation_key] = n.popup_translation_key if n.translation_key == "notifications.mentioned" - n[:post] = Mention.find(n.target_id).post - else - n[:post] = Post.find(n.target_id) + n[:target] = n[:target].post end # Go find out if the post exists, and set the target_id to nil if it doesn't end @@ -48,7 +46,7 @@ class NotificationsController < VannaController Notification.where(:recipient_id => current_user.id).update_all(:unread => false) end post_process :html do - def post_read_all + def post_read_all(json) Response.new(:status => 302, :location => aspects_path) end end diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 161c4ba6e..07f26494b 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -21,9 +21,9 @@ .span-8.notifications_for_day - notes.each do |note| .stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : ''}"} - - if note.type == "Notifications::StartedSharing" && contact = current_user.contact_for(note.target) + - if note.type == "Notifications::StartedSharing" && contact = current_user.contact_for(note[:target]) .right - = render 'aspect_memberships/aspect_dropdown', :contact => contact, :person => note.target, :hang => 'left' + = render 'aspect_memberships/aspect_dropdown', :contact => contact, :person => note[:target], :hang => 'left' %span.from = notification_message_for(note) diff --git a/public/javascripts/widgets/notifications-badge.js b/public/javascripts/widgets/notifications-badge.js index 64042c1c6..23384aeaf 100644 --- a/public/javascripts/widgets/notifications-badge.js +++ b/public/javascripts/widgets/notifications-badge.js @@ -1,5 +1,5 @@ $(function() { - $("#notification_badge a").live("click", function(event){ + $("#notification_badge a").live("_click", function(event){ event.preventDefault(); $.getJSON("/notifications", function(hash) { $("#notifications_overlay").show(); @@ -15,7 +15,7 @@ $(function() { dayElement.find(".day").text(dayParts[1]) var notificationsForDay = hash["group_days"][day], notificationsForDayElement = dayElement.find('.notifications_for_day'); - + $.each(notificationsForDay, function(i, notificationHash) { $.each(notificationHash, function(notificationType, notification) { var actor = notification.actors[0]; @@ -27,15 +27,15 @@ $(function() { }); }); notificationsElement.append(dayElement) - - Diaspora.widgets.timeago.updateTimeAgo("time"); + + Diaspora.widgets.timeago.updateTimeAgo("time"); }); }); }); - + $("#notifications_overlay").delegate('a.close', 'click', function() { console.log("hi!"); $('#notifications_overlay').hide(); }); - -}); \ No newline at end of file + +}); diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 03dccdd6b..696dce9cc 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -46,8 +46,9 @@ describe NotificationsController do describe '#index' do before do + @post = Factory(:status_message) 26.times do - Factory(:notification, :recipient => @user) + Factory(:notification, :recipient => @user, :target => @post) end end @@ -56,13 +57,14 @@ describe NotificationsController do @controller.index(:page => 2)[:notifications].count.should == 1 end it "includes the actors" do - notification = Factory(:notification, :recipient => @user) - @controller.index({})[:notifications].first[:actors].should == notification.actors + notification = Factory(:notification, :recipient => @user, :target => @post) + response = @controller.index({}) + response[:notifications].first[:actors].first.should be_a(Person) end it 'eager loads the target' do - get :index - assigns[:notifications].each{ |note| note.loaded_target?.should be_true } + response = @controller.index({}) + response[:notifications].each{ |note| note[:target].should be } end end end