<commit_before>require 'rails_helper'

describe EmailDigest do

  describe "create" do
    pending "only send unread notifications"
  end

end<commit_msg>adds specs<commit_after>require 'rails_helper'

describe EmailDigest do

  describe "notifications" do

    it "returns notifications for a user" do
      user1 = create(:user)
      user2 = create(:user)

      proposal_notification = create(:proposal_notification)
      notification1 = create(:notification, notifiable: proposal_notification, user: user1)
      notification2 = create(:notification, notifiable: proposal_notification, user: user2)

      email_digest = EmailDigest.new(user1)

      expect(email_digest.notifications).to include(notification1)
      expect(email_digest.notifications).to_not include(notification2)
    end

    it "returns only proposal notifications" do
      user = create(:user)

      proposal_notification = create(:proposal_notification)
      comment = create(:comment)

      notification1 = create(:notification, notifiable: proposal_notification, user: user)
      notification2 = create(:notification, notifiable: comment,               user: user)

      email_digest = EmailDigest.new(user)

      expect(email_digest.notifications).to include(notification1)
      expect(email_digest.notifications).to_not include(notification2)
    end

  end

  describe "pending_notifications?" do

    it "returns true when notifications have not been emailed" do
      user = create(:user)

      proposal_notification = create(:proposal_notification)
      notification = create(:notification, notifiable: proposal_notification, user: user)

      email_digest = EmailDigest.new(user)
      expect(email_digest.pending_notifications?).to be
    end

    it "returns false when notifications have been emailed" do
      user = create(:user)

      proposal_notification = create(:proposal_notification)
      notification = create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.now)

      email_digest = EmailDigest.new(user)
      expect(email_digest.pending_notifications?).to_not be
    end

    it "returns false when there are no notifications for a user" do
      user = create(:user)
      email_digest = EmailDigest.new(user)
      expect(email_digest.pending_notifications?).to_not be
    end

  end

  describe "deliver" do

    it "delivers email if notifications pending" do
      user = create(:user)

      proposal_notification = create(:proposal_notification)
      notification = create(:notification, notifiable: proposal_notification, user: user)

      email_digest = EmailDigest.new(user)
      email_digest.deliver

      email = open_last_email
      expect(email).to have_subject("Proposal notifications in Consul")
    end

    it "does not deliver email if no notifications pending" do
      user = create(:user)

      proposal_notification = create(:proposal_notification)
      notification = create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.now)

      email_digest = EmailDigest.new(user)
      email_digest.deliver

      expect(all_emails.count).to eq(0)
    end

  end

end
{'fraction_non_alphanumeric': 0.07823343848580441, 'fraction_numerical': 0.004416403785488959, 'mean_word_length': 3.8191489361702127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4914307', 'n_tokens_mistral': 889, 'n_tokens_neox': 826, 'n_words': 222}