Add avatar downloading to Bluesky scan user job
- Modified process_user_avatar method to enqueue Domain::UserAvatarJob for avatar downloads - Made Domain::UserAvatarJob concrete (removed abstract!) with generic HTTP client - Added smart avatar management: handles new avatars, URL changes, and pending re-enqueues - Added comprehensive test coverage for all avatar scenarios - Updated HTTP mocking in specs to use HttpClientMockHelpers pattern - Fixed caused_by_entry handling for chained HTTP requests - Updated .cursorrules with proper HTTP mocking documentation including caused_by_entry: :any The job now automatically downloads user avatars when scanning Bluesky users.
This commit is contained in:
46
.cursorrules
46
.cursorrules
@@ -10,6 +10,7 @@
|
||||
- For instance, if you modify `app/models/domain/post.rb`, run `bin/rspec spec/models/domain/post_spec.rb`. If you modify `app/views/domain/users/index.html.erb`, run `bin/rspec spec/controllers/domain/users_controller_spec.rb`.
|
||||
- At the end of a long series of changes, run `just test`.
|
||||
- If specs are failing, then fix the failures, and rerun with `bin/rspec <path_to_spec_file>`.
|
||||
- If you need to add logging to a Job to debug it, set `quiet: false` on the spec you are debugging.
|
||||
|
||||
# Typescript Development
|
||||
|
||||
@@ -17,6 +18,51 @@
|
||||
- Styling is done with Tailwind CSS and FontAwesome.
|
||||
- Put new typescript files in `app/javascript/bundles/Main/components/`
|
||||
|
||||
# HTTP Mocking in Job Specs
|
||||
|
||||
When writing specs for jobs that make HTTP requests, use `HttpClientMockHelpers.init_http_client_mock()` instead of manually creating doubles:
|
||||
|
||||
```ruby
|
||||
# CORRECT: Use HttpClientMockHelpers
|
||||
let(:client_mock_config) do
|
||||
[
|
||||
{
|
||||
uri: "https://example.com/api/first-endpoint",
|
||||
status_code: 200,
|
||||
content_type: "application/json",
|
||||
contents: first_response_body,
|
||||
},
|
||||
{
|
||||
uri: "https://example.com/api/second-endpoint",
|
||||
status_code: 200,
|
||||
content_type: "application/json",
|
||||
contents: second_response_body,
|
||||
caused_by_entry: :any, # Use this for chained requests
|
||||
},
|
||||
]
|
||||
end
|
||||
|
||||
before do
|
||||
@log_entries =
|
||||
HttpClientMockHelpers.init_http_client_mock(
|
||||
http_client_mock,
|
||||
client_mock_config,
|
||||
)
|
||||
end
|
||||
|
||||
# WRONG: Don't create doubles manually
|
||||
expect(http_client_mock).to receive(:get).and_return(
|
||||
double(status_code: 200, body: response_body, log_entry: double),
|
||||
)
|
||||
```
|
||||
|
||||
This pattern:
|
||||
|
||||
- Creates real HttpLogEntry objects that can be serialized by ActiveJob
|
||||
- Follows the established codebase pattern
|
||||
- Avoids "Unsupported argument type: RSpec::Mocks::Double" errors
|
||||
- Use `caused_by_entry: :any` for HTTP requests that are chained (where one request's log entry becomes the `caused_by_entry` for the next request)
|
||||
|
||||
# === BACKLOG.MD GUIDELINES START ===
|
||||
|
||||
# Instructions for the usage of Backlog.md CLI Tool
|
||||
|
||||
Reference in New Issue
Block a user