Commit 3ec7029d authored by Igor Drozdov's avatar Igor Drozdov

Verify flash on controller instead of response

Since we removed include ActionDispatch::TestProcess
the flash now isn't mixed into response.

We need to change it to the controller object that
does have the flash
parent 7f29cfb2
......@@ -201,7 +201,7 @@ RSpec.describe Admin::ApplicationSettingsController do
put :update, params: { application_setting: { repository_size_limit: '100' } }
expect(response).to redirect_to(general_admin_application_settings_path)
expect(response).to set_flash[:notice].to('Application settings saved successfully')
expect(controller).to set_flash[:notice].to('Application settings saved successfully')
end
it 'does not accept negative repository_size_limit' do
......
......@@ -26,7 +26,7 @@ RSpec.describe Admin::GroupsController do
subject
expect(response).to redirect_to(admin_group_path(group))
expect(response).to set_flash[:notice]
expect(controller).to set_flash[:notice]
end
end
......@@ -37,7 +37,7 @@ RSpec.describe Admin::GroupsController do
subject
expect(response).to render_template(:edit)
expect(response).to set_flash.now[:error]
expect(controller).to set_flash.now[:error]
end
end
end
......
......@@ -76,7 +76,7 @@ RSpec.describe Admin::UsersController do
subject
expect(response).to redirect_to(admin_user_path(user))
expect(response).to set_flash[:notice]
expect(controller).to set_flash[:notice]
end
end
......@@ -87,7 +87,7 @@ RSpec.describe Admin::UsersController do
subject
expect(response).to render_template(:edit)
expect(response).to set_flash.now[:error]
expect(controller).to set_flash.now[:error]
end
end
end
......
......@@ -123,7 +123,7 @@ RSpec.describe Groups::GroupMembersController do
it 'creates a new access request to the group' do
post :request_access, params: { group_id: group }
expect(response).to set_flash.to 'Your request for access has been queued for review.'
expect(controller).to set_flash.to 'Your request for access has been queued for review.'
expect(response).to redirect_to(group_path(group))
expect(group.requesters.exists?(user_id: requesting_user)).to be_truthy
expect(group.users).not_to include requesting_user
......@@ -156,7 +156,7 @@ RSpec.describe Groups::GroupMembersController do
it 'does not create a new access request' do
post :request_access, params: { group_id: group }
expect(response).to set_flash.to "Your request for access could not be processed: "\
expect(controller).to set_flash.to "Your request for access could not be processed: "\
"User email 'unverified@gitlab.com' is not a verified email."
expect(response).to redirect_to(group_path(group))
expect(group.requesters.exists?(user_id: requesting_user)).to be_falsey
......@@ -199,7 +199,7 @@ RSpec.describe Groups::GroupMembersController do
post :request_access, params: { group_id: group }
expect(response).to redirect_to(new_user_session_path)
expect(response).to set_flash.to I18n.t('devise.failure.unconfirmed')
expect(controller).to set_flash.to I18n.t('devise.failure.unconfirmed')
expect(group.requesters.exists?(user_id: requesting_user)).to be_falsey
expect(group.users).not_to include requesting_user
end
......
......@@ -45,7 +45,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do
post_create
expect(response).to set_flash[:notice].to('Subscription successfully created.')
expect(controller).to set_flash[:notice].to('Subscription successfully created.')
end
it 'redirects to ci_cd settings' do
......@@ -67,7 +67,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do
post_create
expect(response).to set_flash[:alert].to(['Maximum number of ci project subscriptions (2) exceeded'])
expect(controller).to set_flash[:alert].to(['Maximum number of ci project subscriptions (2) exceeded'])
end
it 'redirects to ci_cd settings' do
......@@ -90,7 +90,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do
post_create
expect(response).to set_flash[:alert].to(['Upstream project needs to be public'])
expect(controller).to set_flash[:alert].to(['Upstream project needs to be public'])
end
it 'redirects to ci_cd settings' do
......@@ -109,7 +109,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do
post_create
expect(response).to set_flash[:warning].to('This project path either does not exist or you do not have access.')
expect(controller).to set_flash[:warning].to('This project path either does not exist or you do not have access.')
end
it 'redirects to ci_cd settings' do
......@@ -174,7 +174,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do
delete_destroy
expect(response).to set_flash[:notice].to('Subscription successfully deleted.')
expect(controller).to set_flash[:notice].to('Subscription successfully deleted.')
end
it 'redirects to ci_cd settings' do
......
......@@ -8,7 +8,7 @@ RSpec.describe Registrations::GroupsController do
shared_examples 'hides email confirmation warning' do
RSpec::Matchers.define :set_confirm_warning_for do |email|
match do |response|
expect(response).to set_flash.now[:warning].to include("Please check your email (#{email}) to verify that you own this address and unlock the power of CI/CD.")
expect(controller).to set_flash.now[:warning].to include("Please check your email (#{email}) to verify that you own this address and unlock the power of CI/CD.")
end
end
......
......@@ -69,12 +69,20 @@ RSpec.describe Subscriptions::GroupsController do
expect(subject).to redirect_to('/new-path')
end
it { is_expected.to set_flash[:notice].to('Subscription successfully applied to "New name"') }
it 'sets flash notice' do
subject
expect(controller).to set_flash[:notice].to('Subscription successfully applied to "New name"')
end
context 'with new_user param' do
subject { post :update, params: { id: group.to_param, group: params, new_user: 'true' } }
it { is_expected.to set_flash[:notice].to("Welcome to GitLab, #{user.first_name}!") }
it 'sets flash notice' do
subject
expect(controller).to set_flash[:notice].to("Welcome to GitLab, #{user.first_name}!")
end
end
end
......
......@@ -365,7 +365,7 @@ RSpec.describe TrialsController do
RSpec::Matchers.define :set_confirm_warning_for do |email|
match do |response|
expect(response).to set_flash.now[:warning].to include("Please check your email (#{email}) to verify that you own this address and unlock the power of CI/CD.")
expect(controller).to set_flash.now[:warning].to include("Please check your email (#{email}) to verify that you own this address and unlock the power of CI/CD.")
end
end
......
......@@ -55,7 +55,7 @@ RSpec.describe Admin::GroupsController do
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'Users were successfully added.'
expect(controller).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(admin_group_path(group))
expect(group.users).to include group_user
end
......@@ -67,7 +67,7 @@ RSpec.describe Admin::GroupsController do
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'Users were successfully added.'
expect(controller).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(admin_group_path(group))
end
......@@ -78,7 +78,7 @@ RSpec.describe Admin::GroupsController do
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'No users specified.'
expect(controller).to set_flash.to 'No users specified.'
expect(response).to redirect_to(admin_group_path(group))
expect(group.users).not_to include group_user
end
......
......@@ -18,7 +18,7 @@ RSpec.describe ConfirmEmailWarning do
RSpec::Matchers.define :set_confirm_warning_for do |email|
match do |response|
expect(response).to set_flash.now[:warning].to include("Please check your email (#{email}) to verify that you own this address and unlock the power of CI/CD.")
expect(controller).to set_flash.now[:warning].to include("Please check your email (#{email}) to verify that you own this address and unlock the power of CI/CD.")
end
end
......
......@@ -27,7 +27,7 @@ RSpec.describe RedirectsForMissingPathOnTree, type: :controller do
get :fake, params: { project_id: project.id, ref: 'theref', file_path: long_file_path }
expect(response).to redirect_to project_tree_path(project, 'theref')
expect(response.flash[:notice]).to eq(expected_message)
expect(controller).to set_flash[:notice].to eq(expected_message)
end
end
end
......@@ -130,7 +130,7 @@ RSpec.describe Groups::GroupMembersController do
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'Users were successfully added.'
expect(controller).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(group_group_members_path(group))
expect(group.users).to include group_user
end
......@@ -142,7 +142,7 @@ RSpec.describe Groups::GroupMembersController do
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'No users specified.'
expect(controller).to set_flash.to 'No users specified.'
expect(response).to redirect_to(group_group_members_path(group))
expect(group.users).not_to include group_user
end
......@@ -180,7 +180,7 @@ RSpec.describe Groups::GroupMembersController do
it 'adds user to members' do
subject
expect(response).to set_flash.to 'Users were successfully added.'
expect(controller).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(group_group_members_path(group))
expect(group.users).to include group_user
end
......@@ -330,7 +330,7 @@ RSpec.describe Groups::GroupMembersController do
it '[HTML] removes user from members' do
delete :destroy, params: { group_id: group, id: member }
expect(response).to set_flash.to 'User was successfully removed from group.'
expect(controller).to set_flash.to 'User was successfully removed from group.'
expect(response).to redirect_to(group_group_members_path(group))
expect(group.members).not_to include member
expect(sub_group.members).to include sub_member
......@@ -339,7 +339,7 @@ RSpec.describe Groups::GroupMembersController do
it '[HTML] removes user from members including subgroups and projects' do
delete :destroy, params: { group_id: group, id: member, remove_sub_memberships: true }
expect(response).to set_flash.to 'User was successfully removed from group and any subgroups and projects.'
expect(controller).to set_flash.to 'User was successfully removed from group and any subgroups and projects.'
expect(response).to redirect_to(group_group_members_path(group))
expect(group.members).not_to include member
expect(sub_group.members).not_to include sub_member
......@@ -377,7 +377,7 @@ RSpec.describe Groups::GroupMembersController do
it 'removes user from members' do
delete :leave, params: { group_id: group }
expect(response).to set_flash.to "You left the \"#{group.name}\" group."
expect(controller).to set_flash.to "You left the \"#{group.name}\" group."
expect(response).to redirect_to(dashboard_groups_path)
expect(group.users).not_to include user
end
......@@ -410,7 +410,7 @@ RSpec.describe Groups::GroupMembersController do
it 'removes user from members' do
delete :leave, params: { group_id: group }
expect(response).to set_flash.to 'Your access request to the group has been withdrawn.'
expect(controller).to set_flash.to 'Your access request to the group has been withdrawn.'
expect(response).to redirect_to(group_path(group))
expect(group.requesters).to be_empty
expect(group.users).not_to include user
......@@ -427,7 +427,7 @@ RSpec.describe Groups::GroupMembersController do
it 'creates a new GroupMember that is not a team member' do
post :request_access, params: { group_id: group }
expect(response).to set_flash.to 'Your request for access has been queued for review.'
expect(controller).to set_flash.to 'Your request for access has been queued for review.'
expect(response).to redirect_to(group_path(group))
expect(group.requesters.exists?(user_id: user)).to be_truthy
expect(group.users).not_to include user
......
......@@ -128,7 +128,7 @@ RSpec.describe Groups::Settings::CiCdController do
end
it 'returns a flash alert' do
expect(response).to set_flash[:alert]
expect(controller).to set_flash[:alert]
.to eq("There was a problem updating Auto DevOps pipeline: [\"Error 1\"].")
end
end
......@@ -137,7 +137,7 @@ RSpec.describe Groups::Settings::CiCdController do
it 'returns a flash notice' do
subject
expect(response).to set_flash[:notice]
expect(controller).to set_flash[:notice]
.to eq('Auto DevOps pipeline was updated for the group')
end
end
......@@ -209,7 +209,7 @@ RSpec.describe Groups::Settings::CiCdController do
end
it 'returns a flash alert' do
expect(response).to set_flash[:alert]
expect(controller).to set_flash[:alert]
.to eq("There was a problem updating the pipeline settings: [\"Error 1\"].")
end
end
......@@ -218,7 +218,7 @@ RSpec.describe Groups::Settings::CiCdController do
it 'returns a flash notice' do
subject
expect(response).to set_flash[:notice]
expect(controller).to set_flash[:notice]
.to eq('Pipeline settings was updated for the group')
end
end
......
......@@ -1704,7 +1704,7 @@ RSpec.describe Projects::IssuesController do
request_csv
expect(response).to redirect_to(project_issues_path(project))
expect(response.flash[:notice]).to match(/\AYour CSV export has started/i)
expect(controller).to set_flash[:notice].to match(/\AYour CSV export has started/i)
end
end
......
......@@ -2229,7 +2229,7 @@ RSpec.describe Projects::MergeRequestsController do
subject
expect(response).to redirect_to(project_merge_requests_path(project))
expect(response.flash[:notice]).to match(/\AYour CSV export has started/i)
expect(controller).to set_flash[:notice].to match(/\AYour CSV export has started/i)
end
it 'enqueues an IssuableExportCsvWorker worker' do
......
......@@ -64,7 +64,7 @@ RSpec.describe Projects::PerformanceMonitoring::DashboardsController do
post :create, params: params
expect(response).to have_gitlab_http_status :created
expect(response).to set_flash[:notice].to eq("Your dashboard has been copied. You can <a href=\"/-/ide/project/#{namespace.path}/#{project.name}/edit/#{branch_name}/-/.gitlab/dashboards/#{file_name}\">edit it here</a>.")
expect(controller).to set_flash[:notice].to eq("Your dashboard has been copied. You can <a href=\"/-/ide/project/#{namespace.path}/#{project.name}/edit/#{branch_name}/-/.gitlab/dashboards/#{file_name}\">edit it here</a>.")
expect(json_response).to eq('status' => 'success', 'dashboard' => { 'path' => ".gitlab/dashboards/#{file_name}" })
end
......@@ -203,7 +203,7 @@ RSpec.describe Projects::PerformanceMonitoring::DashboardsController do
put :update, params: params
expect(response).to have_gitlab_http_status :created
expect(response).to set_flash[:notice].to eq("Your dashboard has been updated. You can <a href=\"/-/ide/project/#{namespace.path}/#{project.name}/edit/#{branch_name}/-/.gitlab/dashboards/#{file_name}\">edit it here</a>.")
expect(controller).to set_flash[:notice].to eq("Your dashboard has been updated. You can <a href=\"/-/ide/project/#{namespace.path}/#{project.name}/edit/#{branch_name}/-/.gitlab/dashboards/#{file_name}\">edit it here</a>.")
expect(json_response).to eq('status' => 'success', 'dashboard' => { 'default' => false, 'display_name' => "custom_dashboard.yml", 'path' => ".gitlab/dashboards/#{file_name}", 'system_dashboard' => false })
end
......
......@@ -199,7 +199,7 @@ RSpec.describe Projects::ProjectMembersController do
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'Users were successfully added.'
expect(controller).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(project_project_members_path(project))
end
......@@ -215,7 +215,7 @@ RSpec.describe Projects::ProjectMembersController do
access_level: Gitlab::Access::GUEST
}
expect(response).to set_flash.to 'Message'
expect(controller).to set_flash.to 'Message'
expect(response).to redirect_to(project_project_members_path(project))
end
end
......@@ -276,7 +276,7 @@ RSpec.describe Projects::ProjectMembersController do
it 'adds user to members' do
subject
expect(response).to set_flash.to 'Users were successfully added.'
expect(controller).to set_flash.to 'Users were successfully added.'
expect(response).to redirect_to(project_project_members_path(project))
expect(project.users).to include project_user
end
......@@ -489,7 +489,7 @@ RSpec.describe Projects::ProjectMembersController do
project_id: project
}
expect(response).to set_flash.to "You left the \"#{project.human_name}\" project."
expect(controller).to set_flash.to "You left the \"#{project.human_name}\" project."
expect(response).to redirect_to(dashboard_projects_path)
expect(project.users).not_to include user
end
......@@ -523,7 +523,7 @@ RSpec.describe Projects::ProjectMembersController do
project_id: project
}
expect(response).to set_flash.to 'Your access request to the project has been withdrawn.'
expect(controller).to set_flash.to 'Your access request to the project has been withdrawn.'
expect(response).to redirect_to(project_path(project))
expect(project.requesters).to be_empty
expect(project.users).not_to include user
......@@ -543,7 +543,7 @@ RSpec.describe Projects::ProjectMembersController do
project_id: project
}
expect(response).to set_flash.to 'Your request for access has been queued for review.'
expect(controller).to set_flash.to 'Your request for access has been queued for review.'
expect(response).to redirect_to(
project_path(project)
)
......@@ -639,7 +639,7 @@ RSpec.describe Projects::ProjectMembersController do
it 'imports source project members' do
expect(project.team_members).to include member
expect(response).to set_flash.to 'Successfully imported'
expect(controller).to set_flash.to 'Successfully imported'
expect(response).to redirect_to(
project_project_members_path(project)
)
......
......@@ -271,7 +271,7 @@ RSpec.describe Projects::ServicesController do
expect(response).to redirect_to(edit_project_service_path(project, service))
expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated."
expect(response).to set_flash.now[:alert].to(expected_alert)
expect(controller).to set_flash.now[:alert].to(expected_alert)
end
it 'does not modify service' do
......@@ -317,7 +317,7 @@ RSpec.describe Projects::ServicesController do
it 'renders deprecation warning notice' do
expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated."
expect(response).to set_flash.now[:alert].to(expected_alert)
expect(controller).to set_flash.now[:alert].to(expected_alert)
end
end
......@@ -328,7 +328,7 @@ RSpec.describe Projects::ServicesController do
end
it 'does not render deprecation warning notice' do
expect(response).not_to set_flash.now[:alert]
expect(controller).not_to set_flash.now[:alert]
end
end
end
......
......@@ -162,7 +162,9 @@ RSpec.describe Projects::Settings::CiCdController do
context 'when the project repository is empty' do
it 'sets a notice flash' do
expect(subject).to set_flash[:notice]
subject
expect(controller).to set_flash[:notice]
end
it 'does not queue a CreatePipelineWorker' do
......@@ -178,7 +180,9 @@ RSpec.describe Projects::Settings::CiCdController do
it 'displays a toast message' do
allow(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args)
expect(subject).to set_flash[:toast]
subject
expect(controller).to set_flash[:toast]
end
it 'queues a CreatePipelineWorker' do
......@@ -239,7 +243,9 @@ RSpec.describe Projects::Settings::CiCdController do
let(:params) { { build_timeout_human_readable: '5m' } }
it 'set specified timeout' do
expect(subject).to set_flash[:alert]
subject
expect(controller).to set_flash[:alert]
expect(response).to redirect_to(namespace_project_settings_ci_cd_path)
end
end
......
......@@ -102,7 +102,7 @@ RSpec.describe Projects::StaticSiteEditorController do
it 'redirects to project page and flashes error message' do
expect(response).to redirect_to(project_path(project))
expect(response).to set_flash[:alert].to('invalid')
expect(controller).to set_flash[:alert].to('invalid')
end
end
......
......@@ -85,8 +85,7 @@ RSpec.describe SessionsController do
it 'does not authenticate user' do
post(:create, params: { user: { login: 'invalid', password: 'invalid' } })
expect(response)
.to set_flash.now[:alert].to(/Invalid login or password/)
expect(controller).to set_flash.now[:alert].to(/Invalid login or password/)
end
end
......@@ -348,7 +347,7 @@ RSpec.describe SessionsController do
otp_user_id: user.id
)
expect(response).to set_flash.now[:alert].to(/Invalid login or password/)
expect(controller).to set_flash.now[:alert].to(/Invalid login or password/)
end
end
......@@ -396,7 +395,7 @@ RSpec.describe SessionsController do
end
it 'warns about invalid OTP code' do
expect(response).to set_flash.now[:alert]
expect(controller).to set_flash.now[:alert]
.to(/Invalid two-factor code/)
end
end
......
......@@ -101,7 +101,7 @@ RSpec.describe 'GraphQL' do
login_as(user)
get('/')
post '/api/graphql', params: { query: query }, headers: { 'X-CSRF-Token' => response.session['_csrf_token'] }
post '/api/graphql', params: { query: query }, headers: { 'X-CSRF-Token' => session['_csrf_token'] }
expect(graphql_data['echo']).to eq("\"#{user.username}\" says: Hello world")
end
......
......@@ -40,7 +40,7 @@ RSpec.shared_examples 'project access tokens available #create' do
it 'returns success message' do
subject
expect(response.flash[:notice]).to match('Your new project access token has been created.')
expect(controller).to set_flash[:notice].to match('Your new project access token has been created.')
end
it 'creates project access token' do
......@@ -88,7 +88,7 @@ RSpec.shared_examples 'project access tokens available #create' do
it 'shows a failure alert' do
subject
expect(response.flash[:alert]).to match("Failed to create new project access token: Failed!")
expect(controller).to set_flash[:alert].to match("Failed to create new project access token: Failed!")
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