Skip to content

Commit

Permalink
ActiveSupport::Notifications listen/forget fix (forem#18549)
Browse files Browse the repository at this point in the history
* active support notifications debug

* Match missing .forget listeners
  • Loading branch information
fdocr authored Oct 7, 2022
1 parent 29421d8 commit 5caca50
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/requests/admin/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@
# These ids match the affected articles/comments and not the ones created above
expect(log.data["target_article_ids"]).to match_array(target_articles.map(&:id))
expect(log.data["target_comment_ids"]).to match_array(target_comments.map(&:id))

Audit::Subscribe.forget :moderator
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/requests/api/v1/articles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,8 @@ def put_article(**params)

before { Audit::Subscribe.listen listener }

after { Audit::Subscribe.forget listener }

context "when unauthorized" do
it "fails with no api key" do
put path, headers: headers
Expand Down
4 changes: 4 additions & 0 deletions spec/requests/api/v1/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@

before { Audit::Subscribe.listen listener }

after { Audit::Subscribe.forget listener }

context "when unauthenticated" do
it "returns unauthorized" do
put api_user_suspend_path(id: target_user.id),
Expand Down Expand Up @@ -193,6 +195,8 @@

before { Audit::Subscribe.listen listener }

after { Audit::Subscribe.forget listener }

context "when unauthenticated" do
it "returns unauthorized" do
put api_user_unpublish_path(id: target_user.id),
Expand Down
4 changes: 4 additions & 0 deletions spec/services/moderator/unpublish_all_articles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@

expect(log.data["target_article_ids"]).to match_array(articles.map(&:id))
expect(log.data["target_comment_ids"]).to match_array(comments.map(&:id))

Audit::Subscribe.forget :admin_api
end

it "creates audit_log records for admin action" do
Expand All @@ -72,5 +74,7 @@
expect(log.slug).to eq("unpublish_all_articles")
expect(log.data["action"]).to eq("unpublish_all_articles")
expect(log.user_id).to eq(admin.id)

Audit::Subscribe.forget :moderator
end
end

0 comments on commit 5caca50

Please sign in to comment.