Work around limitations of expect_any_instance_of by stubbing Project.find

This commit is contained in:
Stan Hu 2018-06-11 09:47:51 -07:00
parent 6defeb0a7d
commit 96ce4ed25c
3 changed files with 23 additions and 9 deletions

View File

@ -1726,7 +1726,11 @@ describe Project do
.with(project.repository_storage, project.disk_path, project.import_url) .with(project.repository_storage, project.disk_path, project.import_url)
.and_return(true) .and_return(true)
expect_any_instance_of(Repository).to receive(:after_import) # Works around https://github.com/rspec/rspec-mocks/issues/910
expect(Project).to receive(:find).with(project.id).twice.and_return(project)
expect(project.repository).to receive(:after_import)
.and_call_original
expect(project.wiki.repository).to receive(:after_import)
.and_call_original .and_call_original
end end

View File

@ -55,10 +55,15 @@ describe RepositoryForkWorker do
it 'flushes various caches' do it 'flushes various caches' do
expect_fork_repository.and_return(true) expect_fork_repository.and_return(true)
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches) # Works around https://github.com/rspec/rspec-mocks/issues/910
expect(Project).to receive(:find).with(fork_project.id).and_return(fork_project)
expect(fork_project.repository).to receive(:expire_emptiness_caches)
.and_call_original .and_call_original
expect(fork_project.repository).to receive(:expire_exists_cache)
expect_any_instance_of(Repository).to receive(:expire_exists_cache) .and_call_original
expect(fork_project.wiki.repository).to receive(:expire_emptiness_caches)
.and_call_original
expect(fork_project.wiki.repository).to receive(:expire_exists_cache)
.and_call_original .and_call_original
perform! perform!

View File

@ -22,8 +22,11 @@ describe RepositoryImportWorker do
expect_any_instance_of(Projects::ImportService).to receive(:execute) expect_any_instance_of(Projects::ImportService).to receive(:execute)
.and_return({ status: :ok }) .and_return({ status: :ok })
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches) # Works around https://github.com/rspec/rspec-mocks/issues/910
expect_any_instance_of(Project).to receive(:import_finish) expect(Project).to receive(:find).with(project.id).and_return(project)
expect(project.repository).to receive(:expire_emptiness_caches)
expect(project.wiki.repository).to receive(:expire_emptiness_caches)
expect(project).to receive(:import_finish)
subject.perform(project.id) subject.perform(project.id)
end end
@ -34,9 +37,11 @@ describe RepositoryImportWorker do
expect_any_instance_of(Projects::ImportService).to receive(:execute) expect_any_instance_of(Projects::ImportService).to receive(:execute)
.and_return({ status: :ok }) .and_return({ status: :ok })
expect_any_instance_of(Project).to receive(:after_import).and_call_original # Works around https://github.com/rspec/rspec-mocks/issues/910
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches) expect(Project).to receive(:find).with(project.id).and_return(project)
expect_any_instance_of(Project).to receive(:import_finish) expect(project.repository).to receive(:expire_emptiness_caches)
expect(project.wiki.repository).to receive(:expire_emptiness_caches)
expect(project).to receive(:import_finish)
subject.perform(project.id) subject.perform(project.id)
end end