notifications tests pass

This commit is contained in:
Dennis Collinson & Michael Sofaer 2011-06-27 19:10:45 -07:00 committed by Michael Sofaer & Raphael Sofaer
parent 46c83a7c7d
commit f9e8e7a041
5 changed files with 20 additions and 19 deletions

1
.pairs
View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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();

View file

@ -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