Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/killbill_client/models/role_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module Model
class RoleDefinition < RoleDefinitionAttributes

class << self
def find_all(options = {})
get "#{Security::KILLBILL_API_SECURITY_PREFIX}/roles",
{},
options
end

def find_by_name(role_name, options = {})
role = get "#{Security::KILLBILL_API_SECURITY_PREFIX}/roles/#{role_name}",
{},
Expand Down
36 changes: 36 additions & 0 deletions spec/killbill_client/role_definition_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'spec_helper'

describe KillBillClient::Model::RoleDefinition do

def json_response(body)
response = Net::HTTPOK.new('1.1', '200', 'OK')
response['Content-Type'] = 'application/json'
response.instance_variable_set(:@read, true)
response.instance_variable_set(:@body, body)
response
end

describe '.find_all' do
it 'lists the role definitions' do
body = [{'role' => 'admin', 'permissions' => ['account:create', 'invoice:view']},
{'role' => 'finance', 'permissions' => ['payment:view']}].to_json

expect(KillBillClient::API).to receive(:get)
.with('/1.0/kb/security/roles', {}, {:api_key => 'key'})
.and_return(json_response(body))

roles = KillBillClient::Model::RoleDefinition.find_all({:api_key => 'key'})

expect(roles.map(&:role)).to eq(%w(admin finance))
expect(roles.first).to be_a(KillBillClient::Model::RoleDefinition)
expect(roles.first.permissions).to eq(['account:create', 'invoice:view'])
expect(roles.last.permissions).to eq(['payment:view'])
end

it 'returns an empty list when there are no role definitions' do
allow(KillBillClient::API).to receive(:get).and_return(json_response('[]'))

expect(KillBillClient::Model::RoleDefinition.find_all).to be_empty
end
end
end
Loading