Commit d12cf228 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'next-instance-of-controllers-features' into 'master'

Update RSpec helper methods to *_next_instance_of

See merge request gitlab-org/gitlab!19872
parents a930271b 68752e8f
......@@ -227,16 +227,17 @@ describe Admin::ClustersController do
describe 'security' do
before do
allow_any_instance_of(described_class)
.to receive(:token_in_session).and_return('token')
allow_any_instance_of(described_class)
.to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
allow_any_instance_of(GoogleApi::CloudPlatform::Client)
.to receive(:projects_zones_clusters_create) do
OpenStruct.new(
self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123',
status: 'RUNNING'
)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:token_in_session).and_return('token')
allow(instance).to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
end
allow_next_instance_of(GoogleApi::CloudPlatform::Client) do |instance|
allow(instance).to receive(:projects_zones_clusters_create) do
OpenStruct.new(
self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123',
status: 'RUNNING'
)
end
end
allow(WaitForClusterCreationWorker).to receive(:perform_in).and_return(nil)
......@@ -467,7 +468,9 @@ describe Admin::ClustersController do
end
it 'invokes schedule_status_update on each application' do
expect_any_instance_of(Clusters::Applications::Ingress).to receive(:schedule_status_update)
expect_next_instance_of(Clusters::Applications::Ingress) do |instance|
expect(instance).to receive(:schedule_status_update)
end
get_cluster_status
end
......
......@@ -13,7 +13,9 @@ describe Admin::IdentitiesController do
let(:user) { create(:omniauth_user, provider: 'ldapmain', extern_uid: 'uid=myuser,ou=people,dc=example,dc=com') }
it 'repairs ldap blocks' do
expect_any_instance_of(RepairLdapBlockedUserService).to receive(:execute)
expect_next_instance_of(RepairLdapBlockedUserService) do |instance|
expect(instance).to receive(:execute)
end
put :update, params: { user_id: user.username, id: user.ldap_identity.id, identity: { provider: 'twitter' } }
end
......@@ -23,7 +25,9 @@ describe Admin::IdentitiesController do
let(:user) { create(:omniauth_user, provider: 'ldapmain', extern_uid: 'uid=myuser,ou=people,dc=example,dc=com') }
it 'repairs ldap blocks' do
expect_any_instance_of(RepairLdapBlockedUserService).to receive(:execute)
expect_next_instance_of(RepairLdapBlockedUserService) do |instance|
expect(instance).to receive(:execute)
end
delete :destroy, params: { user_id: user.username, id: user.ldap_identity.id }
end
......
......@@ -39,7 +39,9 @@ describe Admin::SpamLogsController do
describe '#mark_as_ham' do
before do
allow_any_instance_of(AkismetService).to receive(:submit_ham).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:submit_ham).and_return(true)
end
end
it 'submits the log as ham' do
post :mark_as_ham, params: { id: first_spam.id }
......
......@@ -20,8 +20,9 @@ describe Import::GitlabController do
describe "GET callback" do
it "updates access token" do
allow_any_instance_of(Gitlab::GitlabImport::Client)
.to receive(:get_token).and_return(token)
allow_next_instance_of(Gitlab::GitlabImport::Client) do |instance|
allow(instance).to receive(:get_token).and_return(token)
end
stub_omniauth_provider('gitlab')
get :callback
......
......@@ -104,7 +104,9 @@ describe Projects::DiscussionsController do
end
it "sends notifications if all discussions are resolved" do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(merge_request)
expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
expect(instance).to receive(:execute).with(merge_request)
end
post :resolve, params: request_params
end
......@@ -122,8 +124,10 @@ describe Projects::DiscussionsController do
end
it "renders discussion with serializer" do
expect_any_instance_of(DiscussionSerializer).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
expect_next_instance_of(DiscussionSerializer) do |instance|
expect(instance).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
end
post :resolve, params: request_params
end
......@@ -193,8 +197,10 @@ describe Projects::DiscussionsController do
end
it "renders discussion with serializer" do
expect_any_instance_of(DiscussionSerializer).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
expect_next_instance_of(DiscussionSerializer) do |instance|
expect(instance).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
end
delete :unresolve, params: request_params
end
......
......@@ -13,8 +13,9 @@ describe Projects::MattermostsController do
describe 'GET #new' do
before do
allow_any_instance_of(MattermostSlashCommandsService)
.to receive(:list_teams).and_return([])
allow_next_instance_of(MattermostSlashCommandsService) do |instance|
allow(instance).to receive(:list_teams).and_return([])
end
end
it 'accepts the request' do
......@@ -42,7 +43,9 @@ describe Projects::MattermostsController do
context 'no request can be made to mattermost' do
it 'shows the error' do
allow_any_instance_of(MattermostSlashCommandsService).to receive(:configure).and_return([false, "error message"])
allow_next_instance_of(MattermostSlashCommandsService) do |instance|
allow(instance).to receive(:configure).and_return([false, "error message"])
end
expect(subject).to redirect_to(new_project_mattermost_url(project))
end
......@@ -50,7 +53,9 @@ describe Projects::MattermostsController do
context 'the request is succesull' do
before do
allow_any_instance_of(Mattermost::Command).to receive(:create).and_return('token')
allow_next_instance_of(Mattermost::Command) do |instance|
allow(instance).to receive(:create).and_return('token')
end
end
it 'redirects to the new page' do
......
......@@ -85,7 +85,9 @@ describe Projects::MergeRequests::CreationsController do
describe 'GET diffs' do
context 'when merge request cannot be created' do
it 'does not assign diffs var' do
allow_any_instance_of(MergeRequest).to receive(:can_be_created).and_return(false)
allow_next_instance_of(MergeRequest) do |instance|
allow(instance).to receive(:can_be_created).and_return(false)
end
get :diffs, params: get_diff_params.merge(format: 'json')
......
......@@ -86,7 +86,9 @@ describe Projects::MergeRequests::DiffsController do
end
it 'serializes merge request diff collection' do
expect_any_instance_of(DiffsSerializer).to receive(:represent).with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff), an_instance_of(Hash))
expect_next_instance_of(DiffsSerializer) do |instance|
expect(instance).to receive(:represent).with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff), an_instance_of(Hash))
end
go
end
......@@ -98,7 +100,9 @@ describe Projects::MergeRequests::DiffsController do
end
it 'serializes merge request diff collection' do
expect_any_instance_of(DiffsSerializer).to receive(:represent).with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff), an_instance_of(Hash))
expect_next_instance_of(DiffsSerializer) do |instance|
expect(instance).to receive(:represent).with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff), an_instance_of(Hash))
end
go
end
......
......@@ -785,7 +785,9 @@ describe Projects::NotesController do
end
it "sends notifications if all discussions are resolved" do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(merge_request)
expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
expect(instance).to receive(:execute).with(merge_request)
end
post :resolve, params: request_params
end
......
......@@ -45,7 +45,9 @@ describe Projects::ProjectMembersController do
end
it 'adds user to members' do
expect_any_instance_of(Members::CreateService).to receive(:execute).and_return(status: :success)
expect_next_instance_of(Members::CreateService) do |instance|
expect(instance).to receive(:execute).and_return(status: :success)
end
post :create, params: {
namespace_id: project.namespace,
......@@ -59,7 +61,9 @@ describe Projects::ProjectMembersController do
end
it 'adds no user to members' do
expect_any_instance_of(Members::CreateService).to receive(:execute).and_return(status: :failure, message: 'Message')
expect_next_instance_of(Members::CreateService) do |instance|
expect(instance).to receive(:execute).and_return(status: :failure, message: 'Message')
end
post :create, params: {
namespace_id: project.namespace,
......
......@@ -85,7 +85,9 @@ describe Projects::Prometheus::MetricsController do
end
it 'calls prometheus adapter service' do
expect_any_instance_of(::Prometheus::AdapterService).to receive(:prometheus_adapter)
expect_next_instance_of(::Prometheus::AdapterService) do |instance|
expect(instance).to receive(:prometheus_adapter)
end
subject.__send__(:prometheus_adapter)
end
......
......@@ -125,7 +125,9 @@ describe Projects::Settings::CiCdController do
context 'when run_auto_devops_pipeline is true' do
before do
expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(true)
expect_next_instance_of(Projects::UpdateService) do |instance|
expect(instance).to receive(:run_auto_devops_pipeline?).and_return(true)
end
end
context 'when the project repository is empty' do
......@@ -159,7 +161,9 @@ describe Projects::Settings::CiCdController do
context 'when run_auto_devops_pipeline is not true' do
before do
expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(false)
expect_next_instance_of(Projects::UpdateService) do |instance|
expect(instance).to receive(:run_auto_devops_pipeline?).and_return(false)
end
end
it 'does not queue a CreatePipelineWorker' do
......
......@@ -92,7 +92,9 @@ describe Projects::SnippetsController do
context 'when the snippet is spam' do
before do
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
context 'when the snippet is private' do
......@@ -170,7 +172,9 @@ describe Projects::SnippetsController do
context 'when the snippet is spam' do
before do
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
context 'when the snippet is private' do
......@@ -278,7 +282,9 @@ describe Projects::SnippetsController do
let(:snippet) { create(:project_snippet, :private, project: project, author: user) }
before do
allow_any_instance_of(AkismetService).to receive_messages(submit_spam: true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive_messages(submit_spam: true)
end
stub_application_setting(akismet_enabled: true)
end
......
......@@ -174,7 +174,9 @@ describe UsersController do
let(:user) { create(:user) }
before do
allow_any_instance_of(User).to receive(:contributed_projects_ids).and_return([project.id])
allow_next_instance_of(User) do |instance|
allow(instance).to receive(:contributed_projects_ids).and_return([project.id])
end
sign_in(user)
project.add_developer(user)
......
......@@ -73,8 +73,9 @@ describe "Admin::Projects" do
before do
create(:group, name: 'Web')
allow_any_instance_of(Projects::TransferService)
.to receive(:move_uploads_to_new_namespace).and_return(true)
allow_next_instance_of(Projects::TransferService) do |instance|
allow(instance).to receive(:move_uploads_to_new_namespace).and_return(true)
end
end
it 'transfers project to group web', :js do
......
......@@ -179,7 +179,9 @@ describe "Admin::Users" do
end
it "calls send mail" do
expect_any_instance_of(NotificationService).to receive(:new_user)
expect_next_instance_of(NotificationService) do |instance|
expect(instance).to receive(:new_user)
end
click_button "Create user"
end
......
......@@ -40,7 +40,9 @@ describe 'Cycle Analytics', :js do
context "when there's cycle analytics data" do
before do
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
allow_next_instance_of(Gitlab::ReferenceExtractor) do |instance|
allow(instance).to receive(:issues).and_return([issue])
end
project.add_maintainer(user)
@build = create_cycle(user, project, issue, mr, milestone, pipeline)
......@@ -99,7 +101,9 @@ describe 'Cycle Analytics', :js do
project.add_developer(user)
project.add_guest(guest)
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
allow_next_instance_of(Gitlab::ReferenceExtractor) do |instance|
allow(instance).to receive(:issues).and_return([issue])
end
create_cycle(user, project, issue, mr, milestone, pipeline)
deploy_master(user, project)
......
......@@ -21,7 +21,9 @@ describe 'Global search' do
describe 'I search through the issues and I see pagination' do
before do
allow_any_instance_of(Gitlab::SearchResults).to receive(:per_page).and_return(1)
allow_next_instance_of(Gitlab::SearchResults) do |instance|
allow(instance).to receive(:per_page).and_return(1)
end
create_list(:issue, 2, project: project, title: 'initial')
end
......
......@@ -13,8 +13,12 @@ describe 'User Cluster', :js do
gitlab_sign_in(user)
allow(Groups::ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 }
allow_any_instance_of(Clusters::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute)
allow_any_instance_of(Clusters::Cluster).to receive(:retrieve_connection_status).and_return(:connected)
allow_next_instance_of(Clusters::Kubernetes::CreateOrUpdateNamespaceService) do |instance|
allow(instance).to receive(:execute)
end
allow_next_instance_of(Clusters::Cluster) do |instance|
allow(instance).to receive(:retrieve_connection_status).and_return(:connected)
end
end
context 'when user does not have a cluster and visits cluster index page' do
......
......@@ -17,7 +17,9 @@ describe "Jira", :js do
stub_request(:get, "https://jira.example.com/rest/api/2/issue/JIRA-5")
stub_request(:post, "https://jira.example.com/rest/api/2/issue/JIRA-5/comment")
allow_any_instance_of(JIRA::Resource::Issue).to receive(:remotelink).and_return(remotelink)
allow_next_instance_of(JIRA::Resource::Issue) do |instance|
allow(instance).to receive(:remotelink).and_return(remotelink)
end
sign_in(user)
......
......@@ -47,7 +47,9 @@ describe 'User squashes a merge request', :js do
before do
# Prevent source branch from being removed so we can use be_merged_to_root_ref
# method to check if squash was performed or not
allow_any_instance_of(MergeRequest).to receive(:force_remove_source_branch?).and_return(false)
allow_next_instance_of(MergeRequest) do |instance|
allow(instance).to receive(:force_remove_source_branch?).and_return(false)
end
project.add_maintainer(user)
sign_in user
......
......@@ -13,8 +13,12 @@ describe 'User Cluster', :js do
gitlab_sign_in(user)
allow(Projects::ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 }
allow_any_instance_of(Clusters::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute)
allow_any_instance_of(Clusters::Cluster).to receive(:retrieve_connection_status).and_return(:connected)
allow_next_instance_of(Clusters::Kubernetes::CreateOrUpdateNamespaceService) do |instance|
allow(instance).to receive(:execute)
end
allow_next_instance_of(Clusters::Cluster) do |instance|
allow(instance).to receive(:retrieve_connection_status).and_return(:connected)
end
end
context 'when user does not have a cluster and visits cluster index page' do
......
......@@ -57,7 +57,9 @@ describe 'User browses commits' do
create(:ci_build, pipeline: pipeline)
allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file).and_return('')
allow_next_instance_of(Ci::Pipeline) do |instance|
allow(instance).to receive(:ci_yaml_file).and_return('')
end
end
it 'renders commit ci info' do
......@@ -94,8 +96,12 @@ describe 'User browses commits' do
let(:commit) { create(:commit, project: project) }
it 'renders successfully' do
allow_any_instance_of(Gitlab::Diff::File).to receive(:blob).and_return(nil)
allow_any_instance_of(Gitlab::Diff::File).to receive(:binary?).and_return(true)
allow_next_instance_of(Gitlab::Diff::File) do |instance|
allow(instance).to receive(:blob).and_return(nil)
end
allow_next_instance_of(Gitlab::Diff::File) do |instance|
allow(instance).to receive(:binary?).and_return(true)
end
visit(project_commit_path(project, commit))
......
......@@ -107,7 +107,9 @@ describe "Compare", :js do
visit project_compare_index_path(project, from: "feature", to: "master")
allow(Commit).to receive(:max_diff_options).and_return(max_files: 3)
allow_any_instance_of(DiffHelper).to receive(:render_overflow_warning?).and_return(true)
allow_next_instance_of(DiffHelper) do |instance|
allow(instance).to receive(:render_overflow_warning?).and_return(true)
end
click_button('Compare')
......
......@@ -175,8 +175,9 @@ describe 'Environment' do
#
# In EE we have to stub EE::Environment since it overwrites
# the "terminals" method.
allow_any_instance_of(Gitlab.ee? ? EE::Environment : Environment)
.to receive(:terminals) { nil }
allow_next_instance_of(Gitlab.ee? ? EE::Environment : Environment) do |instance|
allow(instance).to receive(:terminals) { nil }
end
visit terminal_project_environment_path(project, environment)
end
......
......@@ -71,7 +71,9 @@ describe 'Environments page', :js do
let!(:application_prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
before do
allow_any_instance_of(Kubeclient::Client).to receive(:proxy_url).and_raise(Kubeclient::HttpError.new(401, 'Unauthorized', nil))
allow_next_instance_of(Kubeclient::Client) do |instance|
allow(instance).to receive(:proxy_url).and_raise(Kubeclient::HttpError.new(401, 'Unauthorized', nil))
end
end
it 'shows one environment without error' do
......
......@@ -42,7 +42,9 @@ describe 'Edit Project Settings' do
context 'When external issue tracker is enabled and issues enabled on project settings' do
it 'does not hide issues tab' do
allow_any_instance_of(Project).to receive(:external_issue_tracker).and_return(JiraService.new)
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:external_issue_tracker).and_return(JiraService.new)
end
visit project_path(project)
......@@ -54,7 +56,9 @@ describe 'Edit Project Settings' do
it 'hides issues tab' do
project.issues_enabled = false
project.save!
allow_any_instance_of(Project).to receive(:external_issue_tracker).and_return(JiraService.new)
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:external_issue_tracker).and_return(JiraService.new)
end
visit project_path(project)
......
......@@ -26,7 +26,9 @@ describe 'Import/Export - project export integration test', :js do
let(:project) { setup_project }
before do
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
allow_next_instance_of(Gitlab::ImportExport) do |instance|
allow(instance).to receive(:storage_path).and_return(export_path)
end
end
after do
......
......@@ -11,7 +11,9 @@ describe 'Import/Export - project import integration test', :js do
before do
stub_uploads_object_storage(FileUploader)
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
allow_next_instance_of(Gitlab::ImportExport) do |instance|
allow(instance).to receive(:storage_path).and_return(export_path)
end
gitlab_sign_in(user)
end
......
......@@ -18,7 +18,9 @@ describe "Pages with Let's Encrypt", :https_pages_enabled do
project.add_role(user, role)
sign_in(user)
project.namespace.update(owner: user)
allow_any_instance_of(Project).to receive(:pages_deployed?) { true }
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:pages_deployed?) { true }
end
end
context 'when the auto SSL management is initially disabled' do
......
......@@ -264,7 +264,9 @@ describe "Internal Project Access" do
before do
# Speed increase
allow_any_instance_of(Project).to receive(:branches).and_return([])
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:branches).and_return([])
end
end
it { is_expected.to be_allowed_for(:admin) }
......@@ -283,7 +285,9 @@ describe "Internal Project Access" do
before do
# Speed increase
allow_any_instance_of(Project).to receive(:tags).and_return([])
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:tags).and_return([])
end
end
it { is_expected.to be_allowed_for(:admin) }
......
......@@ -236,7 +236,9 @@ describe "Private Project Access" do
before do
# Speed increase
allow_any_instance_of(Project).to receive(:branches).and_return([])
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:branches).and_return([])
end
end
it { is_expected.to be_allowed_for(:admin) }
......@@ -255,7 +257,9 @@ describe "Private Project Access" do
before do
# Speed increase
allow_any_instance_of(Project).to receive(:tags).and_return([])
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:tags).and_return([])
end
end
it { is_expected.to be_allowed_for(:admin) }
......
......@@ -477,7 +477,9 @@ describe "Public Project Access" do
before do
# Speed increase
allow_any_instance_of(Project).to receive(:branches).and_return([])
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:branches).and_return([])
end
end
it { is_expected.to be_allowed_for(:admin) }
......@@ -496,7 +498,9 @@ describe "Public Project Access" do
before do
# Speed increase
allow_any_instance_of(Project).to receive(:tags).and_return([])
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:tags).and_return([])
end
end
it { is_expected.to be_allowed_for(:admin) }
......
......@@ -39,8 +39,10 @@ describe 'Developer deletes tag' do
context 'when pre-receive hook fails', :js do
before do
allow_any_instance_of(Gitlab::GitalyClient::OperationService).to receive(:rm_tag)
.and_raise(Gitlab::Git::PreReceiveError, 'GitLab: Do not delete tags')
allow_next_instance_of(Gitlab::GitalyClient::OperationService) do |instance|
allow(instance).to receive(:rm_tag)
.and_raise(Gitlab::Git::PreReceiveError, 'GitLab: Do not delete tags')
end
end
it 'shows the error message' do
......
......@@ -379,7 +379,9 @@ shared_examples 'Signup' do
before do
InvisibleCaptcha.timestamp_enabled = true
stub_application_setting(recaptcha_enabled: true)
allow_any_instance_of(RegistrationsController).to receive(:verify_recaptcha).and_return(false)
allow_next_instance_of(RegistrationsController) do |instance|
allow(instance).to receive(:verify_recaptcha).and_return(false)
end
end
after do
......
......@@ -34,7 +34,9 @@ context 'U2F' do
before do
sign_in(user)
allow_any_instance_of(Profiles::TwoFactorAuthsController).to receive(:build_qr_code).and_return('qrcode:blackandwhitesquares')
allow_next_instance_of(Profiles::TwoFactorAuthsController) do |instance|
allow(instance).to receive(:build_qr_code).and_return('qrcode:blackandwhitesquares')
end
end
it 'u2f/register.html' do
......
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