Skip to content
Extraits de code Groupes Projets
notifications_controller_spec.rb 1,63 ko
Newer Older
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
  before do
    @user   = alice
    @aspect = @user.aspects.first
    sign_in :user, @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)
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é

      Factory(:notification, :recipient => @user)
      note = Factory(:notification, :recipient => user2)
maxwell's avatar
maxwell a validé

maxwell's avatar
maxwell a validé
      put :update, :id => note.id
maxwell's avatar
maxwell a validé

Raphael's avatar
Raphael 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
Raphael's avatar
Raphael a validé
      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
      get :read_all
      Notification.where(:unread => true).count.should == 0
maxwell's avatar
maxwell a validé
    end
  end
  describe '#index' do
      26.times do
        Factory(:notification, :recipient => @user)
      get :index, :page => 2
      assigns[:notifications].count.should == 1

    it 'eager loads the target' do
      get :index
      assigns[:notifications].each{ |note| note.loaded_target?.should be_true }
    end