Skip to content
Browse files

Users Resource

  • Loading branch information...
1 parent 3ce3c12 commit 82ed27ba66c95c8893658ef18afa4ab42f697590 @drcapulet drcapulet committed
Showing with 157 additions and 5 deletions.
  1. +1 −1 LICENSE
  2. +35 −2 README.rdoc
  3. +6 −2 lib/freeagent_api.rb
  4. +33 −0 test/stubs/users/find_all
  5. +18 −0 test/stubs/users/find_single
  6. +5 −0 test/test_helper.rb
  7. +59 −0 test/user_test.rb
View
2 LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2009 Aaron Russell
+Copyright (c) 2010 Aaron Russell & Alex Coomans
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
37 README.rdoc
@@ -11,10 +11,10 @@ This supports all GET, POST, PUT and DELETE ActiveResource calls for the followi
* Invoices
* Invoice Items
* Timeslips
+* Users
At the moment, the following API resources are NOT supported (although is being worked on):
-* Users
* Expenses
* Attachments
@@ -229,10 +229,43 @@ Please note: version 0.2 is significantly different from 0.1 so if you are upgra
# or
@timeslip.destroy
+=== Users
+
+<b>Find users</b>
+
+ @users = User.find :all # returns all users
+ @user = User.find id # returns specific user
+
+<b>Create user</b>
+
+ # Required attributes
+ # :first-name
+ # :last-name
+ # :email
+ # :role
+ # :password
+ # :password_confirmation
+
+
+ @user = User.new params
+ @user.save
+
+<b>Update user</b>
+
+ @user.first_name = '3.5'
+ @user.save
+
+<b>Delete user</b>
+
+ User.delete id
+ # or
+ @user.destroy
+
== Author
* Aaron Russell - (www.aaronrussell.co.uk)
+* Alex Comans - (www.alexcoomans.com)
== Copyright
-Copyright (c) 2009 Aaron Russell. See LICENSE for details.
+Copyright (c) 2010 Aaron Russell & Alex Coomans. See LICENSE for details.
View
8 lib/freeagent_api.rb
@@ -1,5 +1,5 @@
require 'rubygems'
-require 'activeresource'
+require 'active_resource'
module Freeagent
@@ -111,5 +111,9 @@ def self.find(*arguments)
end
end
end
-
+
+ # Users
+ class User < Base
+ self.prefix = '/company/'
+ end
end
View
33 test/stubs/users/find_all
@@ -0,0 +1,33 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<users type="array">
+ <user>
+ <company-id type="integer">10</company-id>
+ <email>olly@lylo.co.uk</email>
+ <first-name>Olly</first-name>
+ <id type="integer">11</id>
+ <last-logged-in-at type="datetime">2008-03-03T21:16:09Z</last-logged-in-at>
+ <last-name>Headey</last-name>
+ <opening-director-loan-account-balance type="decimal">0.0</opening-director-loan-account-balance>
+ <opening-expense-balance type="decimal">0.0</opening-expense-balance>
+ <opening-salary-balance type="decimal">0.0</opening-salary-balance>
+ <opening-share-or-capital-balance type="decimal">0.0</opening-share-or-capital-balance>
+ <role>Director</role>
+ </user>
+ <user>
+ <company-id type="integer">11</company-id>
+ <email>olly@lylo.co.uk</email>
+ <first-name>Olly</first-name>
+ <id type="integer">11</id>
+ <last-logged-in-at type="datetime">2008-03-03T21:16:09Z</last-logged-in-at>
+ <last-name>Headey</last-name>
+ <opening-director-loan-account-balance type="decimal">0.0</opening-director-loan-account-balance>
+ <opening-expense-balance type="decimal">0.0</opening-expense-balance>
+ <opening-salary-balance type="decimal">0.0</opening-salary-balance>
+ <opening-share-or-capital-balance type="decimal">0.0</opening-share-or-capital-balance>
+ <role>Director</role>
+ </user>
+</users>
View
18 test/stubs/users/find_single
@@ -0,0 +1,18 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<user>
+ <company-id type="integer">11</company-id>
+ <email>olly@lylo.co.uk</email>
+ <first-name>Olly</first-name>
+ <id type="integer">11</id>
+ <last-logged-in-at type="datetime">2008-03-03T21:16:09Z</last-logged-in-at>
+ <last-name>Headey</last-name>
+ <opening-director-loan-account-balance type="decimal">0.0</opening-director-loan-account-balance>
+ <opening-expense-balance type="decimal">0.0</opening-expense-balance>
+ <opening-salary-balance type="decimal">0.0</opening-salary-balance>
+ <opening-share-or-capital-balance type="decimal">0.0</opening-share-or-capital-balance>
+ <role>Director</role>
+</user>
View
5 test/test_helper.rb
@@ -43,6 +43,8 @@ def fake_it_all
'/timeslips.xml?view=2009-10-01_2009-10-10' => File.join('timeslips', 'find_all'),
'/timeslips/84445.xml' => File.join('timeslips', 'find_single'),
'/projects/17820/timeslips.xml' => File.join('projects', 'timeslips'),
+ '/company/users.xml' => File.join('users', 'find_all'),
+ '/company/users/11.xml' => File.join('users', 'find_single')
}.each do |path, stub|
FakeWeb.register_uri(:get, site_url+path, :response => stub_file(stub))
end
@@ -54,6 +56,7 @@ def fake_it_all
'/invoices.xml' => File.join('http', '201'),
'/invoices/73867/invoice_items.xml' => File.join('http', '201'),
'/timeslips.xml' => File.join('http', '201'),
+ '/company/users.xml' => File.join('http', '201')
}.each do |path, stub|
FakeWeb.register_uri(:post, site_url+path, :response => stub_file(stub))
end
@@ -70,6 +73,7 @@ def fake_it_all
'/invoices/73867/invoice_items/169399.xml' => File.join('http', '200'),
'/timeslips/84445.xml' => File.join('http', '200'),
'/timeslips/74814.xml' => File.join('http', '200'),
+ '/company/users/11.xml' => File.join('http', '200')
}.each do |path, stub|
FakeWeb.register_uri(:put, site_url+path, :response => stub_file(stub))
end
@@ -83,6 +87,7 @@ def fake_it_all
'/invoices/73867/invoice_items/169399.xml' => File.join('http', '200'),
'/timeslips/84445.xml' => File.join('http', '200'),
'/timeslips/74814.xml' => File.join('http', '200'),
+ '/company/users/11.xml' => File.join('http', '200')
}.each do |path, stub|
FakeWeb.register_uri(:delete, site_url+path, :response => stub_file(stub))
end
View
59 test/user_test.rb
@@ -0,0 +1,59 @@
+require 'test_helper'
+
+class UserTest < Test::Unit::TestCase
+
+ fake_it_all
+
+ context "User class" do
+ should "have correct collection path" do
+ assert_equal '/company/users.xml', User.collection_path
+ end
+ should "have correct element path" do
+ assert_equal '/company/users/first.xml', User.element_path(:first)
+ assert_equal '/company/users/1000.xml', User.element_path(1000)
+ end
+ end
+
+ context "Users" do
+ setup do
+ @users = User.find :all
+ end
+ should "return an array" do
+ assert @users.is_a? Array
+ end
+ should "return Users" do
+ assert_equal 2, @users.size
+ assert @users.first.is_a? User
+ end
+ end
+
+ context "User" do
+ setup do
+ @user = User.find 11
+ end
+ should "return a User" do
+ assert @user.is_a? User
+ end
+ should "update and save" do
+ @user.email = 'olly@gmail.com'
+ assert @user.save
+ end
+ should "be destroyed" do
+ assert @user.destroy
+ end
+ end
+ #
+ # context "New User" do
+ # setup do
+ # params = {
+ # :project_id => '17820',
+ # :name => 'Creative design'
+ # }
+ # @task = User.new params
+ # end
+ # should "validate and save" do
+ # assert @task.save_with_validation
+ # end
+ # end
+
+end

0 comments on commit 82ed27b

Please sign in to comment.
Something went wrong with that request. Please try again.