Skip to content
Extraits de code Groupes Projets
notifications_controller_spec.rb 2,31 ko
Newer Older
  • Learn to ignore specific revisions
  • danielgrippi's avatar
    danielgrippi a validé
    #   Copyright (c) 2010-2011, Diaspora Inc.  This file is
    
    maxwell's avatar
    maxwell a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    #   the COPYRIGHT file.
    
    require 'spec_helper'
    
    describe NotificationsController do
    
      render_views(false)
    
    maxwell's avatar
    maxwell a validé
      before do
    
        @aspect = @user.aspects.first
    
        @controller = NotificationsController.new
        @controller.stub!(:current_user).and_return(@user)
    
    maxwell's avatar
    maxwell a validé
      end
    
    
    maxwell's avatar
    maxwell a validé
      describe '#update' do
    
        it 'marks a notification as read' do
    
          note = Factory(:notification, :recipient => @user)
    
          @controller.update :id => note.id
    
    maxwell's avatar
    maxwell a validé
          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é
    
    
          Factory(:notification, :recipient => @user)
          note = Factory(:notification, :recipient => user2)
    
    maxwell's avatar
    maxwell a validé
    
    
          @controller.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
    
          request.env["HTTP_REFERER"] = "I wish I were spelled right"
    
          Factory(:notification, :recipient => @user)
          Factory(:notification, :recipient => @user)
    
    
          Notification.where(:unread => true).count.should == 2
    
          @controller.read_all({})
    
          Notification.where(:unread => true).count.should == 0
    
    maxwell's avatar
    maxwell a validé
        end
      end
    
      describe '#index' do
    
          @post = Factory(:status_message)
    
          Factory(:notification, :recipient => @user, :target => @post)
    
        it 'paginates the notifications' do
          25.times { Factory(:notification, :recipient => @user, :target => @post) }
    
          @controller.index({})[:notifications].count.should == 25
          @controller.index(:page => 2)[:notifications].count.should == 1
        end
    
        it "includes the actors" do
          Factory(:notification, :recipient => @user, :target => @post)
          response = @controller.index({})
          response[:notifications].first[:actors].first.should be_a(Person)
    
        it 'eager loads the target' do
          response = @controller.index({})
          response[:notifications].each { |note| note[:target].should be }
        end
    
        it "supports a limit per_page parameter" do
          5.times { Factory(:notification, :recipient => @user, :target => @post) }
          response = @controller.index({:per_page => 5})
          response[:notifications].length.should == 5