Skip to content

Commit

Permalink
add ability to list project snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ committed Oct 19, 2012
1 parent 6c5637e commit 7632ecb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/gitlab/client/snippets.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
class Gitlab::Client
# Defines methods related to snippets.
module Snippets
# Gets a list of project's snippets.
#
# @example
# Gitlab.snippets(42)
# Gitlab.snippets('gitlab')
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Hash] options A customizable set of options.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @return [Gitlab::ObjectifiedHash]
def snippets(project, options={})
get("/projects/#{project}/snippets", :query => options)
end

# Gets information about a snippet.
#
# @example
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/snippets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":1,"title":"Rails Console ActionMailer","file_name":"mailer_test.rb","author":{"id":1,"email":"john@example.com","name":"John Smith","blocked":false,"created_at":"2012-09-17T09:41:56Z"},"expires_at":"2012-09-24T00:00:00Z","updated_at":"2012-09-17T09:51:42Z","created_at":"2012-09-17T09:51:42Z"}]
16 changes: 16 additions & 0 deletions spec/gitlab/client/snippets_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
require 'spec_helper'

describe Gitlab::Client do
describe ".snippets" do
before do
stub_get("/projects/3/snippets", "snippets")
@snippets = Gitlab.snippets(3)
end

it "should get the correct resource" do
a_get("/projects/3/snippets").should have_been_made
end

it "should return an array of project's snippets" do
@snippets.should be_an Array
@snippets.first.file_name.should == "mailer_test.rb"
end
end

describe ".snippet" do
before do
stub_get("/projects/3/snippets/1", "snippet")
Expand Down

0 comments on commit 7632ecb

Please sign in to comment.