Add invalidate_reference to ReferenceFilterSpecHelper

This commit is contained in:
Robert Speicher 2015-05-12 17:59:30 -04:00
parent 136ab73803
commit 91eb346de6
1 changed files with 19 additions and 0 deletions

View File

@ -10,6 +10,25 @@ module ReferenceFilterSpecHelper
Rails.application.routes.url_helpers
end
# Modify a reference to make it invalid
#
# Commit SHAs get reversed, IDs get incremented by 1
#
# reference - String reference to modify
#
# Returns a String
def invalidate_reference(reference)
if reference =~ /\A(.+)?.\d+\z/
# Integer-based reference with optional project prefix
reference.gsub(/\d+\z/) { |i| i.to_i + 1 }
elsif reference =~ /\A(.+@)?(\h{6,40}\z)/
# SHA-based reference with optional prefix
reference.gsub(/\h{6,40}\z/) { |v| v.reverse }
else
reference
end
end
# Perform `call` on the described class
#
# Automatically passes the current `project` value to the context if none is