Skip to content

Commit

Permalink
Merge pull request #6 from kalupa/role-configuration
Browse files Browse the repository at this point in the history
Role configuration
  • Loading branch information
Paul Kalupnieks committed Mar 22, 2012
2 parents 2763c52 + 9ae65a3 commit 0a9eddf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/woopy.rb
Expand Up @@ -8,6 +8,7 @@
require 'woopy/resource'
require 'woopy/user'
require 'woopy/account'
require 'woopy/role'
require 'woopy/employment'
require 'woopy/ownership'

Expand Down
7 changes: 6 additions & 1 deletion lib/woopy/account.rb
Expand Up @@ -17,5 +17,10 @@ def find_employment(user)

Employment.new(employment_json, true)
end

def grant_role(user, roles)
false unless roles.class == Array
Account.put("#{self.id}/users/#{user.id}/update_roles", { roles: roles })
end
end
end
end
8 changes: 8 additions & 0 deletions lib/woopy/role.rb
@@ -0,0 +1,8 @@
module Woopy
class Role < Resource
def initialize(attributes = {}, persisted = false)
self.class.site = Resource.site + "accounts/:account_id/users/:user_id/"
super(attributes, persisted)
end
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -44,6 +44,10 @@ def employment_attributes
{ account_id: 1, user_id: 1 }
end

def roles_attributes
{roles: ["role1", "role2"] }
end

def ownership_response
{ ownership: ownership_attributes.merge(id: 1) }.to_json
end
Expand Down
15 changes: 12 additions & 3 deletions spec/woopy/account_spec.rb
Expand Up @@ -6,13 +6,15 @@
@token = 'foo'
Woopy(token: @token)
ActiveResource::HttpMock.respond_to do |mock|
mock.post( '/services/v1/accounts.json', request_headers(@token), account_response )
mock.post( '/services/v1/users.json', request_headers(@token), user_response )
mock.post( '/services/v1/ownerships.json', request_headers(@token), ownership_response )
mock.post( '/services/v1/accounts.json', request_headers(@token), account_response )
mock.post( '/services/v1/users.json', request_headers(@token), user_response )
mock.post( '/services/v1/ownerships.json', request_headers(@token), ownership_response )

mock.get( '/services/v1/accounts/1/users/1/employment.json', accept_request_headers(@token), employment_response )
mock.post( '/services/v1/accounts/1/employments.json', request_headers(@token), employment_response )
mock.delete( '/services/v1/accounts/1/employments/1.json', accept_request_headers(@token), employment_response )

mock.put( "/services/v1/accounts/1/users/1/update_roles.json?#{ roles_attributes.to_query }", request_headers(@token), :ok )
end
end

Expand Down Expand Up @@ -64,5 +66,12 @@
it { should be_persisted }
its(:user_id) { should == @user.id }
end

describe "#grant_role" do
subject { @account.grant_role(@user, ["role1", "role2"]) }

it { should be_true }
end

end
end

0 comments on commit 0a9eddf

Please sign in to comment.