Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b1ee093dd6
Fetching contributors…

Cannot retrieve contributors at this time

file 72 lines (57 sloc) 1.606 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
require 'spec_helper'

describe Notification do

  before(:each) do
    @event = stub_model(Event)
    @user = stub_model(Student, institution: stub_model(Institution))
    @notification = Notification.new(
      user: @user,
      resource: @event,
      text: 'Test notification.',
      url: '/tests/1'
    )
  end

  it "should be valid with given attributes" do
    @notification.should be_valid
  end

  it "should not be valid without text" do
    @notification.text = nil
    @notification.should_not be_valid
  end

  it "should not be valid without url" do
    @notification.url = nil
    @notification.should_not be_valid
  end

  context "when scoped by unread" do

    it "should only find unread notifications" do
      @new_notification = @notification.dup
      @new_notification.user = @user
      @new_notification.read = true
      @new_notification.save
      @notification.save
      Notification.unread.should == [@notification]
    end

  end

  context "when scoped by since" do

    [
      1.hour.ago,
      1.day.ago,
      10.days.ago
    ].each do |since|
      it "should only find ones created since #{since}" do
        @new_notification = @notification.dup
        @new_notification.user = @user
        @new_notification.save
        @notification.created_at = since - 1
        @notification.save
        Notification.since(since).should == [@new_notification]
      end
    end

  end

  describe "#read!" do

    it "should mark the notification as read" do
      @notification.save
      @notification.read!
      @notification.read.should be_true
    end

  end

end
Something went wrong with that request. Please try again.