board-client 0.3.0 → 0.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.rvmrc +47 -0
- data/Gemfile +1 -7
- data/README.md +63 -17
- data/Rakefile +4 -44
- data/board-client.gemspec +22 -66
- data/lib/board/client.rb +41 -22
- data/lib/board/client/api.rb +29 -0
- data/lib/board/client/candidates.rb +13 -0
- data/lib/board/client/organizations.rb +17 -0
- data/lib/board/client/request.rb +98 -0
- data/lib/board/client/user_organizations.rb +20 -0
- data/lib/board/client/users.rb +21 -0
- data/lib/board/client/version.rb +5 -0
- data/spec/board/client_spec.rb +27 -83
- data/spec/cassettes/candidate_exists_with_id.yml +30 -0
- data/spec/cassettes/candidate_id_does_not_exist.yml +336 -0
- data/spec/cassettes/candidate_invite_email_exists.yml +30 -0
- data/spec/cassettes/candidate_invite_when_invalid.yml +30 -0
- data/spec/cassettes/candidate_invite_when_valid.yml +32 -0
- data/spec/cassettes/list_user_organizations_with_invalid_id.yml +346 -0
- data/spec/cassettes/list_user_organizations_with_valid_id.yml +30 -0
- data/spec/cassettes/organization_add_user.yml +26 -0
- data/spec/cassettes/organization_add_user_-_organization_does_not_exist.yml +356 -0
- data/spec/cassettes/organization_add_user_-_user_does_not_exist.yml +348 -0
- data/spec/cassettes/organization_create_is_invalid.yml +30 -0
- data/spec/cassettes/organization_create_is_valid.yml +32 -0
- data/spec/cassettes/organization_exists_with_email.yml +30 -0
- data/spec/cassettes/organization_exists_with_id.yml +30 -0
- data/spec/cassettes/organization_id_does_not_exist.yml +354 -0
- data/spec/cassettes/organization_name_does_not_exist.yml +334 -0
- data/spec/cassettes/unsubscribe_email_does_not_exist.yml +340 -0
- data/spec/cassettes/unsubscribe_email_exists.yml +30 -0
- data/spec/cassettes/user_does_exist.yml +30 -0
- data/spec/cassettes/user_does_not_exist.yml +32 -0
- data/spec/cassettes/user_email_does_not_exist.yml +334 -0
- data/spec/cassettes/user_email_md5_does_not_exist.yml +334 -0
- data/spec/cassettes/user_exists_with_email.yml +30 -0
- data/spec/cassettes/user_exists_with_email_md5.yml +30 -0
- data/spec/cassettes/user_exists_with_id.yml +30 -0
- data/spec/cassettes/user_id_does_not_exist.yml +346 -0
- data/spec/cassettes/user_missing_attributes.yml +30 -0
- data/spec/integration/candidates/find_spec.rb +28 -0
- data/spec/integration/candidates/invite_spec.rb +48 -0
- data/spec/integration/organizations/add_user_spec.rb +34 -0
- data/spec/integration/organizations/create_spec.rb +38 -0
- data/spec/integration/organizations/find_spec.rb +50 -0
- data/spec/integration/users/create_spec.rb +54 -0
- data/spec/integration/users/find_spec.rb +73 -0
- data/spec/integration/users/list_organizations_spec.rb +36 -0
- data/spec/integration/users/unsubscribe_spec.rb +27 -0
- data/spec/spec_helper.rb +6 -5
- data/spec/support/integration_helpers.rb +17 -0
- data/spec/support/vcr.rb +11 -0
- metadata +144 -52
- data/Gemfile.lock +0 -22
- data/lib/board/candidate_search.rb +0 -45
- data/lib/board/request.rb +0 -78
- data/spec/board/candidate_search_spec.rb +0 -45
- data/spec/spec.opts +0 -1
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Candidate Find' do
|
4
|
+
|
5
|
+
context 'by id' do
|
6
|
+
context 'when the candidate exists' do
|
7
|
+
use_vcr_cassette 'candidate exists with id'
|
8
|
+
|
9
|
+
it 'returns a user with the correct attributes' do
|
10
|
+
candidate = board.candidates.find(100)
|
11
|
+
|
12
|
+
candidate.id.should == 100
|
13
|
+
candidate.email.should == 'candidate@recruitmilitary.com'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when the candidate does not exist' do
|
18
|
+
use_vcr_cassette 'candidate id does not exist'
|
19
|
+
|
20
|
+
it 'raises a not found exception' do
|
21
|
+
expect {
|
22
|
+
board.candidates.find(42)
|
23
|
+
}.to raise_error(Board::Client::NotFound)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Candidate Invite' do
|
4
|
+
|
5
|
+
def create_invitation(attributes = {})
|
6
|
+
attributes = {
|
7
|
+
:email => "makers@mark.com",
|
8
|
+
:first_name => "Maker's",
|
9
|
+
:last_name => "Mark"
|
10
|
+
}.merge(attributes)
|
11
|
+
|
12
|
+
board.candidates.invite(attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when the email is not already registered' do
|
16
|
+
context 'and the invitation is valid' do
|
17
|
+
use_vcr_cassette 'candidate invite when valid'
|
18
|
+
|
19
|
+
it 'returns an invitation with the correct attributes' do
|
20
|
+
invitation = create_invitation
|
21
|
+
|
22
|
+
invitation.email.should == "makers@mark.com"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'and the invitation is not valid' do
|
27
|
+
use_vcr_cassette 'candidate invite when invalid'
|
28
|
+
|
29
|
+
it 'raises an error' do
|
30
|
+
expect {
|
31
|
+
create_invitation(:email => nil)
|
32
|
+
}.to raise_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# TODO: should this be considered when the invitation is not valid?
|
38
|
+
context 'when the email belongs to an existing user' do
|
39
|
+
use_vcr_cassette 'candidate invite email exists'
|
40
|
+
|
41
|
+
it 'raises a conflict error' do
|
42
|
+
expect {
|
43
|
+
create_invitation(:email => "candidate@recruitmilitary.com")
|
44
|
+
}.to raise_error(Board::Client::Conflict)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Organization Add User' do
|
4
|
+
|
5
|
+
context 'when the user and organization exist' do
|
6
|
+
use_vcr_cassette "organization add user"
|
7
|
+
|
8
|
+
it 'responds with an empty success' do
|
9
|
+
response = board.user_organizations.create(:user_id => 1, :organization_id => 3)
|
10
|
+
response.should be_true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when the user does not exist' do
|
15
|
+
use_vcr_cassette "organization add user - user does not exist"
|
16
|
+
|
17
|
+
it 'raises a not found error' do
|
18
|
+
expect {
|
19
|
+
board.user_organizations.create(:user_id => 100_000, :organization_id => 1)
|
20
|
+
}.to raise_error(Board::Client::NotFound)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when the organization does not exist' do
|
25
|
+
use_vcr_cassette "organization add user - organization does not exist"
|
26
|
+
|
27
|
+
it 'raises a not found error' do
|
28
|
+
expect {
|
29
|
+
board.user_organizations.create(:user_id => 1, :organization_id => 100_000)
|
30
|
+
}.to raise_error(Board::Client::NotFound)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Organization Create' do
|
4
|
+
|
5
|
+
def create_organization(attributes = {})
|
6
|
+
attributes = {
|
7
|
+
:name => "Nike",
|
8
|
+
:description => "<h1>Nike Shoes</h1>",
|
9
|
+
:website => "http://nike.com",
|
10
|
+
}.merge(attributes)
|
11
|
+
|
12
|
+
board.organizations.create(attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when valid' do
|
16
|
+
use_vcr_cassette "organization create is valid"
|
17
|
+
|
18
|
+
it 'creates the organization' do
|
19
|
+
organization = create_organization
|
20
|
+
|
21
|
+
organization.id.should_not be_blank
|
22
|
+
organization.name.should == "Nike"
|
23
|
+
organization.description.should == "<h1>Nike Shoes</h1>"
|
24
|
+
organization.website.should == "http://nike.com"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when invalid' do
|
29
|
+
use_vcr_cassette "organization create is invalid"
|
30
|
+
|
31
|
+
it 'raises an error' do
|
32
|
+
expect {
|
33
|
+
create_organization(:name => nil)
|
34
|
+
}.to raise_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Organization Find' do
|
4
|
+
|
5
|
+
context 'by id' do
|
6
|
+
context 'when the organization exists' do
|
7
|
+
use_vcr_cassette 'organization exists with id'
|
8
|
+
|
9
|
+
it 'returns an organization with the correct attributes' do
|
10
|
+
organization = board.organizations.find(1)
|
11
|
+
|
12
|
+
organization.id.should == 1
|
13
|
+
organization.name.should == "RecruitMilitary"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when the organization does not exist' do
|
18
|
+
use_vcr_cassette 'organization id does not exist'
|
19
|
+
|
20
|
+
it 'raises a not found error' do
|
21
|
+
expect {
|
22
|
+
board.organizations.find(100_000)
|
23
|
+
}.to raise_error(Board::Client::NotFound)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'by name' do
|
29
|
+
context 'when the organization exists' do
|
30
|
+
use_vcr_cassette 'organization exists with email'
|
31
|
+
|
32
|
+
it 'returns an organization with the correct attributes' do
|
33
|
+
organization = board.organizations.find(:name => "RecruitMilitary")
|
34
|
+
|
35
|
+
organization.name.should == "RecruitMilitary"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when the organization does not exist' do
|
40
|
+
use_vcr_cassette 'organization name does not exist'
|
41
|
+
|
42
|
+
it 'raises a not found error' do
|
43
|
+
expect {
|
44
|
+
board.organizations.find(:name => "Blah Blah")
|
45
|
+
}.to raise_error(Board::Client::NotFound)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'User Create' do
|
4
|
+
|
5
|
+
def create_user(attributes = {})
|
6
|
+
attributes = {
|
7
|
+
:email => "steve@apple.com",
|
8
|
+
:first_name => "Steve",
|
9
|
+
:last_name => "Jobs",
|
10
|
+
:primary_role_id => 1,
|
11
|
+
:password => "password",
|
12
|
+
:password_confirmation => "password"
|
13
|
+
}.merge(attributes)
|
14
|
+
|
15
|
+
board.users.create(attributes)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when no user with the email exists' do
|
19
|
+
use_vcr_cassette "user does not exist"
|
20
|
+
|
21
|
+
it 'creates the user' do
|
22
|
+
user = create_user
|
23
|
+
|
24
|
+
user.email.should == "steve@apple.com"
|
25
|
+
user.first_name.should == "Steve"
|
26
|
+
user.last_name.should == "Jobs"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when a user with the email exists' do
|
31
|
+
use_vcr_cassette "user does exist"
|
32
|
+
|
33
|
+
it 'raises an error' do
|
34
|
+
begin
|
35
|
+
create_user
|
36
|
+
rescue Board::Client::Error => e
|
37
|
+
end
|
38
|
+
|
39
|
+
e.response.body.should =~ /is already taken/
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when missing required attributes' do
|
44
|
+
use_vcr_cassette "user missing attributes"
|
45
|
+
|
46
|
+
it 'raises an error' do
|
47
|
+
expect {
|
48
|
+
create_user(:email => nil)
|
49
|
+
}.to raise_error
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'User Find' do
|
4
|
+
|
5
|
+
context 'by id' do
|
6
|
+
context 'when the user exists' do
|
7
|
+
use_vcr_cassette 'user exists with id'
|
8
|
+
|
9
|
+
it 'returns a user with the correct attributes' do
|
10
|
+
user = board.users.find(1)
|
11
|
+
|
12
|
+
user.id.should == 1
|
13
|
+
user.email.should == 'staff@recruitmilitary.com'
|
14
|
+
user.first_name.should == 'Staff'
|
15
|
+
user.last_name.should == 'McStafforson'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when the user does not exist' do
|
20
|
+
use_vcr_cassette 'user id does not exist'
|
21
|
+
|
22
|
+
it 'raises a not found exception' do
|
23
|
+
expect {
|
24
|
+
board.users.find(42)
|
25
|
+
}.to raise_error(Board::Client::NotFound)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'by email' do
|
31
|
+
context 'when the user exists' do
|
32
|
+
use_vcr_cassette 'user exists with email'
|
33
|
+
|
34
|
+
it 'returns a user with the correct attributes' do
|
35
|
+
user = board.users.find(:email => 'candidate@recruitmilitary.com')
|
36
|
+
|
37
|
+
user.email.should == 'candidate@recruitmilitary.com'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when the user does not exist' do
|
42
|
+
use_vcr_cassette 'user email does not exist'
|
43
|
+
|
44
|
+
it 'raises a not found exception' do
|
45
|
+
expect {
|
46
|
+
board.users.find(:email => 'michael@jordan.com')
|
47
|
+
}.to raise_error(Board::Client::NotFound)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'by email_md5' do
|
53
|
+
context 'when the user exists' do
|
54
|
+
use_vcr_cassette 'user exists with email md5'
|
55
|
+
|
56
|
+
it 'returns a user with the correct attributes' do
|
57
|
+
user = board.users.find(:email_md5 => '3e67fa7c8045d085e66a51deee26cbc4')
|
58
|
+
|
59
|
+
user.email.should == 'staff@recruitmilitary.com'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when the user does not exist' do
|
64
|
+
use_vcr_cassette 'user email md5 does not exist'
|
65
|
+
|
66
|
+
it 'raises a not found exception' do
|
67
|
+
expect {
|
68
|
+
board.users.find(:email_md5 => '93e8d736de5088cb392465e024b69eef')
|
69
|
+
}.to raise_error(Board::Client::NotFound)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'List User Organizations' do
|
4
|
+
|
5
|
+
context 'with a valid user id' do
|
6
|
+
use_vcr_cassette "list user organizations with valid id"
|
7
|
+
|
8
|
+
it 'returns a list of organizations that the user belong to' do
|
9
|
+
organizations = board.user_organizations.list(:user_id => 1)
|
10
|
+
|
11
|
+
organizations.size.should == 2
|
12
|
+
organization = organizations.first
|
13
|
+
|
14
|
+
organization.name.should == "Local Organization"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'without a user id' do
|
19
|
+
it 'raises an error' do
|
20
|
+
expect {
|
21
|
+
board.user_organizations.list(:foo => :bar)
|
22
|
+
}.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with an invalid user id' do
|
27
|
+
use_vcr_cassette "list user organizations with invalid id"
|
28
|
+
|
29
|
+
it 'raises an error' do
|
30
|
+
expect {
|
31
|
+
board.user_organizations.list(:user_id => 1_000_000)
|
32
|
+
}.to raise_error(Board::Client::NotFound)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'User Unsubscribe' do
|
4
|
+
|
5
|
+
context 'by email' do
|
6
|
+
context 'when the user exists' do
|
7
|
+
use_vcr_cassette 'unsubscribe email exists'
|
8
|
+
|
9
|
+
it 'returns true' do
|
10
|
+
response = board.users.unsubscribe("candidate@recruitmilitary.com")
|
11
|
+
|
12
|
+
response.should be_true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when the user does not exist' do
|
17
|
+
use_vcr_cassette 'unsubscribe email does not exist'
|
18
|
+
|
19
|
+
it 'raises a not found error' do
|
20
|
+
expect {
|
21
|
+
board.users.unsubscribe("michael@jordan.com")
|
22
|
+
}.to raise_error(Board::Client::NotFound)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'board-client'
|
4
|
-
require '
|
5
|
-
|
6
|
-
require
|
4
|
+
require 'rspec'
|
5
|
+
|
6
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
7
7
|
|
8
|
-
|
8
|
+
Board::Client.default_endpoint = 'http://localhost:3000/api/v1'
|
9
9
|
|
10
|
-
|
10
|
+
require 'webmock/rspec'
|
11
|
+
RSpec.configure do |config|
|
11
12
|
config.include WebMock::API
|
12
13
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module IntegrationHelpers
|
2
|
+
|
3
|
+
def board
|
4
|
+
@board ||= Board::Client.new('Bdrc3t1LaiWtygbJ4jD6')
|
5
|
+
end
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
def config.escaped_path(*parts)
|
11
|
+
Regexp.compile(parts.join('[\\\/]'))
|
12
|
+
end
|
13
|
+
|
14
|
+
config.include IntegrationHelpers, :type => :integration, :example_group => {
|
15
|
+
:file_path => config.escaped_path(%w[spec integration])
|
16
|
+
}
|
17
|
+
end
|
data/spec/support/vcr.rb
ADDED