Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Find a user by email and a few doc fixes.

  • Loading branch information...
commit 9cfd4eef96ea6679ac8a4f073a826e9c9592cca6 1 parent 82ed27b
Alex Coomans drcapulet authored
7 README.rdoc
View
@@ -235,14 +235,15 @@ Please note: version 0.2 is significantly different from 0.1 so if you are upgra
@users = User.find :all # returns all users
@user = User.find id # returns specific user
+ @user = User.find_by_email email
<b>Create user</b>
# Required attributes
- # :first-name
- # :last-name
+ # :first_name
+ # :last_name
# :email
- # :role
+ # :role # must be Owner, Director, Partner, Company Secretary, Employee, Shareholder, or Accountant
# :password
# :password_confirmation
7 lib/freeagent_api.rb
View
@@ -115,5 +115,12 @@ def self.find(*arguments)
# Users
class User < Base
self.prefix = '/company/'
+ def self.find_by_email(email)
+ users = User.find :all
+ users.each do |u|
+ u.email == email ? (return u) : next
+ end
+ raise Error, "No user matches that email!"
+ end
end
end
2  test/stubs/users/find_all
View
@@ -19,7 +19,7 @@ Content-Type: application/xml; charset=utf-8
</user>
<user>
<company-id type="integer">11</company-id>
- <email>olly@lylo.co.uk</email>
+ <email>olly@gmail.com</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>
2  test/stubs/users/find_single
View
@@ -5,7 +5,7 @@ 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>
+ <email>olly@gmail.com</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>
42 test/user_test.rb
View
@@ -42,18 +42,34 @@ class UserTest < Test::Unit::TestCase
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
+
+ context "Finding User" do
+ setup do
+ @user = User.find_by_email('olly@gmail.com')
+ end
+ should "return a User" do
+ assert @user.is_a? User
+ end
+ should "return the correct User" do
+ assert_equal User.find(11), @user
+ end
+ end
+
+ context "New User" do
+ setup do
+ params = {
+ :first_name => 'John',
+ :last_name => 'Doe',
+ :email => 'jdoe@example.com',
+ :role => 'Owner',
+ :password => 'password',
+ :password_confirmation => 'password'
+ }
+ @user = User.new params
+ end
+ should "validate and save" do
+ assert @user.save_with_validation
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.