Add JSON API support for timezone update (#2806)
* Add JSON API support for timezone update * Simplify timezone controller to just head :no_content * Use PUT instead of PATCH in timezone tests to match docs * Use PATCH instead of PUT for timezone endpoint Reverts tests to use patch and updates docs heading to PATCH for consistency.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
class My::TimezonesController < ApplicationController
|
class My::TimezonesController < ApplicationController
|
||||||
def update
|
def update
|
||||||
Current.user.settings.update!(timezone_name: timezone_param)
|
Current.user.settings.update!(timezone_name: timezone_param)
|
||||||
|
head :no_content
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -44,3 +44,23 @@ __Response:__
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `PATCH /my/timezone`
|
||||||
|
|
||||||
|
Updates the current user's timezone. This affects how times are displayed in notification emails.
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
|-----------|------|----------|-------------|
|
||||||
|
| `timezone_name` | string | Yes | IANA timezone identifier (e.g. `America/New_York`, `Europe/London`, `Asia/Tokyo`) |
|
||||||
|
|
||||||
|
__Request:__
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"timezone_name": "America/New_York"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
__Response:__
|
||||||
|
|
||||||
|
Returns `204 No Content` on success.
|
||||||
|
|||||||
@@ -12,4 +12,11 @@ class My::TimezonesControllerTest < ActionDispatch::IntegrationTest
|
|||||||
patch my_timezone_path, params: { timezone_name: "America/New_York" }
|
patch my_timezone_path, params: { timezone_name: "America/New_York" }
|
||||||
assert_equal time_zone, users(:kevin).reload.timezone
|
assert_equal time_zone, users(:kevin).reload.timezone
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "update as JSON" do
|
||||||
|
assert_not_equal ActiveSupport::TimeZone["America/Chicago"], users(:kevin).timezone
|
||||||
|
patch my_timezone_path, params: { timezone_name: "America/Chicago" }, as: :json
|
||||||
|
assert_response :no_content
|
||||||
|
assert_equal ActiveSupport::TimeZone["America/Chicago"], users(:kevin).reload.timezone
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user