Sha256: 9bf8013eaa2e92cd781cc28c16d302591237dc83198b4dc6b66a1110b2bd9208

Contents?: true

Size: 1.96 KB

Versions: 26

Compression:

Stored size: 1.96 KB

Contents

describe UserMailbox do
  let(:user)         { create(:user) }
  let(:another_user) { create(:user) }
  before do
    another_user.send_message(user, "Test Message", "Test Subject")
    user.send_message(another_user, "Test Message", "Test Subject")
  end

  subject { described_class.new(user) }

  describe "#inbox" do
    subject { described_class.new(user).inbox.first.last_message }
    it "has mail" do
      expect(subject.body).to eq('Test Message')
      expect(subject.subject).to eq('Test Subject')
      expect(user.mailbox.inbox(unread: true).count).to eq(0)
    end
  end

  describe "#delete_all" do
    before do
      another_user.send_message(user, 'message 2', 'subject 2')
      another_user.send_message(user, 'message 3', 'subject 3')
    end
    it "deletes all messages" do
      expect(user.mailbox.inbox.count).to eq(3)
      subject.delete_all
      expect(user.mailbox.inbox.count).to eq(0)
    end
  end

  describe "#delete" do
    let(:rec)         { another_user.send_message(user, 'message 2', 'subject 2') }
    let!(:message_id) { rec.conversation.id }

    it "deletes a message" do
      subject.destroy message_id
      expect { Mailboxer::Conversation.find(message_id) }.to raise_error(ActiveRecord::RecordNotFound)
    end

    context "non-existing conversation" do
      let!(:message_id) { -99 }
      it "raises an error" do
        expect { subject.destroy message_id }.to raise_error(ActiveRecord::RecordNotFound)
      end
    end

    context "deleting a message from a third party" do
      let(:curator)     { create(:user) }
      let(:message)     { another_user.send_message(curator, 'message 3', 'subject 3') }
      let!(:message_id) { message.conversation.id }

      it "does not delete the message" do
        subject.destroy message_id
        expect(subject.destroy(message_id)).to eq "You do not have privileges to delete the notification..."
        expect(Mailboxer::Conversation.find(message_id).id).to eq message_id
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
hyrax-1.1.1 spec/models/user_mailbox_spec.rb
hyrax-1.1.0 spec/models/user_mailbox_spec.rb
sufia-7.4.1 spec/models/user_mailbox_spec.rb
hyrax-1.0.5 spec/models/user_mailbox_spec.rb
sufia-7.4.0 spec/models/user_mailbox_spec.rb
hyrax-1.0.4 spec/models/user_mailbox_spec.rb
hyrax-1.0.3 spec/models/user_mailbox_spec.rb
hyrax-1.0.2 spec/models/user_mailbox_spec.rb
hyrax-1.0.1 spec/models/user_mailbox_spec.rb
hyrax-1.0.0.rc2 spec/models/user_mailbox_spec.rb
sufia-7.3.1 spec/models/user_mailbox_spec.rb
hyrax-1.0.0.rc1 spec/models/user_mailbox_spec.rb
sufia-7.3.0 spec/models/user_mailbox_spec.rb
sufia-7.3.0.rc3 spec/models/user_mailbox_spec.rb
sufia-7.3.0.rc2 spec/models/user_mailbox_spec.rb
sufia-7.3.0.rc1 spec/models/user_mailbox_spec.rb
test_hyrax-0.0.1.alpha spec/models/user_mailbox_spec.rb
sufia-7.2.0 spec/models/user_mailbox_spec.rb
sufia-7.1.0 spec/models/user_mailbox_spec.rb
sufia-7.0.0 spec/models/user_mailbox_spec.rb