added api method to return labels of a given project

This commit is contained in:
Ábner Silva de Oliveira 2014-03-21 06:18:19 -03:00
parent fb919a631c
commit 44aa6b90dd
3 changed files with 39 additions and 0 deletions

View File

@ -187,5 +187,9 @@ module API
end
end
end
class Label < Grape::Entity
expose :name
end
end
end

View File

@ -215,6 +215,15 @@ module API
@users = paginate @users
present @users, with: Entities::User
end
# Get a labels list
#
# Example Request:
# GET /users
get ':id/labels' do
@labels = user_project.issues_labels
present @labels, with: Entities::Label
end
end
end
end

View File

@ -0,0 +1,26 @@
require 'spec_helper'
describe API::API do
include ApiHelpers
before(:each) { ActiveRecord::Base.observers.enable(:user_observer) }
after(:each) { ActiveRecord::Base.observers.disable(:user_observer) }
let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, author: user, assignee: user, project: project, :label_list => "label1, label2") }
before { project.team << [user, :reporter] }
describe "GET /projects/:id/labels" do
it "should return project labels" do
get api("/projects/#{project.id}/labels", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['name'].should == 'label1'
json_response.last['name'].should == 'label2'
end
end
end