Commit 93ae17ec authored by Patrick Bajao's avatar Patrick Bajao

Add user's preferred language to cache key of MR title partial

This is to fix a bug wherein the Edit button is being shown in a
different language from the current user's preferred language.

Before this fix, when the partial was cached and the language is
different, it'll stay that way until the cache is invalidated.

Now, the current user's preferred language will be taken into
consideration for the cache key.

Changelog: fixed
parent d7c3f9ba
......@@ -2,7 +2,7 @@
- can_update_merge_request = can?(current_user, :update_merge_request, @merge_request)
- can_reopen_merge_request = can?(current_user, :reopen_merge_request, @merge_request)
- are_close_and_open_buttons_hidden = merge_request_button_hidden?(@merge_request, true) && merge_request_button_hidden?(@merge_request, false)
- cache_key = [@project, @merge_request, can_update_merge_request, can_reopen_merge_request, are_close_and_open_buttons_hidden]
- cache_key = [@project, @merge_request, can_update_merge_request, can_reopen_merge_request, are_close_and_open_buttons_hidden, current_user&.preferred_language]
= cache(cache_key, expires_in: 1.day) do
- if @merge_request.closed_or_merged_without_fork?
......
......@@ -128,4 +128,30 @@ RSpec.describe 'User views an open merge request' do
expect(find("[data-testid='ref-name']")[:title]).to eq(source_branch)
end
end
context 'when user preferred language has changed', :use_clean_rails_memory_store_fragment_caching do
let(:project) { create(:project, :public, :repository) }
let(:user) { create(:user) }
before do
project.add_maintainer(user)
sign_in(user)
end
it 'renders edit button in preferred language' do
visit(merge_request_path(merge_request))
page.within('.detail-page-header-actions') do
expect(page).to have_link('Edit')
end
user.update!(preferred_language: 'de')
visit(merge_request_path(merge_request))
page.within('.detail-page-header-actions') do
expect(page).to have_link('Bearbeiten')
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment