Permalink
Browse files

fully fixed contacts spec

  • Loading branch information...
1 parent 29af077 commit 571121298ff2cbba8dc206b367aed3f5a45c4183 Danny committed May 29, 2012
Showing with 27 additions and 12 deletions.
  1. +27 −12 spec/lib/api_operations/contacts_spec.rb
@@ -11,12 +11,10 @@
ApiOperations::Common.empty_hr_parties @user_map
end
-
it "should create a new Highrise person for a new Ringio contact" do
# initial empty synchronization
ApiOperations::Common.complete_synchronization
-
- rg_contact = Factory.create(:ringio_contact)
+ rg_contact = create_contact
previous_cm_count = ContactMap.count
ApiOperations::Common.complete_synchronization
assert_equal previous_cm_count + 1, ContactMap.count
@@ -50,9 +48,8 @@
end
end
-
it "in the initial synchronization should create a new Highrise person for a new Ringio contact" do
- rg_contact = Factory.create(:ringio_contact)
+ rg_contact = create_contact
previous_cm_count = ContactMap.count
ApiOperations::Common.complete_synchronization
assert_equal previous_cm_count + 1, ContactMap.count
@@ -86,23 +83,28 @@
end
end
-
it "should update a Highrise person for an edited Ringio contact" do
# initial empty synchronization
ApiOperations::Common.complete_synchronization
- rg_contact = Factory.create(:ringio_contact)
+ rg_contact = create_contact
previous_cm_count = ContactMap.count
ApiOperations::Common.complete_synchronization
assert_equal previous_cm_count + 1, ContactMap.count
# edit the title as it is a simple change, and use a new variable so as not to modify the initial values
+
+
+ oldToken = RingioAPI::Base.user
+ RingioAPI::Base.user = ApiOperations::TestingInfo::RINGIO_TEST_TOKEN
aux_rg_contact = RingioAPI::Contact.find rg_contact.id
aux_rg_contact.title = 'Edited title'
+
aux_rg_contact.save
- ApiOperations::Common.complete_synchronization
+ RingioAPI::Base.user = oldToken
+ ApiOperations::Common.complete_synchronization
cm = ContactMap.find_by_rg_contact_id(rg_contact.id)
assert_not_nil cm
@@ -137,7 +139,7 @@
# initial empty synchronization
ApiOperations::Common.complete_synchronization
- rg_contact = Factory.create(:ringio_contact)
+ rg_contact = create_contact
previous_cm_count = ContactMap.count
ApiOperations::Common.complete_synchronization
assert_equal previous_cm_count + 1, ContactMap.count
@@ -152,7 +154,13 @@
ApiOperations::Common.empty_hr_base
# delete the Ringio contact
- (RingioAPI::Contact.find rg_contact.id).destroy
+ rg_to_delete = RingioAPI::Contact.find rg_contact.id
+ oldToken = RingioAPI::Base.user
+ RingioAPI::Base.user = ApiOperations::TestingInfo::RINGIO_TEST_TOKEN
+ rg_to_delete.save
+
+ rg_to_delete.destroy
+ RingioAPI::Base.user = oldToken
ApiOperations::Common.complete_synchronization
assert_equal previous_cm_count, ContactMap.count
@@ -167,7 +175,6 @@
end
end
-
it "should create a new Ringio contact for a new Highrise person" do
# initial empty synchronization
ApiOperations::Common.complete_synchronization
@@ -358,7 +365,15 @@
@account.destroy
end
-
+ def create_contact
+ oldToken = RingioAPI::Base.user
+ RingioAPI::Base.user = ApiOperations::TestingInfo::RINGIO_TEST_TOKEN
+ @account.save()
+ rg_contact = Factory.create(:ringio_contact)
+ RingioAPI::Base.user = oldToken
+ rg_contact
+ end
+
def create_full_hr_person
# we need this method because the factory cannot save in the middle of the process to get the ContactData structure
hr_person = Factory.create(:highrise_person)

0 comments on commit 5711212

Please sign in to comment.