`self.run_permission_checks` from `lib/gitlab/git_access_spec.rb` doesn't run any examples since Tue Oct 18
While working on this spec file, I noticed that the whole file took only 29 seconds to run and that only 36 examples were run. That didn't sound right to me as I knew that the self.run_permission_checks
is supposed to run a few hundred examples (560 to be precise)...
In fact if you try to run only these permissions matrix specs you get:
› bin/rspec spec/lib/gitlab/git_access_spec.rb:225
Running via Spring preloader in process 21296
Run options: include {:locations=>{"./spec/lib/gitlab/git_access_spec.rb"=>[225]}}
All examples were filtered out
0/0 |================================================= 100 =================================================>| Time: 00:00:00
Finished in 1.43 seconds (files took 0.79932 seconds to load)
0 examples, 0 failures
0 examples!
After investigating a bit, I noticed the following:
def self.run_permission_checks(permissions_matrix)
permissions_matrix.keys.each do |role|
describe "#{role} access" do
before do
if role == :admin
user.update_attribute(:admin, true)
else
project.team << [user, role]
end
permissions_matrix[role].each do |action, allowed|
context action do
subject { access.send(:check_push_access!, changes[action]) }
it { expect(subject.allowed?).to allowed ? be_truthy : be_falsey }
end
end
end
end
end
end
if we go backward and remove the nestings one by one we get:
permissions_matrix.keys.each do |role|
describe "#{role} access" do
before do
if role == :admin
user.update_attribute(:admin, true)
else
project.team << [user, role]
end
permissions_matrix[role].each do |action, allowed|
context action do
subject { access.send(:check_push_access!, changes[action]) }
it { expect(subject.allowed?).to allowed ? be_truthy : be_falsey }
end
end
end
end
end
then
describe "#{role} access" do
before do
if role == :admin
user.update_attribute(:admin, true)
else
project.team << [user, role]
end
permissions_matrix[role].each do |action, allowed|
context action do
subject { access.send(:check_push_access!, changes[action]) }
it { expect(subject.allowed?).to allowed ? be_truthy : be_falsey }
end
end
end
end
then
before do
if role == :admin
user.update_attribute(:admin, true)
else
project.team << [user, role]
end
permissions_matrix[role].each do |action, allowed|
context action do
subject { access.send(:check_push_access!, changes[action]) }
it { expect(subject.allowed?).to allowed ? be_truthy : be_falsey }
end
end
end
Wow! The actual examples are inside the before
block, no wonder no examples are run.
If we fix the nesting and move the examples out of the before
block we get a lot of errors:
› bin/rspec spec/lib/gitlab/git_access_spec.rb:184
Running via Spring preloader in process 21352
Run options: include {:locations=>{"./spec/lib/gitlab/git_access_spec.rb"=>[184]}}
273) Gitlab::GitAccess#check_push_access! when no one is allowed to push to the feature protected branch guest access push_new_branch
Failure/Error:
GitHooksService.new.execute(
user,
repository.path_to_repo,
oldrev,
newrev,
ref) do |service|
yield(service)
end
#<GitHooksService:0x007fd823df2048> yielded || to block with arity of 1
# ./app/services/git_operation_service.rb:117:in `with_hooks'
# ./app/services/git_operation_service.rb:111:in `update_ref_in_hooks'
# ./app/services/git_operation_service.rb:13:in `add_branch'
# ./app/models/repository.rb:172:in `add_branch'
# ./spec/lib/gitlab/git_access_spec.rb:208:in `merge_into_protected_branch'
# ./spec/lib/gitlab/git_access_spec.rb:185:in `block (3 levels) in <top (required)>'
# /Users/remy/.gem/ruby/2.3.3/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:98:in `block in run'
# /Users/remy/.gem/ruby/2.3.3/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:88:in `loop'
# /Users/remy/.gem/ruby/2.3.3/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:88:in `run'
# /Users/remy/.gem/ruby/2.3.3/gems/rspec-retry-0.4.5/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
# /Users/remy/.gem/ruby/2.3.3/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:22:in `block (2 levels) in setup'
# /Users/remy/.gem/ruby/2.3.3/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:268:in `load'
# /Users/remy/.gem/ruby/2.3.3/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:268:in `block in load'
# /Users/remy/.gem/ruby/2.3.3/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:240:in `load_dependency'
# /Users/remy/.gem/ruby/2.3.3/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:268:in `load'
# /Users/remy/.gem/ruby/2.3.3/gems/spring-commands-rspec-1.0.4/lib/spring/commands/rspec.rb:18:in `call'
# -e:1:in `<main>'
This is broken since https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/645 in EE and https://gitlab.com/gitlab-org/gitlab-ce/commit/cc6d42861bed8fc4c050ee8906d77bdb49783de5 in CE.