Files
growstuff/spec/models/notification_spec.rb
google-labs-jules[bot] 8564ec7a7c Add comments to photos (#4130)
* Add comments to photos

Extend the photo show page to support comments by logged in users.

- Make the Comment model polymorphic.
- Update the Photo and Post models to have comments.
- Update the comments controller to handle the polymorphic association.
- Update the photo show page to display comments and a comment form.
- Create a reusable comments partial.

* Add migration

* Fix tests

* Fix tests

* Slightly fix tests

* Fix variables

* Add field

* Refactor slightly

* Refactor slightly

* Refactor slightly

* Refactor

* Photos respond to this as well

* Refactor to polymorphic_url

* Rename

* Wrong relationship

* Refactor and fix tests

* Fix relationships

* Fix rendering

* Fix tests

* Fix model tests

* Fix test

* Fix test

* Fix test

* Fix test

* Fix controller spec

* Fix view tests

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2025-08-24 21:10:16 +09:30

55 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe Notification do
let(:notification) { FactoryBot.create(:notification) }
it "belongs to a post" do
expect(notification.notifiable).to be_an_instance_of Post
end
it "belongs to a recipient" do
expect(notification.recipient).to be_an_instance_of Member
end
it "belongs to a sender" do
expect(notification.sender).to be_an_instance_of Member
end
it "has a scope for unread" do
expect(described_class.unread).to eq [notification]
@n2 = FactoryBot.create(:notification, read: true)
expect(described_class.unread).to eq [notification]
@n3 = FactoryBot.create(:notification, read: false)
expect(described_class.unread).to include @n3
expect(described_class.unread).to include notification
end
it "sends email if asked" do
@notification2 = FactoryBot.create(:notification)
@notification2.send_message
expect(ActionMailer::Base.deliveries.last&.to).to eq [@notification2.recipient.email]
end
it "doesn't send email to people who don't want it" do
FactoryBot.create(:no_email_notification).send_message
expect(ActionMailer::Base.deliveries.last&.to).not_to eq [notification.recipient.email]
end
it "sends email on creation" do
@notification2 = FactoryBot.create(:notification)
expect(ActionMailer::Base.deliveries.last&.to).to eq [@notification2.recipient.email]
end
it "replaces missing subjects with (no subject)" do
notification = FactoryBot.create(:notification, subject: nil)
expect(notification.subject).to eq "(no subject)"
end
it "replaces whitespace-only subjects with (no subject)" do
notification = FactoryBot.create(:notification, subject: " ")
expect(notification.subject).to eq "(no subject)"
end
end