Commit 506235eb authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix flash message for anonymous search

We need to use flash.now so that the message does not persist to the
next page load since we're not redirecting
parent 550065c4
...@@ -16,7 +16,7 @@ module IssuableCollections ...@@ -16,7 +16,7 @@ module IssuableCollections
def show_alert_if_search_is_disabled def show_alert_if_search_is_disabled
return if current_user || params[:search].blank? || !html_request? || Feature.disabled?(:disable_anonymous_search, type: :ops) return if current_user || params[:search].blank? || !html_request? || Feature.disabled?(:disable_anonymous_search, type: :ops)
flash[:notice] = _('You must sign in to search for specific terms.') flash.now[:notice] = _('You must sign in to search for specific terms.')
end end
# rubocop:disable Gitlab/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
......
...@@ -125,7 +125,7 @@ class Explore::ProjectsController < Explore::ApplicationController ...@@ -125,7 +125,7 @@ class Explore::ProjectsController < Explore::ApplicationController
def show_alert_if_search_is_disabled def show_alert_if_search_is_disabled
return if current_user || params[:name].blank? && params[:search].blank? || !html_request? || Feature.disabled?(:disable_anonymous_project_search, type: :ops) return if current_user || params[:name].blank? && params[:search].blank? || !html_request? || Feature.disabled?(:disable_anonymous_project_search, type: :ops)
flash[:notice] = _('You must sign in to search for specific projects.') flash.now[:notice] = _('You must sign in to search for specific projects.')
end end
end end
......
...@@ -214,7 +214,7 @@ RSpec.describe Explore::ProjectsController do ...@@ -214,7 +214,7 @@ RSpec.describe Explore::ProjectsController do
sign_in(create(:user)) sign_in(create(:user))
get controller_action, params: params_with_name get controller_action, params: params_with_name
expect(flash[:notice]).to be_nil expect(flash.now[:notice]).to be_nil
end end
end end
end end
...@@ -260,14 +260,14 @@ RSpec.describe Explore::ProjectsController do ...@@ -260,14 +260,14 @@ RSpec.describe Explore::ProjectsController do
it 'shows a flash message' do it 'shows a flash message' do
get controller_action, params: params_with_name get controller_action, params: params_with_name
expect(flash[:notice]).to eq('You must sign in to search for specific projects.') expect(flash.now[:notice]).to eq('You must sign in to search for specific projects.')
end end
context 'when search param is not given' do context 'when search param is not given' do
it 'does not show a flash message' do it 'does not show a flash message' do
get controller_action get controller_action
expect(flash[:notice]).to be_nil expect(flash.now[:notice]).to be_nil
end end
end end
...@@ -275,7 +275,7 @@ RSpec.describe Explore::ProjectsController do ...@@ -275,7 +275,7 @@ RSpec.describe Explore::ProjectsController do
it 'does not show a flash message' do it 'does not show a flash message' do
get controller_action, params: params_with_name.merge(format: :atom) get controller_action, params: params_with_name.merge(format: :atom)
expect(flash[:notice]).to be_nil expect(flash.now[:notice]).to be_nil
end end
end end
end end
...@@ -288,7 +288,7 @@ RSpec.describe Explore::ProjectsController do ...@@ -288,7 +288,7 @@ RSpec.describe Explore::ProjectsController do
it 'does not show a flash message' do it 'does not show a flash message' do
get controller_action, params: params_with_name get controller_action, params: params_with_name
expect(flash[:notice]).to be_nil expect(flash.now[:notice]).to be_nil
end end
end end
end end
......
...@@ -12,14 +12,14 @@ RSpec.shared_examples 'issuable list with anonymous search disabled' do |action| ...@@ -12,14 +12,14 @@ RSpec.shared_examples 'issuable list with anonymous search disabled' do |action|
it 'shows a flash message' do it 'shows a flash message' do
get controller_action, params: params_with_search get controller_action, params: params_with_search
expect(flash[:notice]).to eq('You must sign in to search for specific terms.') expect(flash.now[:notice]).to eq('You must sign in to search for specific terms.')
end end
context 'when search param is not given' do context 'when search param is not given' do
it 'does not show a flash message' do it 'does not show a flash message' do
get controller_action, params: params get controller_action, params: params
expect(flash[:notice]).to be_nil expect(flash.now[:notice]).to be_nil
end end
end end
...@@ -28,7 +28,7 @@ RSpec.shared_examples 'issuable list with anonymous search disabled' do |action| ...@@ -28,7 +28,7 @@ RSpec.shared_examples 'issuable list with anonymous search disabled' do |action|
sign_in(create(:user)) sign_in(create(:user))
get controller_action, params: params_with_search get controller_action, params: params_with_search
expect(flash[:notice]).to be_nil expect(flash.now[:notice]).to be_nil
end end
end end
...@@ -36,7 +36,7 @@ RSpec.shared_examples 'issuable list with anonymous search disabled' do |action| ...@@ -36,7 +36,7 @@ RSpec.shared_examples 'issuable list with anonymous search disabled' do |action|
it 'does not show a flash message' do it 'does not show a flash message' do
get controller_action, params: params_with_search.merge(format: :atom) get controller_action, params: params_with_search.merge(format: :atom)
expect(flash[:notice]).to be_nil expect(flash.now[:notice]).to be_nil
end end
end end
end end
...@@ -49,7 +49,7 @@ RSpec.shared_examples 'issuable list with anonymous search disabled' do |action| ...@@ -49,7 +49,7 @@ RSpec.shared_examples 'issuable list with anonymous search disabled' do |action|
it 'does not show a flash message' do it 'does not show a flash message' do
get controller_action, params: params_with_search get controller_action, params: params_with_search
expect(flash[:notice]).to be_nil expect(flash.now[:notice]).to be_nil
end end
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