Skip to content

Commit

Permalink
DEV: Update test where it updates all assignments
Browse files Browse the repository at this point in the history
Change `on(:accepted_solution)` is defined

Update test to use acting_user instead of admin
  • Loading branch information
Grubba27 committed Apr 24, 2024
1 parent c1d37ac commit e102d82
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
3 changes: 2 additions & 1 deletion plugin.rb
Expand Up @@ -623,8 +623,9 @@ def self.skip_db?
end
end

if defined?(DiscourseAssign) && SiteSetting.assignment_status_on_solve.present?
if defined?(DiscourseAssign)
on(:accepted_solution) do |post|
next if SiteSetting.assignment_status_on_solve.blank?
Assigner.new(post.topic, post.acting_user).assign(
post.acting_user,
status: SiteSetting.assignment_status_on_solve,
Expand Down
25 changes: 11 additions & 14 deletions spec/integration/solved_spec.rb
Expand Up @@ -369,34 +369,31 @@

context "with discourse-assign installed", if: defined?(DiscourseAssign) do
let(:admin) { Fabricate(:admin) }
fab!(:group)

before do
SiteSetting.solved_enabled = true
SiteSetting.assign_enabled = true
SiteSetting.enable_assign_status = true
SiteSetting.assign_allowed_on_groups = "#{group.id}"
SiteSetting.assigns_public = true
SiteSetting.assignment_status_on_solve = "Done"
sign_in(admin)

group.add(p1.acting_user)
group.add(user)

sign_in(user)
end

it "update all assignments to this status when a post is accepted" do
Jobs.run_immediately!
assigner = Assigner.new(p1.topic, admin)
result = assigner.assign(admin)
assigner = Assigner.new(p1.topic, user)
result = assigner.assign(user)
expect(result[:success]).to eq(true)

expect(p1.topic.assignment.status).to eq("New")

# post "/solution/accept.json", params: { id: p1.id }
# expect(response.status).to eq(200)

DiscourseSolved.accept_answer!(p1, admin)
DiscourseSolved.accept_answer!(p1, user)

expect(p1.reload.custom_fields["is_accepted_answer"]).to eq("true")

# still does not trigger
# DiscourseEvent.trigger(:accepted_solution, p1)
# It runs inside of a DistributedMutex.synchronize

expect(p1.topic.assignment.reload.status).to eq("Done")
end
end
Expand Down

0 comments on commit e102d82

Please sign in to comment.