Sha256: 785b28c651bc557b3c6f3ab9d55c6cf9455e1d7558c3469408a0bccffe4260ca

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

describe Unread::GarbageCollector do
  before :each do
    @reader = Reader.create! :name => 'David'
    @other_reader = Reader.create :name => 'Matz'
    @sti_reader = StiReader.create!
    wait
    @email1 = Email.create!
    wait
    @email2 = MultiLevelStiReadable.create!
  end

  describe :run! do
    it "should delete all single read marks" do
      expect(@reader.read_marks.single.count).to eq 0

      @email1.mark_as_read! :for => @reader

      expect(Email.unread_by(@reader)).to eq [@email2]
      expect(@reader.read_marks.single.count).to eq 1

      Unread::GarbageCollector.new(Email).run!

      @reader.reload
      expect(@reader.read_marks.single.count).to eq 0
    end

    it "should reset if all objects are read" do
      @email1.mark_as_read! :for => @reader
      @email2.mark_as_read! :for => @reader

      expect(@reader.read_marks.single.count).to eq 2

      Unread::GarbageCollector.new(Email).run!

      expect(@reader.read_marks.single.count).to eq 0
    end

    it "should not delete read marks from other readables" do
      other_read_mark = @reader.read_marks.create! do |rm|
        rm.readable_type = 'Foo'
        rm.readable_id   = 42
        rm.timestamp     = 5.years.ago
      end

      Unread::GarbageCollector.new(Email).run!

      expect(ReadMark.exists?(other_read_mark.id)).to be_truthy
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unread-0.9.1 spec/unread/garbage_collector_spec.rb
unread-0.9.0 spec/unread/garbage_collector_spec.rb