Files
grecia/spec/shared/models/notifiable.rb
Javi Martín 15f7632f3d Refactor notifiable_available? method
This method was calling `check_availability`, which returned a boolean
value and caused a `Naming/PredicateMethod` when upgrading rubocop.

So we're changing the logic a little bit to remove the
`check_availability` method and merge the tests of `check_availability`
and `notifiable_available?` (which were almost identical) together.
2025-11-05 14:27:11 +01:00

70 lines
2.3 KiB
Ruby

shared_examples "notifiable" do
let(:notifiable) { create(model_name(described_class)) }
describe "#notification_title" do
it "returns the notifiable title when it's a root comment" do
notification = create(:notification, notifiable: notifiable)
expect(notification.notifiable_title).to eq notifiable.title
end
it "returns the notifiable title when it's a reply to a root comment" do
comment = create(:comment, commentable: notifiable)
notification = create(:notification, notifiable: comment)
expect(notification.notifiable_title).to eq notifiable.title
end
end
describe "notifiable_available?" do
it "returns true if the resource is present, not hidden, nor retired" do
notification = create(:notification, notifiable: notifiable)
expect(notification.notifiable_available?).to be true
end
it "returns true when it's a reply to comment and the notifiable is available" do
comment = create(:comment, commentable: notifiable)
notification = create(:notification, notifiable: comment)
expect(notification.notifiable_available?).to be true
end
it "returns false if the resource is hidden" do
notification = create(:notification, notifiable: notifiable)
notifiable.hide
notification.reload
expect(notification.notifiable_available?).not_to be true
end
it "returns false when it's a reply to comment and the commentable has been hidden" do
comment = create(:comment, commentable: notifiable)
notification = create(:notification, notifiable: comment)
notifiable.hide
notification.reload
expect(notification.notifiable_available?).to be false
end
it "returns false if the resource is not present" do
notification = create(:notification, notifiable: notifiable)
notifiable.really_destroy!
expect(notification.notifiable_available?).to be false
end
it "returns false if the resource is retired" do
notification = create(:notification, notifiable: notifiable)
if notifiable.respond_to?(:retired_at)
notifiable.update!(retired_at: Time.current, retired_reason: "unfeasible",
retired_explanation: "Unfeasibility explanation ...")
expect(notification.notifiable_available?).to be false
end
end
end
end