Commit d71074ec authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'cherry-pick-e83cb57f' into 'master'

Use Rack::Test::UploadedFile instead of fixture_file_upload [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!59237
parents 3491d296 3ec7029d
...@@ -201,7 +201,7 @@ RSpec.describe Admin::ApplicationSettingsController do ...@@ -201,7 +201,7 @@ RSpec.describe Admin::ApplicationSettingsController do
put :update, params: { application_setting: { repository_size_limit: '100' } } put :update, params: { application_setting: { repository_size_limit: '100' } }
expect(response).to redirect_to(general_admin_application_settings_path) 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 end
it 'does not accept negative repository_size_limit' do it 'does not accept negative repository_size_limit' do
......
...@@ -26,7 +26,7 @@ RSpec.describe Admin::GroupsController do ...@@ -26,7 +26,7 @@ RSpec.describe Admin::GroupsController do
subject subject
expect(response).to redirect_to(admin_group_path(group)) expect(response).to redirect_to(admin_group_path(group))
expect(response).to set_flash[:notice] expect(controller).to set_flash[:notice]
end end
end end
...@@ -37,7 +37,7 @@ RSpec.describe Admin::GroupsController do ...@@ -37,7 +37,7 @@ RSpec.describe Admin::GroupsController do
subject subject
expect(response).to render_template(:edit) expect(response).to render_template(:edit)
expect(response).to set_flash.now[:error] expect(controller).to set_flash.now[:error]
end end
end end
end end
......
...@@ -76,7 +76,7 @@ RSpec.describe Admin::UsersController do ...@@ -76,7 +76,7 @@ RSpec.describe Admin::UsersController do
subject subject
expect(response).to redirect_to(admin_user_path(user)) expect(response).to redirect_to(admin_user_path(user))
expect(response).to set_flash[:notice] expect(controller).to set_flash[:notice]
end end
end end
...@@ -87,7 +87,7 @@ RSpec.describe Admin::UsersController do ...@@ -87,7 +87,7 @@ RSpec.describe Admin::UsersController do
subject subject
expect(response).to render_template(:edit) expect(response).to render_template(:edit)
expect(response).to set_flash.now[:error] expect(controller).to set_flash.now[:error]
end end
end end
end end
......
...@@ -150,7 +150,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -150,7 +150,7 @@ RSpec.describe Groups::GroupMembersController do
it 'creates a new access request to the group' do it 'creates a new access request to the group' do
post :request_access, params: { group_id: group } 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(response).to redirect_to(group_path(group))
expect(group.requesters.exists?(user_id: requesting_user)).to be_truthy expect(group.requesters.exists?(user_id: requesting_user)).to be_truthy
expect(group.users).not_to include requesting_user expect(group.users).not_to include requesting_user
...@@ -183,7 +183,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -183,7 +183,7 @@ RSpec.describe Groups::GroupMembersController do
it 'does not create a new access request' do it 'does not create a new access request' do
post :request_access, params: { group_id: group } 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." "User email 'unverified@gitlab.com' is not a verified email."
expect(response).to redirect_to(group_path(group)) expect(response).to redirect_to(group_path(group))
expect(group.requesters.exists?(user_id: requesting_user)).to be_falsey expect(group.requesters.exists?(user_id: requesting_user)).to be_falsey
...@@ -226,7 +226,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -226,7 +226,7 @@ RSpec.describe Groups::GroupMembersController do
post :request_access, params: { group_id: group } post :request_access, params: { group_id: group }
expect(response).to redirect_to(new_user_session_path) 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.requesters.exists?(user_id: requesting_user)).to be_falsey
expect(group.users).not_to include requesting_user expect(group.users).not_to include requesting_user
end end
......
...@@ -45,7 +45,7 @@ RSpec.describe Projects::SubscriptionsController do ...@@ -45,7 +45,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do it 'sets the flash' do
post_create post_create
expect(response).to set_flash[:notice].to('Subscription successfully created.') expect(controller).to set_flash[:notice].to('Subscription successfully created.')
end end
it 'redirects to ci_cd settings' do it 'redirects to ci_cd settings' do
...@@ -67,7 +67,7 @@ RSpec.describe Projects::SubscriptionsController do ...@@ -67,7 +67,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do it 'sets the flash' do
post_create 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 end
it 'redirects to ci_cd settings' do it 'redirects to ci_cd settings' do
...@@ -90,7 +90,7 @@ RSpec.describe Projects::SubscriptionsController do ...@@ -90,7 +90,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do it 'sets the flash' do
post_create 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 end
it 'redirects to ci_cd settings' do it 'redirects to ci_cd settings' do
...@@ -109,7 +109,7 @@ RSpec.describe Projects::SubscriptionsController do ...@@ -109,7 +109,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do it 'sets the flash' do
post_create 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 end
it 'redirects to ci_cd settings' do it 'redirects to ci_cd settings' do
...@@ -174,7 +174,7 @@ RSpec.describe Projects::SubscriptionsController do ...@@ -174,7 +174,7 @@ RSpec.describe Projects::SubscriptionsController do
it 'sets the flash' do it 'sets the flash' do
delete_destroy delete_destroy
expect(response).to set_flash[:notice].to('Subscription successfully deleted.') expect(controller).to set_flash[:notice].to('Subscription successfully deleted.')
end end
it 'redirects to ci_cd settings' do it 'redirects to ci_cd settings' do
......
...@@ -8,7 +8,7 @@ RSpec.describe Registrations::GroupsController do ...@@ -8,7 +8,7 @@ RSpec.describe Registrations::GroupsController do
shared_examples 'hides email confirmation warning' do shared_examples 'hides email confirmation warning' do
RSpec::Matchers.define :set_confirm_warning_for do |email| RSpec::Matchers.define :set_confirm_warning_for do |email|
match do |response| 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
end end
......
...@@ -69,12 +69,20 @@ RSpec.describe Subscriptions::GroupsController do ...@@ -69,12 +69,20 @@ RSpec.describe Subscriptions::GroupsController do
expect(subject).to redirect_to('/new-path') expect(subject).to redirect_to('/new-path')
end 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 context 'with new_user param' do
subject { post :update, params: { id: group.to_param, group: params, new_user: 'true' } } 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
end end
......
...@@ -365,7 +365,7 @@ RSpec.describe TrialsController do ...@@ -365,7 +365,7 @@ RSpec.describe TrialsController do
RSpec::Matchers.define :set_confirm_warning_for do |email| RSpec::Matchers.define :set_confirm_warning_for do |email|
match do |response| 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
end end
......
...@@ -55,7 +55,7 @@ RSpec.describe Admin::GroupsController do ...@@ -55,7 +55,7 @@ RSpec.describe Admin::GroupsController do
access_level: Gitlab::Access::GUEST 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(response).to redirect_to(admin_group_path(group))
expect(group.users).to include group_user expect(group.users).to include group_user
end end
...@@ -67,7 +67,7 @@ RSpec.describe Admin::GroupsController do ...@@ -67,7 +67,7 @@ RSpec.describe Admin::GroupsController do
access_level: Gitlab::Access::GUEST 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(response).to redirect_to(admin_group_path(group))
end end
...@@ -78,7 +78,7 @@ RSpec.describe Admin::GroupsController do ...@@ -78,7 +78,7 @@ RSpec.describe Admin::GroupsController do
access_level: Gitlab::Access::GUEST 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(response).to redirect_to(admin_group_path(group))
expect(group.users).not_to include group_user expect(group.users).not_to include group_user
end end
......
...@@ -725,7 +725,7 @@ RSpec.describe ApplicationController do ...@@ -725,7 +725,7 @@ RSpec.describe ApplicationController do
format.csv do format.csv do
stream_csv_headers('test.csv') stream_csv_headers('test.csv')
self.response_body = fixture_file_upload('spec/fixtures/csv_comma.csv') self.response_body = Rack::Test::UploadedFile.new('spec/fixtures/csv_comma.csv')
end end
end end
end end
......
...@@ -18,7 +18,7 @@ RSpec.describe ConfirmEmailWarning do ...@@ -18,7 +18,7 @@ RSpec.describe ConfirmEmailWarning do
RSpec::Matchers.define :set_confirm_warning_for do |email| RSpec::Matchers.define :set_confirm_warning_for do |email|
match do |response| 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
end end
......
...@@ -27,7 +27,7 @@ RSpec.describe RedirectsForMissingPathOnTree, type: :controller do ...@@ -27,7 +27,7 @@ RSpec.describe RedirectsForMissingPathOnTree, type: :controller do
get :fake, params: { project_id: project.id, ref: 'theref', file_path: long_file_path } 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).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 end
end end
...@@ -130,7 +130,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -130,7 +130,7 @@ RSpec.describe Groups::GroupMembersController do
access_level: Gitlab::Access::GUEST 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(response).to redirect_to(group_group_members_path(group))
expect(group.users).to include group_user expect(group.users).to include group_user
end end
...@@ -142,7 +142,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -142,7 +142,7 @@ RSpec.describe Groups::GroupMembersController do
access_level: Gitlab::Access::GUEST 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(response).to redirect_to(group_group_members_path(group))
expect(group.users).not_to include group_user expect(group.users).not_to include group_user
end end
...@@ -180,7 +180,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -180,7 +180,7 @@ RSpec.describe Groups::GroupMembersController do
it 'adds user to members' do it 'adds user to members' do
subject 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(response).to redirect_to(group_group_members_path(group))
expect(group.users).to include group_user expect(group.users).to include group_user
end end
...@@ -330,7 +330,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -330,7 +330,7 @@ RSpec.describe Groups::GroupMembersController do
it '[HTML] removes user from members' do it '[HTML] removes user from members' do
delete :destroy, params: { group_id: group, id: member } 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(response).to redirect_to(group_group_members_path(group))
expect(group.members).not_to include member expect(group.members).not_to include member
expect(sub_group.members).to include sub_member expect(sub_group.members).to include sub_member
...@@ -339,7 +339,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -339,7 +339,7 @@ RSpec.describe Groups::GroupMembersController do
it '[HTML] removes user from members including subgroups and projects' do it '[HTML] removes user from members including subgroups and projects' do
delete :destroy, params: { group_id: group, id: member, remove_sub_memberships: true } 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(response).to redirect_to(group_group_members_path(group))
expect(group.members).not_to include member expect(group.members).not_to include member
expect(sub_group.members).not_to include sub_member expect(sub_group.members).not_to include sub_member
...@@ -377,7 +377,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -377,7 +377,7 @@ RSpec.describe Groups::GroupMembersController do
it 'removes user from members' do it 'removes user from members' do
delete :leave, params: { group_id: group } 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(response).to redirect_to(dashboard_groups_path)
expect(group.users).not_to include user expect(group.users).not_to include user
end end
...@@ -410,7 +410,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -410,7 +410,7 @@ RSpec.describe Groups::GroupMembersController do
it 'removes user from members' do it 'removes user from members' do
delete :leave, params: { group_id: group } 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(response).to redirect_to(group_path(group))
expect(group.requesters).to be_empty expect(group.requesters).to be_empty
expect(group.users).not_to include user expect(group.users).not_to include user
...@@ -427,7 +427,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -427,7 +427,7 @@ RSpec.describe Groups::GroupMembersController do
it 'creates a new GroupMember that is not a team member' do it 'creates a new GroupMember that is not a team member' do
post :request_access, params: { group_id: group } 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(response).to redirect_to(group_path(group))
expect(group.requesters.exists?(user_id: user)).to be_truthy expect(group.requesters.exists?(user_id: user)).to be_truthy
expect(group.users).not_to include user expect(group.users).not_to include user
......
...@@ -128,7 +128,7 @@ RSpec.describe Groups::Settings::CiCdController do ...@@ -128,7 +128,7 @@ RSpec.describe Groups::Settings::CiCdController do
end end
it 'returns a flash alert' do 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\"].") .to eq("There was a problem updating Auto DevOps pipeline: [\"Error 1\"].")
end end
end end
...@@ -137,7 +137,7 @@ RSpec.describe Groups::Settings::CiCdController do ...@@ -137,7 +137,7 @@ RSpec.describe Groups::Settings::CiCdController do
it 'returns a flash notice' do it 'returns a flash notice' do
subject subject
expect(response).to set_flash[:notice] expect(controller).to set_flash[:notice]
.to eq('Auto DevOps pipeline was updated for the group') .to eq('Auto DevOps pipeline was updated for the group')
end end
end end
...@@ -209,7 +209,7 @@ RSpec.describe Groups::Settings::CiCdController do ...@@ -209,7 +209,7 @@ RSpec.describe Groups::Settings::CiCdController do
end end
it 'returns a flash alert' do 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\"].") .to eq("There was a problem updating the pipeline settings: [\"Error 1\"].")
end end
end end
...@@ -218,7 +218,7 @@ RSpec.describe Groups::Settings::CiCdController do ...@@ -218,7 +218,7 @@ RSpec.describe Groups::Settings::CiCdController do
it 'returns a flash notice' do it 'returns a flash notice' do
subject subject
expect(response).to set_flash[:notice] expect(controller).to set_flash[:notice]
.to eq('Pipeline settings was updated for the group') .to eq('Pipeline settings was updated for the group')
end end
end end
......
...@@ -1704,7 +1704,7 @@ RSpec.describe Projects::IssuesController do ...@@ -1704,7 +1704,7 @@ RSpec.describe Projects::IssuesController do
request_csv request_csv
expect(response).to redirect_to(project_issues_path(project)) 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
end end
......
...@@ -2229,7 +2229,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -2229,7 +2229,7 @@ RSpec.describe Projects::MergeRequestsController do
subject subject
expect(response).to redirect_to(project_merge_requests_path(project)) 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 end
it 'enqueues an IssuableExportCsvWorker worker' do it 'enqueues an IssuableExportCsvWorker worker' do
......
...@@ -64,7 +64,7 @@ RSpec.describe Projects::PerformanceMonitoring::DashboardsController do ...@@ -64,7 +64,7 @@ RSpec.describe Projects::PerformanceMonitoring::DashboardsController do
post :create, params: params post :create, params: params
expect(response).to have_gitlab_http_status :created 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}" }) expect(json_response).to eq('status' => 'success', 'dashboard' => { 'path' => ".gitlab/dashboards/#{file_name}" })
end end
...@@ -203,7 +203,7 @@ RSpec.describe Projects::PerformanceMonitoring::DashboardsController do ...@@ -203,7 +203,7 @@ RSpec.describe Projects::PerformanceMonitoring::DashboardsController do
put :update, params: params put :update, params: params
expect(response).to have_gitlab_http_status :created 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 }) expect(json_response).to eq('status' => 'success', 'dashboard' => { 'default' => false, 'display_name' => "custom_dashboard.yml", 'path' => ".gitlab/dashboards/#{file_name}", 'system_dashboard' => false })
end end
......
...@@ -199,7 +199,7 @@ RSpec.describe Projects::ProjectMembersController do ...@@ -199,7 +199,7 @@ RSpec.describe Projects::ProjectMembersController do
access_level: Gitlab::Access::GUEST 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)) expect(response).to redirect_to(project_project_members_path(project))
end end
...@@ -215,7 +215,7 @@ RSpec.describe Projects::ProjectMembersController do ...@@ -215,7 +215,7 @@ RSpec.describe Projects::ProjectMembersController do
access_level: Gitlab::Access::GUEST 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)) expect(response).to redirect_to(project_project_members_path(project))
end end
end end
...@@ -276,7 +276,7 @@ RSpec.describe Projects::ProjectMembersController do ...@@ -276,7 +276,7 @@ RSpec.describe Projects::ProjectMembersController do
it 'adds user to members' do it 'adds user to members' do
subject 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(response).to redirect_to(project_project_members_path(project))
expect(project.users).to include project_user expect(project.users).to include project_user
end end
...@@ -489,7 +489,7 @@ RSpec.describe Projects::ProjectMembersController do ...@@ -489,7 +489,7 @@ RSpec.describe Projects::ProjectMembersController do
project_id: project 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(response).to redirect_to(dashboard_projects_path)
expect(project.users).not_to include user expect(project.users).not_to include user
end end
...@@ -523,7 +523,7 @@ RSpec.describe Projects::ProjectMembersController do ...@@ -523,7 +523,7 @@ RSpec.describe Projects::ProjectMembersController do
project_id: project 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(response).to redirect_to(project_path(project))
expect(project.requesters).to be_empty expect(project.requesters).to be_empty
expect(project.users).not_to include user expect(project.users).not_to include user
...@@ -543,7 +543,7 @@ RSpec.describe Projects::ProjectMembersController do ...@@ -543,7 +543,7 @@ RSpec.describe Projects::ProjectMembersController do
project_id: project 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( expect(response).to redirect_to(
project_path(project) project_path(project)
) )
...@@ -639,7 +639,7 @@ RSpec.describe Projects::ProjectMembersController do ...@@ -639,7 +639,7 @@ RSpec.describe Projects::ProjectMembersController do
it 'imports source project members' do it 'imports source project members' do
expect(project.team_members).to include member 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( expect(response).to redirect_to(
project_project_members_path(project) project_project_members_path(project)
) )
......
...@@ -271,7 +271,7 @@ RSpec.describe Projects::ServicesController do ...@@ -271,7 +271,7 @@ RSpec.describe Projects::ServicesController do
expect(response).to redirect_to(edit_project_service_path(project, service)) 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." 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
it 'does not modify service' do it 'does not modify service' do
...@@ -317,7 +317,7 @@ RSpec.describe Projects::ServicesController do ...@@ -317,7 +317,7 @@ RSpec.describe Projects::ServicesController do
it 'renders deprecation warning notice' 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." 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
end end
...@@ -328,7 +328,7 @@ RSpec.describe Projects::ServicesController do ...@@ -328,7 +328,7 @@ RSpec.describe Projects::ServicesController do
end end
it 'does not render deprecation warning notice' do 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 end
end end
......
...@@ -162,7 +162,9 @@ RSpec.describe Projects::Settings::CiCdController do ...@@ -162,7 +162,9 @@ RSpec.describe Projects::Settings::CiCdController do
context 'when the project repository is empty' do context 'when the project repository is empty' do
it 'sets a notice flash' do it 'sets a notice flash' do
expect(subject).to set_flash[:notice] subject
expect(controller).to set_flash[:notice]
end end
it 'does not queue a CreatePipelineWorker' do it 'does not queue a CreatePipelineWorker' do
...@@ -178,7 +180,9 @@ RSpec.describe Projects::Settings::CiCdController do ...@@ -178,7 +180,9 @@ RSpec.describe Projects::Settings::CiCdController do
it 'displays a toast message' do it 'displays a toast message' do
allow(CreatePipelineWorker).to receive(:perform_async).with(project.id, user.id, project.default_branch, :web, any_args) 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 end
it 'queues a CreatePipelineWorker' do it 'queues a CreatePipelineWorker' do
...@@ -239,7 +243,9 @@ RSpec.describe Projects::Settings::CiCdController do ...@@ -239,7 +243,9 @@ RSpec.describe Projects::Settings::CiCdController do
let(:params) { { build_timeout_human_readable: '5m' } } let(:params) { { build_timeout_human_readable: '5m' } }
it 'set specified timeout' do 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) expect(response).to redirect_to(namespace_project_settings_ci_cd_path)
end end
end end
......
...@@ -102,7 +102,7 @@ RSpec.describe Projects::StaticSiteEditorController do ...@@ -102,7 +102,7 @@ RSpec.describe Projects::StaticSiteEditorController do
it 'redirects to project page and flashes error message' do it 'redirects to project page and flashes error message' do
expect(response).to redirect_to(project_path(project)) 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
end end
......
...@@ -85,8 +85,7 @@ RSpec.describe SessionsController do ...@@ -85,8 +85,7 @@ RSpec.describe SessionsController do
it 'does not authenticate user' do it 'does not authenticate user' do
post(:create, params: { user: { login: 'invalid', password: 'invalid' } }) post(:create, params: { user: { login: 'invalid', password: 'invalid' } })
expect(response) expect(controller).to set_flash.now[:alert].to(/Invalid login or password/)
.to set_flash.now[:alert].to(/Invalid login or password/)
end end
end end
...@@ -348,7 +347,7 @@ RSpec.describe SessionsController do ...@@ -348,7 +347,7 @@ RSpec.describe SessionsController do
otp_user_id: user.id 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
end end
...@@ -396,7 +395,7 @@ RSpec.describe SessionsController do ...@@ -396,7 +395,7 @@ RSpec.describe SessionsController do
end end
it 'warns about invalid OTP code' do 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/) .to(/Invalid two-factor code/)
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
include ActionDispatch::TestProcess
FactoryBot.define do FactoryBot.define do
factory :ci_build, class: 'Ci::Build', parent: :ci_processable do factory :ci_build, class: 'Ci::Build', parent: :ci_processable do
name { 'test' } name { 'test' }
......
# frozen_string_literal: true # frozen_string_literal: true
include ActionDispatch::TestProcess
FactoryBot.define do FactoryBot.define do
factory :ci_job_artifact, class: 'Ci::JobArtifact' do factory :ci_job_artifact, class: 'Ci::JobArtifact' do
job factory: :ci_build job factory: :ci_build
......
# frozen_string_literal: true # frozen_string_literal: true
include ActionDispatch::TestProcess
FactoryBot.define do FactoryBot.define do
factory :lfs_object do factory :lfs_object do
sequence(:oid) { |n| "b68143e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a%05x" % n } sequence(:oid) { |n| "b68143e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a%05x" % n }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
require_relative '../support/helpers/repo_helpers' require_relative '../support/helpers/repo_helpers'
include ActionDispatch::TestProcess
FactoryBot.define do FactoryBot.define do
factory :note do factory :note do
project project
......
...@@ -101,7 +101,7 @@ RSpec.describe 'GraphQL' do ...@@ -101,7 +101,7 @@ RSpec.describe 'GraphQL' do
login_as(user) login_as(user)
get('/') 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") expect(graphql_data['echo']).to eq("\"#{user.username}\" says: Hello world")
end end
......
...@@ -2,6 +2,14 @@ ...@@ -2,6 +2,14 @@
FactoryBot::SyntaxRunner.class_eval do FactoryBot::SyntaxRunner.class_eval do
include RSpec::Mocks::ExampleMethods include RSpec::Mocks::ExampleMethods
# FactoryBot doesn't allow yet to add a helper that can be used in factories
# While the fixture_file_upload helper is reasonable to be used there:
#
# https://github.com/thoughtbot/factory_bot/issues/564#issuecomment-389491577
def fixture_file_upload(*args, **kwargs)
Rack::Test::UploadedFile.new(*args, **kwargs)
end
end end
# Patching FactoryBot to allow stubbing non AR models # Patching FactoryBot to allow stubbing non AR models
......
...@@ -5,7 +5,7 @@ class RenameableUpload < SimpleDelegator ...@@ -5,7 +5,7 @@ class RenameableUpload < SimpleDelegator
# Get a fixture file with a new unique name, and the same extension # Get a fixture file with a new unique name, and the same extension
def self.unique_file(name) def self.unique_file(name)
upload = new(fixture_file_upload("spec/fixtures/#{name}")) upload = new(Rack::Test::UploadedFile.new("spec/fixtures/#{name}"))
ext = File.extname(name) ext = File.extname(name)
new_name = File.basename(FactoryBot.generate(:filename), '.*') new_name = File.basename(FactoryBot.generate(:filename), '.*')
upload.original_filename = new_name + ext upload.original_filename = new_name + ext
......
...@@ -40,7 +40,7 @@ RSpec.shared_examples 'project access tokens available #create' do ...@@ -40,7 +40,7 @@ RSpec.shared_examples 'project access tokens available #create' do
it 'returns success message' do it 'returns success message' do
subject 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 end
it 'creates project access token' do it 'creates project access token' do
...@@ -88,7 +88,7 @@ RSpec.shared_examples 'project access tokens available #create' do ...@@ -88,7 +88,7 @@ RSpec.shared_examples 'project access tokens available #create' do
it 'shows a failure alert' do it 'shows a failure alert' do
subject 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 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