For the HashAlignment rule, we're using the default `key` style (keys are aligned and values aren't) instead of the `table` style (both keys and values are aligned) because, even if we used both in the application, we used the `key` style a lot more. Furthermore, the `table` style looks strange in places where there are both very long and very short keys and sometimes we weren't even consistent with the `table` style, aligning some keys without aligning other keys. Ideally we could align hashes to "either key or table", so developers can decide whether keeping the symmetry of the code is worth it in a case-per-case basis, but Rubocop doesn't allow this option.
82 lines
2.9 KiB
Ruby
82 lines
2.9 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 when it's a root comment and the notifiable is available" 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 when it's a root comment and the notifiable has been 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
|
|
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)
|
|
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.check_availability(notifiable)).to be(false)
|
|
end
|
|
end
|
|
end
|
|
end
|