зеркало из https://github.com/github/explore.git
Make repository/user tests more clear
* Remove double-negative from test message * Remove valid HTTP status constant, since 301 is no longer valid * Include collection name in error message
This commit is contained in:
Родитель
d90e216039
Коммит
66649f7514
|
@ -32,8 +32,8 @@ describe "collections" do
|
|||
assert_empty invalid_slugs, "Invalid item slugs #{invalid_slugs}"
|
||||
end
|
||||
|
||||
it "does not include items pointing to private or non-existent repos" do
|
||||
invalid_repos = []
|
||||
it "fails if a repository does not exist or is private" do
|
||||
errors = []
|
||||
|
||||
items_for_collection(collection).each do |item|
|
||||
next unless item.match?(USERNAME_AND_REPO_REGEX)
|
||||
|
@ -41,16 +41,16 @@ describe "collections" do
|
|||
url = URI("https://github.com/#{item}")
|
||||
http_status = Net::HTTP.get_response(url).code
|
||||
|
||||
unless http_status.match?(VALID_USER_AND_REPO_HTTP_STATUSES)
|
||||
invalid_repos << item
|
||||
unless %w[200 301].include?(http_status)
|
||||
errors << "#{collection}: #{item} does not exist or is private"
|
||||
end
|
||||
end
|
||||
|
||||
assert_empty invalid_repos, "repositories #{invalid_repos} do not exist or are private"
|
||||
assert_empty errors
|
||||
end
|
||||
|
||||
it "does not include items pointing to non-existent users or organizations" do
|
||||
invalid_users = []
|
||||
it "fails if a user or organization does not exist" do
|
||||
errors = []
|
||||
|
||||
items_for_collection(collection).each do |item|
|
||||
next unless item.match?(USERNAME_REGEX)
|
||||
|
@ -58,12 +58,12 @@ describe "collections" do
|
|||
url = URI("https://github.com/#{item}")
|
||||
http_status = Net::HTTP.get_response(url).code
|
||||
|
||||
unless http_status.match?(VALID_USER_AND_REPO_HTTP_STATUSES)
|
||||
invalid_users << item
|
||||
unless %w[200 301].include?(http_status)
|
||||
errors << "#{collection}: #{item} does not exist"
|
||||
end
|
||||
end
|
||||
|
||||
assert_empty invalid_users, "users or organizations #{invalid_users} do not exist"
|
||||
assert_empty errors
|
||||
end
|
||||
|
||||
it "fails if a user, organization, or repository has been renamed" do
|
||||
|
|
|
@ -14,9 +14,6 @@ COLLECTION_REGEX = /\A[a-z0-9][a-z0-9-]*\Z/
|
|||
USERNAME_REGEX = /\A[a-z0-9]+(-[a-z0-9]+)*\z/i
|
||||
USERNAME_AND_REPO_REGEX = %r{\A[^/]+\/[^/]+$\z}
|
||||
|
||||
# We allow 301 in case of automatic redirects for renamed repositories
|
||||
VALID_USER_AND_REPO_HTTP_STATUSES = /\A(200|301)\z/
|
||||
|
||||
def invalid_collection_message(collection)
|
||||
"'#{collection}' must be between 1-#{MAX_COLLECTION_SLUG_LENGTH} characters, start with a letter or number, " \
|
||||
"and may include hyphens"
|
||||
|
|
Загрузка…
Ссылка в новой задаче