Commit f112e2a1 authored by Phil Hughes's avatar Phil Hughes

Fixed issue with returning ref in commits JSON

Added tests to project controller
parent c240cad5
...@@ -102,7 +102,7 @@ class GitLabDropdownFilter ...@@ -102,7 +102,7 @@ class GitLabDropdownFilter
$el = $(@) $el = $(@)
matches = fuzzaldrinPlus.match($el.text().trim(), search_text) matches = fuzzaldrinPlus.match($el.text().trim(), search_text)
if $el.is(':not(.dropdown-header)') unless $el.is('.dropdown-header')
if matches.length if matches.length
$el.show() $el.show()
else else
......
class ProjectsController < Projects::ApplicationController class ProjectsController < Projects::ApplicationController
include ExtractsPath include ExtractsPath
before_action :authenticate_user!, except: [:show, :activity] before_action :authenticate_user!, except: [:show, :activity, :refs]
before_action :project, except: [:new, :create] before_action :project, except: [:new, :create]
before_action :repository, except: [:new, :create] before_action :repository, except: [:new, :create]
before_action :assign_ref_vars, :tree, only: [:show], if: :repo_exists? before_action :assign_ref_vars, :tree, only: [:show], if: :repo_exists?
...@@ -261,8 +261,8 @@ class ProjectsController < Projects::ApplicationController ...@@ -261,8 +261,8 @@ class ProjectsController < Projects::ApplicationController
end end
# If reference is commit id - we should add it to branch/tag selectbox # If reference is commit id - we should add it to branch/tag selectbox
ref = params[:ref] ref = Addressable::URI.unescape(params[:ref])
if ref && options.flatten.exclude?(ref) && ref =~ /\A[0-9a-zA-Z]{6,52}\z/ if ref && options.flatten(2).exclude?(ref) && ref =~ /\A[0-9a-zA-Z]{6,52}\z/
options['Commits'] = [ref] options['Commits'] = [ref]
end end
......
...@@ -237,4 +237,24 @@ describe ProjectsController do ...@@ -237,4 +237,24 @@ describe ProjectsController do
expect(response.status).to eq(401) expect(response.status).to eq(401)
end end
end end
describe "GET refs" do
it "should get a list of branches and tags" do
get :refs, namespace_id: public_project.namespace.path, id: public_project.path
parsed_body = JSON.parse(response.body)
expect(parsed_body["Branches"]).to include("master")
expect(parsed_body["Tags"]).to include("v1.0.0")
expect(parsed_body["Commits"]).to be_nil
end
it "should get a list of branches, tags and commits" do
get :refs, namespace_id: public_project.namespace.path, id: public_project.path, ref: "123456"
parsed_body = JSON.parse(response.body)
expect(parsed_body["Branches"]).to include("master")
expect(parsed_body["Tags"]).to include("v1.0.0")
expect(parsed_body["Commits"]).to include("123456")
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment