Skip to content

Conversation

@nattsw
Copy link
Contributor

@nattsw nattsw commented Jan 10, 2025

Language detection is added to the queue every time the post is serialized. We'll move this into the post_process_cooked event instead, since it is not a good idea to overload a serializer.

This is a follow-up from the move for queueing translations to redis here 8fce768.

@nattsw nattsw force-pushed the lang-detection-on-post-event branch 6 times, most recently from 5909f4c to 4fe18db Compare January 13, 2025 03:54
Language detection is added to the queue every time the post is serialized,
move this into the post_created and post_edited events instead.
@nattsw nattsw force-pushed the lang-detection-on-post-event branch from 4fe18db to a5ccdb0 Compare January 13, 2025 04:02
let(:guardian) { Guardian.new(user) }

it "returns false when the post user is not in restrict_translation_by_poster_group" do
SiteSetting.restrict_translation_by_poster_group = "#{group.id + 1}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Making artificial IDs can end up making flaky tests, we should either Fabricate(:group) here to get a new group or do group.remove(user) in this test

Copy link
Contributor Author

@nattsw nattsw Jan 13, 2025

Choose a reason for hiding this comment

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

Would it matter in this case if it is intentional that the group doesn't exist? Technically speaking, we don't update group-type site settings if a group is deleted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it matters, I just know pretty much every time anyone's used an ID that wasn't from a DB model in specs, it has led to flakes especially in parallel testing environments. It's just safer to Fabricate a new one, as you've done now :)

end

it "returns false when the post raw is empty" do
post.update(raw: "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
post.update(raw: "")
post.update!(raw: "")

Copy link
Contributor Author

@nattsw nattsw Jan 13, 2025

Choose a reason for hiding this comment

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

Yeah this one needs to be not ! on purpose. I've updated the spec to make it clear

Copy link
Contributor

@martin-brennan martin-brennan left a comment

Choose a reason for hiding this comment

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

Nice, much better than doing this in the serializer!

@nattsw
Copy link
Contributor Author

nattsw commented Jan 13, 2025

Thanks @martin-brennan!

@nattsw nattsw merged commit c89a85a into main Jan 13, 2025
3 checks passed
@nattsw nattsw deleted the lang-detection-on-post-event branch January 13, 2025 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants