Skip to content

Commit

Permalink
add testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
hirakiuc committed Jul 15, 2017
1 parent d830a78 commit 07bc985
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 35 deletions.
19 changes: 17 additions & 2 deletions lib/tinybucket/model/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@ module Tinybucket
module Model
class Project < Base
acceptable_attributes \
:description, :links, :uuid, :created_on,
:key, :updated_on, :is_private, :name
:type, :description, :links, :uuid, :created_on,
:key, :updated_on, :is_private, :name, :owner

# Update this project
#
# @param _params [Hash]
# @raise [NotImplementedError] to be implemented
def update(_params)
raise NotImplementedError
end

# Destroy this project
#
# @raise [NotImplementedError] to be implemented.
def destroy
raise NotImplementedError
end
end
end
end
14 changes: 13 additions & 1 deletion lib/tinybucket/model/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ def following(options = {})
# @param options [Hash]
# @return [Tinybucket::Resource::Team::Project]
def projects(options = {})
Tinybucket::Resource::Team::Projects.new(username, options)
projects_resource(options)
end

# Get the project
#
# @param project_key [String]
# @return [Tinybucket::Model::Project]
def project(project_key, options = {})
projects_resource().find(project_key, options)
end

# Get this team's repositories.
Expand All @@ -72,6 +80,10 @@ def repos(options = {})

private

def projects_resource(options = {})
Tinybucket::Resource::Projects.new(username, options)
end

def team_api
create_api('Team')
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tinybucket/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Resource
:Commits,
:Forks,
:OwnersRepos,
:Projects,
:PublicRepos,
:PullRequests,
:Repos,
Expand All @@ -28,7 +29,6 @@ module Team
:Followers,
:Following,
:Members,
:Projects,
:Repos
].each do |klass_name|
autoload klass_name
Expand Down
49 changes: 49 additions & 0 deletions lib/tinybucket/resource/projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

module Tinybucket
module Resource
class Projects < Base
attr_accessor :owner

# Initialize
#
# @param owner_name [String]
# @param options [Hash]
def initialize(owner_name, options = {})
@owner = owner_name
@args = [options]
end

# Find the project
#
# @param project_key [String]
# @param options [Hash]
# @return [Tinybucket::Model::Project]
def find(project_key, options = {})
projects_api.find(project_key, options)
end

# Create a new project
#
# NOTE: Not Implemented yet.
#
# @param params [Hash]
# @raise [NotImplementedError] to be implemented
def create(params)
raise NotImplementedError
end

private

def projects_api
create_api('Projects').tap do |api|
api.owner = @owner
end
end

def enumerator
create_enumerator(projects_api, :list, *@args)
end
end
end
end
28 changes: 0 additions & 28 deletions lib/tinybucket/resource/team/projects.rb

This file was deleted.

