Spec: Fix projects controllers retry
The problem is with @project variable and it is a general one for all specs under Projects::ApplicationController.
In Projects::ApplicationController we set a global variable @project - which is completely fine for the first try. But this variable is kept for the retries (using rspec-retry) and because we use
def project
return @project if @project
it doesn't try to re-fetch the project based on the provided params.
Related issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/29242
Unfortunately, rspec-retry doesn't rerun the example with a clean slate (it only clear let variables), meaning that our json_response method will still return the memoized response from the first run, including the ID of the resource from the first run (i.e. json_response['id'] == 1)...
How to replicate the problem
Locally you can replicate it by changing https://gitlab.com/gitlab-org/gitlab-ce/blob/master/spec/spec_helper.rb#L91 to use retries.
Original description
Note: add
rails5to a branch name to trigger rails5 specific CI jobs.https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/67494093
1) Projects::JobsController GET show when requesting JSON exposes needed information Failure/Error: @builds = @project.pipelines .find_by_sha(@build.sha) .builds .order('id DESC') .present(current_user: current_user) NoMethodError: undefined method `builds' for nil:NilClass # ./app/controllers/projects/jobs_controller.rb:50:in `show' # ./lib/gitlab/i18n.rb:50:in `with_locale' # ./lib/gitlab/i18n.rb:56:in `with_user_locale' # ./app/controllers/application_controller.rb:351:in `set_locale' # ./spec/controllers/projects/jobs_controller_spec.rb:156:in `get_show' # ./spec/controllers/projects/jobs_controller_spec.rb:138:in `block (4 levels) in <top (required)>' # ./spec/spec_helper.rb:160:in `block (2 levels) in <top (required)>'