Skip to content

Commit 0e84fdd

Browse files
authored
Merge pull request #40 from checkr/g/verifications
Add Verification
2 parents e8a3e50 + 0914363 commit 0e84fdd

9 files changed

Lines changed: 146 additions & 1 deletion

File tree

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v1.5.0 (2018-02-2)
2+
3+
Features:
4+
5+
- Add Verification
6+
17
## v1.4.0 (2018-01-24)
28

39
Features:

lib/checkr.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
require 'checkr/sex_offender_search'
3636
require 'checkr/ssn_trace'
3737
require 'checkr/subscription'
38+
require 'checkr/verification'
39+
require 'checkr/verification_list'
3840

3941
# Errors
4042
require 'checkr/errors/checkr_error'

lib/checkr/report.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class Report < APIResource
3535
attribute :documents, APIList.constructor(:Document)
3636
attribute_writer_alias :document_ids, :documents
3737

38+
attribute :verifications, :VerificationList, :nested => true, :default => {}
39+
attribute_writer_alias :verification_ids, :verifications
40+
3841
api_class_method :retrieve, :get, ":path/:id", :arguments => [:id]
3942
api_class_method :create, :post
4043

lib/checkr/verification.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Checkr
2+
class Verification < APIResource
3+
4+
attribute :verification_type
5+
attribute :verification_url
6+
attribute :completed_at
7+
8+
api_class_method :all, :get, "/v1/reports/:report_id/verifications", :constructor => :VerificationList
9+
10+
APIClass.register_subclass(self, "verification")
11+
end
12+
end

lib/checkr/verification_list.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Checkr
2+
class VerificationList < APIList
3+
4+
attribute :next_href
5+
attribute :previous_href
6+
attribute :count
7+
attr_accessor :parent
8+
9+
api_instance_method :all, :get
10+
11+
def self.construct(json, parent=nil)
12+
lambda = constructor(:Verification)
13+
instance = lambda.call(json)
14+
instance.parent = parent if parent
15+
instance.clear_changed_attributes
16+
instance
17+
end
18+
19+
def path
20+
parent.path + "/verifications"
21+
end
22+
23+
end
24+
end

lib/checkr/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Checkr
2-
VERSION = '1.4.0'.freeze
2+
VERSION = '1.5.0'.freeze
33
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require File.expand_path('../../test_helper', __FILE__)
2+
3+
module Checkr
4+
class VerificationListTest < Test::Unit::TestCase
5+
setup do
6+
@report = Report.construct(test_report)
7+
@verification_url = "#{Checkr.api_base}#{@report.path}/verifications"
8+
end
9+
10+
context 'VerificationList class' do
11+
should 'be listable' do
12+
@mock.expects(:get).once.with(@verification_url, anything, anything).returns(test_response(test_verification_list))
13+
14+
verifications = @report.verifications.all
15+
16+
assert(verifications.is_a?(VerificationList))
17+
verifications.each do |document|
18+
assert(document.is_a?(Verification))
19+
end
20+
assert(verifications.length > 0)
21+
end
22+
end
23+
24+
end
25+
end

test/checkr/verifications_test.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require File.expand_path('../../test_helper', __FILE__)
2+
3+
module Checkr
4+
class VerificationTest < Test::Unit::TestCase
5+
setup do
6+
@report = Report.construct(test_report)
7+
@verification_url = "#{Checkr.api_base}#{@report.path}/verifications"
8+
end
9+
10+
context 'Constructed Verification instance' do
11+
setup do
12+
@verification = Verification.construct(test_verification)
13+
end
14+
15+
should 'have the id attribute' do
16+
assert_equal(test_verification[:id], @verification.id)
17+
end
18+
19+
should 'have the object attribute' do
20+
assert_equal(test_verification[:object], @verification.object)
21+
end
22+
23+
should 'have the uri attribute' do
24+
assert_equal(test_verification[:uri], @verification.uri)
25+
end
26+
27+
should 'have the created_at attribute' do
28+
assert_equal(test_verification[:created_at], @verification.created_at)
29+
end
30+
31+
should 'have the completed_at attribute' do
32+
assert_equal(test_verification[:completed_at], @verification.completed_at)
33+
end
34+
35+
should 'have the verification_type attribute' do
36+
assert_equal(test_verification[:verification_type], @verification.verification_type)
37+
end
38+
39+
should 'have the verification_url attribute' do
40+
assert_equal(test_verification[:verification_url], @verification.verification_url)
41+
end
42+
end
43+
44+
context '#all' do
45+
should 'return instances of Verification' do
46+
@mock.expects(:get).once.with(@verification_url, anything, anything)
47+
.returns(test_response(test_verification_list))
48+
assert_equal(@report.verifications.all.first.class, Verification)
49+
end
50+
end
51+
52+
should 'be registered' do
53+
assert(APIClass.subclasses.include?(Verification))
54+
assert_equal(Verification, APIClass.subclass_fetch('verification'))
55+
end
56+
57+
end
58+
end

test/test_data.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,21 @@ def test_document_list
457457
}
458458
end
459459

460+
def test_verification
461+
{:id=>"db313e73383710d4fa2f18fd",
462+
:object=>"verification",
463+
:created_at=>"2015-02-11T20:01:50Z",
464+
:verification_type=>"id",
465+
:verification_url=>"http://verifications.checkr.com/db313e73383710d4fa2f18fd",
466+
:completed_at=>nil}
467+
end
468+
def test_verification_list
469+
{
470+
:object => 'list',
471+
:data => [test_verification, test_verification, test_verification],
472+
}
473+
end
474+
460475
# Errors
461476
def test_api_error
462477
{

0 commit comments

Comments
 (0)