89 changes: 89 additions & 0 deletions spec/fixtures/teams/test_team/projects/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"pagelen": 10,
"values": [
{
"uuid": "{45d24c3d-efa0-4c2a-be4e-78c1b30a30d0}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/test_team/projects/TEST"
},
"html": {
"href": "https://bitbucket.org/account/user/test_team/projects/TEST"
},
"repositories": {
"href": "https://api.bitbucket.org/2.0/repositories/test_team?q='project.key=\"TEST\"'"
},
"avatar": {
"href": "https://bitbucket.org/account/user/test_team/projects/TEST/avatar/32"
}
},
"description": null,
"created_on": "2016-03-19T03:34:27.792230+00:00",
"key": "TEST",
"owner": {
"username": "test_team",
"display_name": "test team",
"type": "team",
"uuid": "{e0f17982-effb-43eb-8589-7bacabb37cab}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/test_team"
},
"html": {
"href": "https://bitbucket.org/test_team/"
},
"avatar": {
"href": "https://bitbucket.org/account/test_team/avatar/32/"
}
}
},
"updated_on": "2016-03-19T03:34:27.792256+00:00",
"type": "project",
"is_private": false,
"name": "test"
},
{
"uuid": "{59278b96-1238-4418-a2b9-8f438234ae45}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/test_team/projects/PROJ"
},
"html": {
"href": "https://bitbucket.org/account/user/test_team/projects/PROJ"
},
"repositories": {
"href": "https://api.bitbucket.org/2.0/repositories/test_team?q='project.key=\"PROJ\"'"
},
"avatar": {
"href": "https://bitbucket.org/account/user/test_team/projects/PROJ/avatar/32"
}
},
"description": "Project created by Bitbucket for test",
"created_on": "2015-12-04T02:27:25.909083+00:00",
"key": "PROJ",
"owner": {
"username": "test_team",
"display_name": "test team",
"type": "team",
"uuid": "{e0f17982-effb-41cb-8589-7bacabb37cab}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/test_team"
},
"html": {
"href": "https://bitbucket.org/test_team/"
},
"avatar": {
"href": "https://bitbucket.org/account/test_team/avatar/32/"
}
}
},
"updated_on": "2015-12-04T02:27:25.909123+00:00",
"type": "project",
"is_private": false,
"name": "Untitled project"
}
],
"page": 1,
"size": 2
}
41 changes: 41 additions & 0 deletions spec/fixtures/teams/test_team/projects/myprj/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"uuid": "{45234c3d-efa0-4c2a-be4e-78c1b30a30d0}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/test_team/projects/myprj"
},
"html": {
"href": "https://bitbucket.org/account/user/test_team/projects/myprj"
},
"repositories": {
"href": "https://api.bitbucket.org/2.0/repositories/test_team?q='project.key=\"myprj\"'"
},
"avatar": {
"href": "https://bitbucket.org/account/user/test_team/projects/myprj/avatar/32"
}
},
"description": null,
"created_on": "2016-03-19T03:34:27.792230+00:00",
"key": "myprj",
"owner": {
"username": "test_team",
"display_name": "test team",
"type": "team",
"uuid": "{e0f17982-efab-43cb-8589-7bacabb37cab}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/teams/test_team"
},
"html": {
"href": "https://bitbucket.org/test_team/"
},
"avatar": {
"href": "https://bitbucket.org/account/test_team/avatar/32/"
}
}
},
"updated_on": "2016-03-19T03:34:27.792256+00:00",
"type": "project",
"is_private": false,
"name": "myprj"
}
29 changes: 29 additions & 0 deletions spec/lib/tinybucket/api/projects_api_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

RSpec.describe Tinybucket::Api::ProjectsApi do
include ApiResponseMacros

let(:api) { Tinybucket::Api::ProjectsApi.new }
let(:owner) { 'test_team' }
let(:request_path) { nil }
before do
api.owner = owner
stub_apiresponse(:get, request_path) if request_path
end

it { expect(api).to be_a_kind_of(Tinybucket::Api::BaseApi) }

describe 'list' do
subject { api.list() }
let(:request_path) { '/teams/test_team/projects/' }
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) }
end

describe 'find' do
let(:project_key) { 'myprj' }
subject { api.find(project_key) }

let(:request_path) { "/teams/test_team/projects/#{project_key}" }
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Project) }
end
end
22 changes: 22 additions & 0 deletions spec/lib/tinybucket/model/project_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'spec_helper'

RSpec.describe Tinybucket::Model::Project do
include ApiResponseMacros

let(:model_json) { load_json_fixture('teams/test_team/projects/myprj/get') }
let(:instance) { Tinybucket::Model::Project.new(model_json) }

it_behaves_like 'model has acceptable_attributes',
Tinybucket::Model::Project,
load_json_fixture('teams/test_team/projects/myprj/get')

describe '#update' do
subject { instance.update({}) }
it { expect { subject }.to raise_error(NotImplementedError) }
end

describe '#destroy' do
subject { instance.destroy() }
it { expect { subject }.to raise_error(NotImplementedError) }
end
end
25 changes: 22 additions & 3 deletions spec/lib/tinybucket/model/team_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
let(:teamname) { 'test_team' }

let(:model) do
m = Tinybucket::Model::Team.new(model_json)
m.username = teamname
m
Tinybucket::Model::Team.new(model_json).tap do |m|
m.username = teamname
end
end

before { stub_apiresponse(:get, request_path) if request_path }
Expand Down Expand Up @@ -67,4 +67,23 @@
Tinybucket::Resource::Team::Repos)
end
end

describe '#projects' do
let(:request_path) { "/teams/#{teamname}/projects/" }
subject { model.projects }
it 'return resource' do
expect(subject).to be_an_instance_of(
Tinybucket::Resource::Projects)
end
end

describe '#project' do
let(:project_key) { 'myprj' }
let(:request_path) { "/teams/#{teamname}/projects/#{project_key}" }
subject { model.project(project_key) }
it 'return Project model' do
expect(subject).to be_an_instance_of(
Tinybucket::Model::Project)
end
end
end
Loading

0 comments on commit 07bc985

Please sign in to comment.