Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Update test setup to work with auto groups #205

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions spec/discourse_code_review/lib/github_pr_syncer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def get_user_email(github_login)
)
end

before { User.set_callback(:create, :after, :ensure_in_trust_level_group) }
after { User.skip_callback(:create, :after, :ensure_in_trust_level_group) }
Comment on lines +92 to +93
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little bit ugly, to avoid this ugly: https://github.com/discourse/discourse/blob/main/spec/rails_helper.rb#L244-L245

This is because the plugin creates new users deep within its belly, and they need the auto-groups for the tag creation not to fail.


describe "#sync_pull_request" do
context "when there are no events" do
let!(:syncer) do
Expand Down
3 changes: 3 additions & 0 deletions spec/discourse_code_review/lib/importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def first_post_of(topic_id)
let(:parent_category) { Fabricate(:category) }
let(:repo) { GithubRepo.new("discourse/discourse", Octokit::Client.new, nil, repo_id: 24) }

before { User.set_callback(:create, :after, :ensure_in_trust_level_group) }
after { User.skip_callback(:create, :after, :ensure_in_trust_level_group) }

it "creates categories with a description" do
category = Category.find_by(id: Importer.new(repo).category_id)

Expand Down
2 changes: 1 addition & 1 deletion spec/discourse_code_review/lib/state/commit_topics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module DiscourseCodeReview
end

describe "#ensure_commit" do
fab!(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:category) { Fabricate(:category) }

it "can handle commits without message" do
Expand Down
4 changes: 4 additions & 0 deletions spec/jobs/code_review_sync_commits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
comment: {
},
)

User.set_callback(:create, :after, :ensure_in_trust_level_group)
end

after { User.skip_callback(:create, :after, :ensure_in_trust_level_group) }

it "creates a commit topic and a category topic, with a full sha in the first post" do
expect {
described_class.new.execute(repo_name: "10xninjarockstar/ultimatetodolist", repo_id: 24)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
end

context "when signed in as an admin" do
fab!(:signed_in_user) { Fabricate(:admin) }
fab!(:another_admin) { Fabricate(:admin) }
fab!(:signed_in_user) { Fabricate(:admin, refresh_auto_groups: true) }
fab!(:another_admin) { Fabricate(:admin, refresh_auto_groups: true) }

before do
SiteSetting.code_review_enabled = true
Expand Down Expand Up @@ -181,7 +181,7 @@
end

it "skips commits from muted categories" do
admin2 = Fabricate(:admin)
admin2 = Fabricate(:admin, refresh_auto_groups: true)

muted_category = Fabricate(:category)

Expand Down Expand Up @@ -220,7 +220,7 @@
create_post(
raw: "this is an old commit",
tags: [SiteSetting.code_review_pending_tag],
user: Fabricate(:admin),
user: Fabricate(:admin, refresh_auto_groups: true),
)

commit =
Expand Down Expand Up @@ -430,7 +430,7 @@
end

describe ".render_next_topic" do
let(:other_user) { Fabricate(:admin) }
let(:other_user) { Fabricate(:admin, refresh_auto_groups: true) }

it "prefers unread topics over read ones" do
commit =
Expand Down