Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7 from kalupa/woople-api-account-index

Added Employment index finder on Account
  • Loading branch information...
commit eec5de7dfe3960340d8cf56025ea9a622a27353b 2 parents 175cef2 + cc140c0
@awd awd authored
View
4 lib/woopy/account.rb
@@ -12,6 +12,10 @@ def make_owner(user, role = nil)
Ownership.create(account_id: self.id, user_id: user.id, role: role)
end
+ def employments
+ Employment.find(:all, params: {account_id: self.id} )
+ end
+
def find_employment(user)
employment_json = Account.get("#{self.id}/users/#{user.id}/employment")
View
4 spec/spec_helper.rb
@@ -36,6 +36,10 @@ def user_attributes
{ name: "User Name", email: "user@example.com" }
end
+def employment_collection_response
+ { employments: [employment_attributes.merge(id: 1)] }.to_json
+end
+
def employment_response
{ employment: employment_attributes.merge(id: 1) }.to_json
end
View
22 spec/woopy/account_spec.rb
@@ -11,6 +11,7 @@
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.get( '/services/v1/accounts/1/employments.json', accept_request_headers(@token), employment_collection_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 )
@@ -74,4 +75,25 @@
end
end
+
+ context "#employments" do
+ context "users on account" do
+ before do
+ @account = Woopy::Account.create(account_attributes)
+ @employments = add_users_to_account(@account)
+ end
+
+ subject { @account.employments }
+
+ it { should == @employments }
+ end
+ end
+
+ def add_users_to_account(account)
+ employments = []
+ user = Woopy::User.create(user_attributes)
+ employment = account.employ(user)
+ employments << employment
+ employments
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.