Sha256: 9b56a52f97850d841d02b295a8861e71f40a777ab303e2d746d6c6839e458703

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

describe Unread::Base do
  before :each do
    @email = Email.create!
    wait
    @reader = Reader.create! name: 'John'
  end

  describe :acts_as_reader do
    it "should create global read mark" do
      expect(@reader.read_marks.count).to eq 1
      expect(@reader.read_marks.global.count).to eq 1
    end

    it "should define association for ReadMark" do
      expect(@reader.read_marks.first.reader).to eq(@reader)
    end

    it "should reset read_marks for created reader" do
      expect(Email.unread_by(@reader)).to be_empty
    end

    it "should memoize read_mark_global" do
      expect {
        rm1 = @reader.read_mark_global(Email)
        rm2 = @reader.read_mark_global(Email)
      }.to perform_queries(1)
    end

    it "should be idempotent" do
      expect {
        Reader.acts_as_reader
        Reader.acts_as_reader
        Reader.acts_as_reader
      }.to_not change { ReadMark.reader_classes }
    end
  end

  describe :acts_as_readable do
    it "should define association" do
      expect(@email.read_marks.count).to eq 0
    end

    it "should add class to ReadMark.readable_classes" do
      expect(ReadMark.readable_classes).to eq [ Document ]
    end

    it "should use default options" do
      expect(Email.readable_options).to eq({ on: :updated_at })
    end

    it "should be idempotent" do
      expect {
        Document.acts_as_readable
        Document.acts_as_readable
        Document.acts_as_readable
      }.to_not change { ReadMark.readable_classes }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unread-0.10.0 spec/unread/base_spec.rb