From 905a2993e93c99c85b8b41d4959494c798262ed5 Mon Sep 17 00:00:00 2001 From: George Andrinopoulos Date: Sun, 5 Mar 2017 21:45:19 +0200 Subject: Fix json response in branches controller --- app/controllers/projects/branches_controller.rb | 2 +- ...28898-fix-search-branches-in-cherry-picking.yml | 4 ++++ .../projects/branches_controller_spec.rb | 23 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/28898-fix-search-branches-in-cherry-picking.yml diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index a01c0caa959..c40f9b7f75f 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -20,7 +20,7 @@ class Projects::BranchesController < Projects::ApplicationController respond_to do |format| format.html format.json do - render json: @repository.branch_names + render json: @branches.map(&:name) end end end diff --git a/changelogs/unreleased/28898-fix-search-branches-in-cherry-picking.yml b/changelogs/unreleased/28898-fix-search-branches-in-cherry-picking.yml new file mode 100644 index 00000000000..48e62f8f70d --- /dev/null +++ b/changelogs/unreleased/28898-fix-search-branches-in-cherry-picking.yml @@ -0,0 +1,4 @@ +--- +title: Fix json response in branches controller +merge_request: 9710 +author: George Andrinopoulos diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index e70737376af..298a7ff179c 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -244,4 +244,27 @@ describe Projects::BranchesController do end end end + + describe "GET index" do + render_views + + before do + sign_in(user) + end + + context 'when rendering a JSON format' do + it 'filters branches by name' do + get :index, + namespace_id: project.namespace, + project_id: project, + format: :json, + search: 'master' + + parsed_response = JSON.parse(response.body) + + expect(parsed_response.length).to eq 1 + expect(parsed_response.first).to eq 'master' + end + end + end end -- cgit v1.2.1