caren-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/caren/link.rb ADDED
@@ -0,0 +1,43 @@
1
+ class Caren::Link < Caren::Base
2
+
3
+ def self.keys
4
+ [:person_name, # String (Caren person name)
5
+ :person_id, # String (Caren person id)
6
+ :person_photo, # String (url of photo)
7
+ :patient_number, # String (12345)
8
+ :external_id, # String (Your person id)
9
+ :status # String (pending,confirmed,cancelled)
10
+ ]
11
+ end
12
+
13
+ def self.search key, value
14
+ from_xml Caren::Api.get( self.search_url(key,value) )
15
+ end
16
+
17
+ def self.all
18
+ from_xml Caren::Api.get(self.resource_url)
19
+ end
20
+
21
+ # Request to create a new link. Example:
22
+ # Caren::Link.new( :patient_number => 1234 ).create
23
+ def create
24
+ Caren::Api.post(self.resource_url, self.to_xml)
25
+ end
26
+
27
+ def as_xml
28
+ { :patient_number => self.patient_number }
29
+ end
30
+
31
+ def self.array_root
32
+ :links
33
+ end
34
+
35
+ def self.node_root
36
+ :link
37
+ end
38
+
39
+ def self.resource_location
40
+ "/api/links/"
41
+ end
42
+
43
+ end
@@ -0,0 +1,25 @@
1
+ class Caren::Person < Caren::Base
2
+
3
+ def self.keys
4
+ [ :external_id, # String (Your person id)
5
+ :uid, # String (Customer unique code)
6
+ :first_name, # String
7
+ :last_name, # String
8
+ :male, # Boolean
9
+ :date_of_birth, # Date
10
+ :address_street, # String
11
+ :address_zipcode, # String
12
+ :address_city, # String
13
+ :address_country # String
14
+ ]
15
+ end
16
+
17
+ def self.array_root
18
+ :people
19
+ end
20
+
21
+ def self.node_root
22
+ :person
23
+ end
24
+
25
+ end
data/lib/caren-api.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "digest/sha2"
2
+ require "uri"
3
+ require "net/https"
4
+
5
+ begin
6
+ require "rubygems"
7
+ rescue LoadError
8
+ end
9
+
10
+ require "active_support"
11
+ require "active_support/secure_random"
12
+ require "active_support/core_ext"
13
+ require "builder"
14
+ require "rest_client"
15
+ require "rexml/document"
16
+ require "base64"
17
+
18
+ require "lib/caren/caren.rb"
19
+ require "lib/caren/error.rb"
20
+ require "lib/caren/base.rb"
21
+ require "lib/caren/event.rb"
22
+ require "lib/caren/person.rb"
23
+ require "lib/caren/care_provider.rb"
24
+ require "lib/caren/external_message.rb"
25
+ require "lib/caren/link.rb"
data/spec/.DS_Store ADDED
Binary file
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe "CareProvider", "converting to xml" do
4
+
5
+ before do
6
+ @care_provider_a = Caren::CareProvider.new( :name => "Zuwe",
7
+ :telephone => "112",
8
+ :website => "http://www.zuwe.nl",
9
+ :email => "zuwe@example.com",
10
+ :address_line => "Sesamestreet 1",
11
+ :url_shortcut => "zuwe",
12
+ :time_zone => "Amsterdam",
13
+ :resolution => "exact",
14
+ :bandwidth => "0",
15
+ :min_start => "07:00",
16
+ :max_start => "00:00",
17
+ :show_employee_name_as_title => true,
18
+ :show_employee_names => true,
19
+ :communication => true )
20
+
21
+ @care_provider_b = Caren::CareProvider.new( :name => "Aveant",
22
+ :telephone => "112",
23
+ :website => "http://www.aveant.nl",
24
+ :email => "aveant@example.com",
25
+ :address_line => "Sesamestreet 1",
26
+ :url_shortcut => "zuwe",
27
+ :time_zone => "Amsterdam",
28
+ :resolution => "exact",
29
+ :bandwidth => "0",
30
+ :min_start => "07:00",
31
+ :max_start => "00:00",
32
+ :show_employee_name_as_title => true,
33
+ :show_employee_names => true,
34
+ :communication => true )
35
+ end
36
+
37
+ it "should be able to convert a person to valid xml" do
38
+ @care_provider_a.should convert_to_valid_caren_xml
39
+ end
40
+
41
+ it "should be able to convert an array of people to valid xml" do
42
+ [@care_provider_a,@care_provider_b].should convert_to_valid_caren_array_xml
43
+ end
44
+
45
+ it "should be able to generate a proper xml file to update the logo" do
46
+ filename = "spec/fixtures/bacon.jpg"
47
+ xml = @care_provider_a.to_logo_xml filename
48
+ doc = REXML::Document.new(xml)
49
+ doc.elements.each('care_provider/logo') do |cp|
50
+ cp.attributes["name"].should == "bacon.jpg"
51
+ cp.attributes["content-type"].should == "image/jpeg"
52
+ cp.text.should == Base64.encode64(File.open(filename).read)
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ describe "CareProvider" do
59
+
60
+ it "should be able to convert a image file path to a hash suited for xml conversion" do
61
+ filename = "spec/fixtures/bacon.jpg"
62
+ logo = Caren::CareProvider.logo_hash( filename )
63
+ logo[:content_type].should == "image/jpeg"
64
+ logo[:name].should == "bacon.jpg"
65
+ logo[:content].should == Base64.encode64(File.open(filename).read)
66
+ end
67
+
68
+ end
69
+
70
+ describe "CareProvider", "REST methods" do
71
+
72
+ before do
73
+ care_providers = File.read("spec/fixtures/caren_care_providers.xml")
74
+ care_providers_search = File.read("spec/fixtures/caren_care_providers_search.xml")
75
+ FakeWeb.register_uri(:put, Caren::CareProvider.resource_url(1), :signature => Caren::Api.sign )
76
+
77
+ FakeWeb.register_uri(:get, Caren::CareProvider.resource_url, :body => care_providers,
78
+ :signature => Caren::Api.sign(care_providers) )
79
+
80
+ FakeWeb.register_uri(:get, "#{Caren::CareProvider.resource_url}?key=url-shortcut&value=pantein",
81
+ :body => care_providers_search,
82
+ :signature => Caren::Api.sign(care_providers_search) )
83
+ end
84
+
85
+ it "should be able to update a care provider" do
86
+ lambda{ Caren::CareProvider.new( :caren_id => 1, :name => "Test" ).update }.should_not raise_error
87
+ end
88
+
89
+ it "should be able to update the logo for a care provider" do
90
+ lambda{ Caren::CareProvider.new( :caren_id => 1 ).update_logo( "spec/fixtures/bacon.jpg" ) }.should_not raise_error
91
+ end
92
+
93
+ it "should be able to search for a specific care provider" do
94
+ care_providers = Caren::CareProvider.search :url_shortcut, "pantein"
95
+ care_providers.should have(1).things
96
+ care_providers.first.name.should == "Pantein"
97
+ care_providers.first.url_shortcut.should == "pantein"
98
+ end
99
+
100
+ it "should be able to find all care providers" do
101
+ care_providers = Caren::CareProvider.all
102
+ care_providers.should have(2).things
103
+ care_providers.first.name.should == "Demo"
104
+ care_providers.first.url_shortcut.should == "demo"
105
+ end
106
+
107
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Caren", "signature checks" do
4
+
5
+ before do
6
+ @incorrect_url = "#{Caren::Api.url}/test_with_incorrect_signature"
7
+ @correct_url = "#{Caren::Api.url}/test_with_correct_signature"
8
+ @error_url = "#{Caren::Api.url}/test_with_errors"
9
+
10
+ FakeWeb.register_uri(:get, @incorrect_url, :body => "TEST", :signature => "[INCORRECT]" )
11
+ FakeWeb.register_uri(:post, @incorrect_url, :body => "TEST", :signature => "[INCORRECT]" )
12
+ FakeWeb.register_uri(:put, @incorrect_url, :body => "TEST", :signature => "[INCORRECT]" )
13
+ FakeWeb.register_uri(:delete, @incorrect_url, :body => "TEST", :signature => "[INCORRECT]" )
14
+
15
+ FakeWeb.register_uri(:get, @correct_url, :body => "TEST", :signature => Caren::Api.sign("TEST") )
16
+ FakeWeb.register_uri(:post, @correct_url, :body => "TEST", :signature => Caren::Api.sign("TEST") )
17
+ FakeWeb.register_uri(:put, @correct_url, :body => "TEST", :signature => Caren::Api.sign("TEST") )
18
+ FakeWeb.register_uri(:delete, @correct_url, :body => "TEST", :signature => Caren::Api.sign("TEST") )
19
+
20
+ errors = File.read "spec/fixtures/caren_care_provider_validation.xml"
21
+ unauth = File.read "spec/fixtures/caren_unauthorized.xml"
22
+ FakeWeb.register_uri(:get, @error_url, :status => 406, :body => errors, :signature => Caren::Api.sign(errors) )
23
+ FakeWeb.register_uri(:post, @error_url, :status => 406, :body => errors, :signature => Caren::Api.sign(errors) )
24
+ FakeWeb.register_uri(:put, @error_url, :status => 406, :body => errors, :signature => Caren::Api.sign(errors) )
25
+ FakeWeb.register_uri(:delete, @error_url, :status => 403, :body => unauth, :signature => Caren::Api.sign(unauth) )
26
+ end
27
+
28
+ it "should not accept result swith an incorrect signature" do
29
+ lambda{ Caren::Api.get @incorrect_url }.should raise_error
30
+ lambda{ Caren::Api.post @incorrect_url, "" }.should raise_error
31
+ lambda{ Caren::Api.put @incorrect_url, "" }.should raise_error
32
+ lambda{ Caren::Api.delete @incorrect_url }.should raise_error
33
+ end
34
+
35
+ it "should accept results with a correct signature" do
36
+ lambda{ Caren::Api.get @correct_url }.should_not raise_error
37
+ lambda{ Caren::Api.post @correct_url, "" }.should_not raise_error
38
+ lambda{ Caren::Api.put @correct_url, "" }.should_not raise_error
39
+ lambda{ Caren::Api.delete @correct_url }.should_not raise_error
40
+ end
41
+
42
+ it "should be able to handle server side errors" do
43
+
44
+ lambda{ Caren::Api.get @error_url }.should raise_error(Caren::Exceptions::ServerSideError)
45
+ lambda{ Caren::Api.put @error_url, "" }.should raise_error(Caren::Exceptions::ServerSideError)
46
+ lambda{ Caren::Api.post @error_url, "" }.should raise_error(Caren::Exceptions::ServerSideError)
47
+ lambda{ Caren::Api.delete @error_url }.should raise_error(Caren::Exceptions::ServerSideError)
48
+
49
+ end
50
+
51
+ it "should be able to handle authorization errors" do
52
+ begin
53
+ Caren::Api.delete @error_url
54
+ rescue Caren::Exceptions::ServerSideError => e
55
+ e.errors.should have(1).things
56
+ e.errors.first.class.should == Caren::Error
57
+ e.errors.first.category.should == "unauthorized"
58
+ e.errors.first.message.should == "You are not allowed to perform this action."
59
+ end
60
+ end
61
+
62
+ it "should be able to handle validation errors" do
63
+ begin
64
+ Caren::Api.get @error_url
65
+ rescue Caren::Exceptions::ServerSideError => e
66
+ e.errors.should have(1).things
67
+ e.errors.first.class.should == Caren::ValidationError
68
+ e.errors.first.message.should == "has already been taken"
69
+ e.errors.first.field.should == :url_shortcut
70
+ e.errors.first.to_s.should == "`url_shortcut` has already been taken"
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Event", "converting to xml" do
4
+
5
+ before do
6
+ @event_a = Caren::Event.new( :external_id => 1, :name => "Washing", :comment => "Real good", :start => "12:00",
7
+ :duration => 30, :valid_from => Date.today, :valid_to => Date.today+1.day,
8
+ :person_first_name => "Andre", :person_last_name => "Foeken", :person_male => true, :external_person_id => 100 )
9
+
10
+ @event_b = Caren::Event.new( :external_id => 2, :name => "Clothing", :comment => "Real bad",
11
+ :start => "13:00", :duration => 30, :valid_from => Date.today, :valid_to => Date.today+1.day,
12
+ :person_first_name => "Oscar", :person_last_name => "Foeken", :person_male => true, :external_person_id => 101 )
13
+ end
14
+
15
+ it "should be able to convert an event to valid xml" do
16
+ @event_a.should convert_to_valid_caren_xml
17
+ end
18
+
19
+ it "should be able to convert an array of events to valid xml" do
20
+ [@event_a,@event_b].should convert_to_valid_caren_array_xml
21
+ end
22
+
23
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ExternalMessage", "converting to xml" do
4
+
5
+ before do
6
+ @external_message_a = Caren::ExternalMessage.new( :person_name => "Andre Foeken",
7
+ :external_person_id => 1,
8
+ :body => "Test message",
9
+ :external_id => 1,
10
+ :in_reply_to_id => nil )
11
+
12
+ @external_message_b = Caren::ExternalMessage.new( :person_name => "Ria Foeken",
13
+ :external_person_id => 2,
14
+ :body => "Test message reply",
15
+ :external_id => 2,
16
+ :in_reply_to_id => 99 )
17
+ end
18
+
19
+ it "should be able to convert a link to valid xml" do
20
+ @external_message_a.should convert_to_valid_caren_xml
21
+ end
22
+
23
+ it "should be able to convert an array of links to valid xml" do
24
+ [@external_message_a,@external_message_b].should convert_to_valid_caren_array_xml
25
+ end
26
+
27
+ end
28
+
29
+ describe "ExternalMessage", "REST methods" do
30
+
31
+ before do
32
+ FakeWeb.register_uri(:post, Caren::ExternalMessage.resource_url(1), :status => 201, :signature => Caren::Api.sign )
33
+ FakeWeb.register_uri(:delete, Caren::ExternalMessage.resource_url(1,1), :signature => Caren::Api.sign )
34
+ end
35
+
36
+ it "should be able to create an external message" do
37
+ lambda{ Caren::ExternalMessage.new( :person_name => "Andre Foeken",
38
+ :external_person_id => 1,
39
+ :body => "Test message",
40
+ :external_id => 1,
41
+ :subject_id => 1 ).create }.should_not raise_error
42
+ end
43
+
44
+ it "should be able to delete an external message" do
45
+ lambda{ Caren::ExternalMessage.new( :subject_id => 1, :caren_id => 1 ).delete }.should_not raise_error
46
+ end
47
+
48
+ end
Binary file
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <errors type="array">
3
+ <error on="url-shortcut" category="validation">
4
+ has already been taken
5
+ </error>
6
+ </errors>
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <care-providers type="array">
3
+ <care-provider>
4
+ <url-shortcut>demo</url-shortcut>
5
+ <name>Demo</name>
6
+ <created-at type="datetime">2011-10-10T10:38:13+02:00</created-at>
7
+ <address-line></address-line>
8
+ <updated-at type="datetime">2011-10-10T10:38:13+02:00</updated-at>
9
+ <lng type="float">5.29127</lng>
10
+ <id type="integer">1</id>
11
+ <website></website>
12
+ <telephone></telephone>
13
+ <time-zone>Europe/Amsterdam</time-zone>
14
+ <lat type="float">52.1326</lat>
15
+ <email></email>
16
+ <logo></logo>
17
+ <linkable>true</linkable>
18
+ </care-provider>
19
+ <care-provider>
20
+ <url-shortcut>pantein</url-shortcut>
21
+ <name>Pantein</name>
22
+ <created-at type="datetime">2011-10-10T14:19:53+02:00</created-at>
23
+ <address-line></address-line>
24
+ <updated-at type="datetime">2011-10-11T08:58:48+02:00</updated-at>
25
+ <lng type="float">5.29127</lng>
26
+ <id type="integer">2</id>
27
+ <website></website>
28
+ <telephone></telephone>
29
+ <time-zone>Europe/Amsterdam</time-zone>
30
+ <lat type="float">52.1326</lat>
31
+ <email></email>
32
+ <logo></logo>
33
+ <linkable>true</linkable>
34
+ </care-provider>
35
+ </care-providers>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <care-providers type="array">
3
+ <care-provider>
4
+ <url-shortcut>pantein</url-shortcut>
5
+ <name>Pantein</name>
6
+ <created-at type="datetime">2011-10-10T14:19:53+02:00</created-at>
7
+ <address-line></address-line>
8
+ <updated-at type="datetime">2011-10-11T08:58:48+02:00</updated-at>
9
+ <lng type="float">5.29127</lng>
10
+ <id type="integer">2</id>
11
+ <website></website>
12
+ <telephone></telephone>
13
+ <time-zone>Europe/Amsterdam</time-zone>
14
+ <lat type="float">52.1326</lat>
15
+ <email></email>
16
+ <logo></logo>
17
+ <linkable>true</linkable>
18
+ </care-provider>
19
+ </care-providers>
@@ -0,0 +1,36 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <links type="array">
3
+ <link>
4
+ <created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
5
+ <updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
6
+ <id type="integer">1</id>
7
+ <care-provider-id type="integer">1</care-provider-id>
8
+ <person-id type="integer">3</person-id>
9
+ <person-name>Andre Foeken</person-name>
10
+ <person-photo>http://example.com/1.png</person-photo>
11
+ <external-id>1</external-id>
12
+ <status>confirmed</status>
13
+ </link>
14
+ <link>
15
+ <created-at type="datetime">2011-10-10T10:42:42+02:00</created-at>
16
+ <updated-at type="datetime">2011-10-10T10:53:07+02:00</updated-at>
17
+ <id type="integer">2</id>
18
+ <care-provider-id type="integer">1</care-provider-id>
19
+ <person-id type="integer">3</person-id>
20
+ <person-name>Andre Foeken</person-name>
21
+ <person-photo>http://example.com/1.png</person-photo>
22
+ <external-id>2</external-id>
23
+ <status>confirmed</status>
24
+ </link>
25
+ <link>
26
+ <created-at type="datetime">2011-10-10T11:05:28+02:00</created-at>
27
+ <updated-at type="datetime">2011-10-10T11:06:44+02:00</updated-at>
28
+ <id type="integer">3</id>
29
+ <care-provider-id type="integer">1</care-provider-id>
30
+ <person-id type="integer">3</person-id>
31
+ <person-name>Andre Foeken</person-name>
32
+ <person-photo>http://example.com/1.png</person-photo>
33
+ <external-id>3</external-id>
34
+ <status>confirmed</status>
35
+ </link>
36
+ </links>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <links type="array">
3
+ <link>
4
+ <created-at type="datetime">2011-10-10T10:38:49+02:00</created-at>
5
+ <updated-at type="datetime">2011-10-10T10:40:35+02:00</updated-at>
6
+ <id type="integer">1</id>
7
+ <care-provider-id type="integer">1</care-provider-id>
8
+ <person-id type="integer">3</person-id>
9
+ <person-name>Andre Foeken</person-name>
10
+ <person-photo>http://example.com/1.png</person-photo>
11
+ <external-id>1</external-id>
12
+ <status>confirmed</status>
13
+ </link>
14
+ </links>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <errors type="array">
3
+ <error category="unauthorized">
4
+ You are not allowed to perform this action.
5
+ </error>
6
+ </errors>
data/spec/link_spec.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Link", "converting to xml" do
4
+
5
+ before do
6
+ @link_a = Caren::Link.new( :patient_number => "12345" )
7
+ @link_b = Caren::Link.new( :patient_number => "67890" )
8
+ end
9
+
10
+ it "should be able to convert a link to valid xml" do
11
+ @link_a.should convert_to_valid_caren_xml
12
+ end
13
+
14
+ it "should be able to convert an array of links to valid xml" do
15
+ [@link_a,@link_b].should convert_to_valid_caren_array_xml
16
+ end
17
+
18
+ end
19
+
20
+ describe "Link", "REST methods" do
21
+
22
+ before do
23
+ links = File.read("spec/fixtures/caren_links.xml")
24
+ search = File.read("spec/fixtures/caren_links_search.xml")
25
+ FakeWeb.register_uri(:get, Caren::Link.resource_url, :body => links, :signature => Caren::Api.sign(links) )
26
+ FakeWeb.register_uri(:get, "#{Caren::Link.resource_url}?key=external-id&value=1", :body => search, :signature => Caren::Api.sign(search) )
27
+ FakeWeb.register_uri(:post, Caren::Link.resource_url, :status => 201, :signature => Caren::Api.sign )
28
+ end
29
+
30
+ it "should be able to create a new link using the API" do
31
+ lambda{ Caren::Link.new( :patient_number => "12345" ).create }.should_not raise_error
32
+ end
33
+
34
+ it "should be find all links using the API" do
35
+ links = Caren::Link.all
36
+ links.should have(3).things
37
+ links.first.status.should == "confirmed"
38
+ links.first.external_id.should == "1"
39
+ links.first.person_name.should == "Andre Foeken"
40
+ links.first.person_id.should == 3
41
+ end
42
+
43
+ it "should be find a specific link using the API" do
44
+ links = Caren::Link.search(:external_id, 1)
45
+ links.should have(1).thing
46
+ end
47
+
48
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Person", "converting to xml" do
4
+
5
+ before do
6
+ @person_a = Caren::Person.new( :external_id => 1,
7
+ :uid => "ABC123",
8
+ :first_name => "Andre",
9
+ :last_name => "Foeken",
10
+ :male => true,
11
+ :date_of_birth => 80.years.ago.to_date,
12
+ :address_street => "Sesamestreet 1",
13
+ :address_zipcode => "7500AA",
14
+ :address_city => "Groenlo",
15
+ :address_country => "The Netherlands" )
16
+
17
+ @person_b = Caren::Person.new( :external_id => 2,
18
+ :uid => "ABC456",
19
+ :first_name => "Oscar",
20
+ :last_name => "Foeken",
21
+ :male => true,
22
+ :date_of_birth => 80.years.ago.to_date,
23
+ :address_street => "Sesamestreet 1",
24
+ :address_zipcode => "7500AA",
25
+ :address_city => "Groenlo",
26
+ :address_country => "The Netherlands" )
27
+ end
28
+
29
+ it "should be able to convert a person to valid xml" do
30
+ @person_a.should convert_to_valid_caren_xml
31
+ end
32
+
33
+ it "should be able to convert an array of people to valid xml" do
34
+ [@person_a,@person_b].should convert_to_valid_caren_array_xml
35
+ end
36
+
37
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'caren-api'
5
+ require 'rspec'
6
+ require 'fakeweb'
7
+ require 'capybara'
8
+
9
+ Caren::Api.shared_key = "specs"
10
+ Caren::Api.url = "http://example.com"
11
+
12
+ FakeWeb.allow_net_connect = false
13
+
14
+ RSpec::Matchers.define :convert_to_valid_caren_xml do
15
+ match do |instance|
16
+ hash = Hash.from_xml(instance.to_xml)
17
+ keys = instance.as_xml.keys.map(&:to_s)
18
+ (hash[instance.class.node_root.to_s].keys - keys).should be_empty
19
+ keys.map{ |key| hash[instance.class.node_root.to_s][key].to_s == instance.send(key.to_sym).to_s }.inject(&:&)
20
+ end
21
+ end
22
+
23
+ RSpec::Matchers.define :convert_to_valid_caren_array_xml do
24
+ match do |array|
25
+ hash = Hash.from_xml( array.first.class.to_xml(array) )
26
+ hash.keys.should eql [array.first.class.array_root.to_s]
27
+ array.each do |obj|
28
+ obj.should convert_to_valid_caren_xml
29
+ end
30
+ end
31
+ end
32
+
33
+ RSpec.configure do |config|
34
+
35
+ end