Skip to content
Extraits de code Groupes Projets
notifications_controller_spec.rb 1,2 ko
Newer Older
  • Learn to ignore specific revisions
  • maxwell's avatar
    maxwell a validé
    #   Copyright (c) 2010, Diaspora Inc.  This file is
    #   licensed under the Affero General Public License version 3 or later.  See
    #   the COPYRIGHT file.
    
    require 'spec_helper'
    
    describe NotificationsController do
    
    
      let!(:user) { Factory.create(:user) }
    
    maxwell's avatar
    maxwell a validé
      let!(:aspect) { user.aspects.create(:name => "AWESOME!!") }
    
    maxwell's avatar
    maxwell a validé
      before do
        sign_in :user, user
    
      end
    
    
    maxwell's avatar
    maxwell a validé
      describe '#update' do
        it 'marks a notification as read' do
    
          note = Notification.create(:recipient_id => user.id)
    
    maxwell's avatar
    maxwell a validé
          put :update, :id => note.id
          Notification.first.unread.should == false
    
    maxwell's avatar
    maxwell a validé
        end
    
    
    maxwell's avatar
    maxwell a validé
        it 'only lets you read your own notifications' do
    
    maxwell's avatar
    maxwell a validé
    
    
          Notification.create(:recipient_id => user.id)
          note = Notification.create(:recipient_id => user2.id)
    
    maxwell's avatar
    maxwell a validé
    
    
    maxwell's avatar
    maxwell a validé
          put :update, :id => note.id
    
    maxwell's avatar
    maxwell a validé
    
    
          Notification.find(note.id).unread.should == true
    
    maxwell's avatar
    maxwell a validé
        end
      end
    
      
      describe "#read_all" do
        it 'marks all notifications as read' do
          Notification.create(:recipient_id => user.id)
          Notification.create(:recipient_id => user.id)
    
          Notification.where(:unread => true).count.should == 2
          get :read_all
          Notification.where(:unread => true).count.should == 0
          
    
        end
      end
    
    maxwell's avatar
    maxwell a validé
    end