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.
This commit is contained in:
Javi Martín
2025-10-31 15:11:22 +01:00
parent 2fdfefe55d
commit 15f7632f3d
4 changed files with 23 additions and 41 deletions

View File

@@ -126,27 +126,21 @@ describe ProposalNotification do
expect(notification.notifiable_available?).to be false
end
end
describe "check_availability" do
it "returns true if the resource is present, not hidden, nor retired" do
notification = create(:notification, notifiable: notifiable)
expect(notification.check_availability(proposal)).to be true
end
it "returns false if the resource is not present" do
notification = create(:notification, notifiable: notifiable)
notifiable.proposal.really_destroy!
expect(notification.check_availability(proposal)).to be false
expect(notification.notifiable_available?).to be false
end
it "returns false if the resource is hidden" do
notification = create(:notification, notifiable: notifiable)
notifiable.proposal.hide
expect(notification.check_availability(proposal)).to be false
expect(notification.notifiable_available?).to be false
end
it "returns false if the resource is retired" do
@@ -155,7 +149,8 @@ describe ProposalNotification do
notifiable.proposal.update!(retired_at: Time.current,
retired_explanation: "Unfeasible reason explanation",
retired_reason: "unfeasible")
expect(notification.check_availability(proposal)).to be false
expect(notification.notifiable_available?).to be false
end
end

View File

@@ -17,7 +17,7 @@ shared_examples "notifiable" do
end
describe "notifiable_available?" do
it "returns true when it's a root comment and the notifiable is 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
@@ -30,7 +30,7 @@ shared_examples "notifiable" do
expect(notification.notifiable_available?).to be true
end
it "returns false when it's a root comment and the notifiable has been hidden" do
it "returns false if the resource is hidden" do
notification = create(:notification, notifiable: notifiable)
notifiable.hide
@@ -48,24 +48,12 @@ shared_examples "notifiable" do
expect(notification.notifiable_available?).to be false
end
end
describe "check_availability" do
it "returns true if the resource is present, not hidden, nor retired" do
notification = create(:notification, notifiable: notifiable)
expect(notification.check_availability(notifiable)).to be true
end
it "returns false if the resource is not present" do
notification = create(:notification, notifiable: notifiable)
notifiable.really_destroy!
expect(notification.check_availability(notifiable)).to be false
end
it "returns false if the resource is not hidden" do
notification = create(:notification, notifiable: notifiable)
notifiable.hide
expect(notification.check_availability(notifiable)).to be false
expect(notification.notifiable_available?).to be false
end
it "returns false if the resource is retired" do
@@ -74,7 +62,7 @@ shared_examples "notifiable" do
if notifiable.respond_to?(:retired_at)
notifiable.update!(retired_at: Time.current, retired_reason: "unfeasible",
retired_explanation: "Unfeasibility explanation ...")
expect(notification.check_availability(notifiable)).to be false
expect(notification.notifiable_available?).to be false
end
end
end