Defect #44731
openIssue's history default tab is nil for fixture users
Description
When users are created from fixtures (e.g., in test or development environments), the history_default_tab preference is not initialized, resulting in nil value. This causes issue_history_default_tab helper method to select the first tab instead of the expected default.
Steps to reproduce¶
1. Load test fixtures (rake db:fixtures:load)
2. Check an admin user created from fixtures (e.g., User ID: 1)
3. View User.find(1).pref.others[:history_default_tab]
Expected: 'notes'
Actual: nil
Root cause¶
In test/fixtures/user_preferences.yml, the history_default_tab key is not defined in the :others hash for fixture records.
Example (user_preferences_001):
user_preferences_001:
others: |
---
:no_self_notified: false
:my_page_layout:
...
# history_default_tab is missing here
Consequence¶
The issue_history_default_tab method in app/helpers/issues_helper.rb receives nil and returns it without setting a default value:
def issue_history_default_tab
return params[:tab] if params[:tab].present?
user_default_tab = User.current.pref.history_default_tab
case user_default_tab
when 'last_tab_visited'
cookies['history_last_tab'].presence || 'notes'
when ''
'notes'
else
user_default_tab # Returns nil without handling it
end
end
This causes the first tab (History) to be selected instead of Notes.
Files
Updated by Ahesh Lakmal 14 days ago
The attached patch fixes this in IssuesHelper#issue_history_default_tab instead of in the fixtures.
history_default_tab is nil not only for fixture users but also for anonymous users and for users who never saved their account page, so the Notes tab should be selected when the preference is not set.
Tests added in IssuesControllerTest for a user without the preference and for anonymous.