From dbd0111390fd24da8782cadcd52471ad002e12da Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 5 Jul 2017 21:00:22 +0900 Subject: [PATCH] Revert unnecesarry changes --- app/models/ci/build.rb | 7 +++++-- spec/models/ci/build_spec.rb | 18 +++++++++++------- .../matchers/access_matchers_for_controller.rb | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 841ad90a9cc..6c5b27a7ac5 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -176,9 +176,12 @@ module Ci # * Lowercased # * Anything not matching [a-z0-9-] is replaced with a - # * Maximum length is 63 bytes + # * First/Last Character is not a hyphen def ref_slug - slugified = ref.to_s.downcase - slugified.gsub(/[^a-z0-9]/, '-')[0..62] + ref.to_s + .downcase + .gsub(/[^a-z0-9]/, '-')[0..62] + .gsub(/(\A-+|-+\z)/, '') end # Variables whose value does not depend on environment diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 42b86a77f17..211356f415a 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -998,13 +998,17 @@ describe Ci::Build, :models do describe '#ref_slug' do { - 'master' => 'master', - '1-foo' => '1-foo', - 'fix/1-foo' => 'fix-1-foo', - 'fix-1-foo' => 'fix-1-foo', - 'a' * 63 => 'a' * 63, - 'a' * 64 => 'a' * 63, - 'FOO' => 'foo' + 'master' => 'master', + '1-foo' => '1-foo', + 'fix/1-foo' => 'fix-1-foo', + 'fix-1-foo' => 'fix-1-foo', + 'a' * 63 => 'a' * 63, + 'a' * 64 => 'a' * 63, + 'FOO' => 'foo', + '-' + 'a' * 61 + '-' => 'a' * 61, + '-' + 'a' * 62 + '-' => 'a' * 62, + '-' + 'a' * 63 + '-' => 'a' * 62, + 'a' * 62 + ' ' => 'a' * 62 }.each do |ref, slug| it "transforms #{ref} to #{slug}" do build.ref = ref diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index 40d6e221428..ff60bd0c0ae 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -65,7 +65,7 @@ module AccessMatchersForController end matcher :be_allowed_for do |role| - match do |action, &block| + match do |action| user = emulate_user(role, @membership) update_owner(@objects, user) action.call