Auto-subscribe to comments on articles from feed (#13717)
* Auto-subscribe to comments on articles from feed * Change specs * Update spec again
This commit is contained in:
parent
2463ac7194
commit
e53b6bff85
2 changed files with 25 additions and 0 deletions
|
|
@ -141,6 +141,7 @@ module Feeds
|
|||
organization_id: nil,
|
||||
)
|
||||
|
||||
subscribe_author_to_comments(user, article)
|
||||
articles.append(article)
|
||||
rescue StandardError => e
|
||||
# TODO: add better exception handling
|
||||
|
|
@ -171,5 +172,14 @@ module Feeds
|
|||
|
||||
feed.entries ? feed.entries.length : "no count"
|
||||
end
|
||||
|
||||
def subscribe_author_to_comments(user, article)
|
||||
NotificationSubscription.create!(
|
||||
user: user,
|
||||
notifiable_id: article.id,
|
||||
notifiable_type: "Article",
|
||||
config: "all_comments",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@ RSpec.describe Feeds::Import, type: :service, vcr: true do
|
|||
expect(num_articles).to eq(21)
|
||||
end
|
||||
|
||||
it "subscribes the article author to comments", vcr: { cassette_name: "feeds_import" } do
|
||||
expect { described_class.call }
|
||||
.to change { NotificationSubscription.where(notifiable_type: "Article", config: "all_comments").count }
|
||||
.from(0)
|
||||
end
|
||||
|
||||
it "does not recreate articles if they already exist", vcr: { cassette_name: "feeds_import_twice" } do
|
||||
described_class.call
|
||||
|
||||
|
|
@ -48,6 +54,15 @@ RSpec.describe Feeds::Import, type: :service, vcr: true do
|
|||
end
|
||||
|
||||
context "when handling errors", vcr: { cassette_name: "feeds_import" } do
|
||||
it "reports an notification subscription creation error" do
|
||||
allow(NotificationSubscription).to receive(:create!).and_raise(StandardError)
|
||||
allow(Rails.logger).to receive(:error)
|
||||
|
||||
described_class.call
|
||||
|
||||
expect(Rails.logger).to have_received(:error).at_least(:once)
|
||||
end
|
||||
|
||||
it "reports an article creation error" do
|
||||
allow(Article).to receive(:create!).and_raise(StandardError)
|
||||
allow(Rails.logger).to receive(:error)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue