Skip to content
Extraits de code Groupes Projets
notifications_controller_spec.rb 3,52 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
      before do
    
        sign_in :user, alice
    
    maxwell's avatar
    maxwell a validé
      end
    
    
    maxwell's avatar
    maxwell a validé
      describe '#update' do
    
        it 'marks a notification as read if it gets no other information' do
          note = mock_model( Notification )
          Notification.should_receive( :where ).and_return( [note] )
          note.should_receive( :set_read_state ).with( true )
    
        end
        it 'marks a notification as read if it is told to' do
          note = mock_model( Notification )
          Notification.should_receive( :where ).and_return( [note] )
          note.should_receive( :set_read_state ).with( true )
    
          get :update, "id" => note.id, :set_unread => "false"
    
        end
    
        it 'marks a notification as unread if it is told to' do
          note = mock_model( Notification )
          Notification.should_receive( :where ).and_return( [note] )
          note.should_receive( :set_read_state ).with( false )
    
          get :update, "id" => note.id, :set_unread => "true"
    
    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 => alice)
    
          note = Factory(:notification, :recipient => user2)
    
    maxwell's avatar
    maxwell a validé
    
    
          get :update, "id" => note.id, :set_unread => "false"
    
    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 => alice)
          Factory(:notification, :recipient => alice)
    
    
          Notification.where(:unread => true).count.should == 2
    
          Notification.where(:unread => true).count.should == 0
    
    maxwell's avatar
    maxwell a validé
        end
    
        it "should redirect to the stream in the html version" do
    
          Factory(:notification, :recipient => alice)
    
          get :read_all, :format => :html
    
          response.should redirect_to(stream_path)
    
        end
        it "should return a dummy value in the json version" do
    
          Factory(:notification, :recipient => alice)
    
          get :read_all, :format => :json
          response.should_not be_redirect
        end
    
    maxwell's avatar
    maxwell a validé
      end
    
      describe '#index' do
    
          @post = Factory(:status_message)
    
          Factory(:notification, :recipient => alice, :target => @post)
    
        it 'paginates the notifications' do
    
          25.times { Factory(:notification, :recipient => alice, :target => @post) }
    
          get :index
          assigns[:notifications].count.should == 25
          get :index, "page" => 2
          assigns[:notifications].count.should == 1
    
        it "supports a limit per_page parameter" do
    
          5.times { Factory(:notification, :recipient => alice, :target => @post) }
    
          get :index, "per_page" => 5
          assigns[:notifications].count.should == 5 
    
    
        describe "special case for start sharing notifications" do
          it "should not provide a contacts menu for standard notifications" do
    
            2.times { Factory(:notification, :recipient => alice, :target => @post) }
    
            get :index, "per_page" => 5
    
            Nokogiri(response.body).css('.aspect_membership').should be_empty
          end
          it "should provide a contacts menu for start sharing notifications" do
    
            2.times { Factory(:notification, :recipient => alice, :target => @post) }
    
            eve.share_with(alice.person, eve.aspects.first)
            get :index, "per_page" => 5
    
            Nokogiri(response.body).css('.aspect_membership').should_not be_empty
          end
    
    
          
        end