Skip to content
Browse files

Moved API operations to their proper place in /lib. Started rspec inf…

…rastructure.
  • Loading branch information...
1 parent 68d3e94 commit c48bf64d91289ca721d860fcc45bfff83bb30ee5 @amartinfraguas amartinfraguas committed Jan 3, 2011
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
1 Gemfile
@@ -28,6 +28,7 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
group :development, :test do
# gem 'webrat'
gem 'ruby-debug19', :require => 'ruby-debug'
+ gem "rspec-rails", ">= 2.4.1"
end
gem 'ringioAPI'
View
23 Gemfile.lock
@@ -32,24 +32,25 @@ GEM
arel (2.0.6)
builder (2.1.2)
columnize (0.3.2)
+ diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
highrise (3.0.0)
activeresource (~> 3.0.0)
- i18n (0.4.2)
+ i18n (0.5.0)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
- mail (2.2.10)
+ mail (2.2.13)
activesupport (>= 2.3.6)
- i18n (~> 0.4.1)
+ i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack (>= 1.0.0)
- rack-test (0.5.6)
+ rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.3)
actionmailer (= 3.0.3)
@@ -67,6 +68,19 @@ GEM
rake (0.8.7)
ringioAPI (0.0.9)
activeresource (>= 3.0.3)
+ rspec (2.4.0)
+ rspec-core (~> 2.4.0)
+ rspec-expectations (~> 2.4.0)
+ rspec-mocks (~> 2.4.0)
+ rspec-core (2.4.0)
+ rspec-expectations (2.4.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.4.0)
+ rspec-rails (2.4.1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.4.0)
ruby-debug-base19 (0.11.24)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
@@ -90,5 +104,6 @@ DEPENDENCIES
highrise
rails (= 3.0.3)
ringioAPI
+ rspec-rails (>= 2.4.1)
ruby-debug19
sqlite3-ruby
View
2 config/application.rb
@@ -14,6 +14,8 @@ class Application < Rails::Application
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
+ config.autoload_paths += %W(#{config.root}/lib)
+ config.autoload_paths += Dir["#{config.root}/lib/api_operations/"]
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
View
7 app/models/api_operations/common.rb → lib/api_operations/common.rb
@@ -108,7 +108,8 @@ def self.log(level,exception,message)
private
-
+
+
def self.synchronize_account(account, new_user_maps, account_not_synchronized_yet)
# we synchronize in reverse order of resource dependency: first contacts, then notes and then rings
ApiOperations::Contacts.synchronize_account(account,new_user_maps, account_not_synchronized_yet)
@@ -117,7 +118,8 @@ def self.synchronize_account(account, new_user_maps, account_not_synchronized_ye
ApiOperations::Rings.synchronize_account(account,new_user_maps, account_not_synchronized_yet)
end
-
+
+
def self.set_hr_base_basic(user_map)
if user_map
Highrise::Base.site = 'https://' + user_map.account.hr_subdomain + '.highrisehq.com'
@@ -127,6 +129,7 @@ def self.set_hr_base_basic(user_map)
self.empty_hr_base_basic
end
end
+
def self.empty_hr_base_basic
Highrise::Base.site = ''
View
40 app/models/api_operations/contacts.rb → lib/api_operations/contacts.rb
@@ -265,7 +265,7 @@ def self.hr_party_to_rg_contact(hr_party, rg_contact)
end
end
end
-
+debugger
# TODO: refactor to move repeated structures to a method
if hr_party.contact_data.present?
# set the email addresses
@@ -281,7 +281,7 @@ def self.hr_party_to_rg_contact(hr_party, rg_contact)
end
cd.type = 'email'
end
-debugger
+
# set the phone numbers
hr_party.contact_data.phone_numbers.each do |pn|
rg_contact.data << (cd = RingioAPI::Contact::Datum.new)
@@ -376,21 +376,11 @@ def self.update_rg_to_hr(user_map, user_rg_feed)
ApiOperations::Common.log(:debug,nil,"Started applying update from Ringio to Highrise of the contact with Ringio id = " + rg_contact.id.to_s)
begin
- new_hr_party = nil
- # if the contact was already mapped to Highrise, update it there
- if (cm = ContactMap.find_by_rg_contact_id(rg_contact.id))
- hr_party = cm.hr_resource_party
- self.rg_contact_to_hr_party(rg_contact,hr_party)
- new_hr_party = false
- else
- # if the contact is new, create it in Highrise (always as a Person, Ringio GUI does not allow creating a Company) and map it
- hr_party = Highrise::Person.new
- self.rg_contact_to_hr_party(rg_contact,hr_party)
- new_hr_party = true
- end
-
+ is_new_hr_party = nil
+ hr_party = self.prepare_hr_party(rg_contact,is_new_hr_party)
+
# if the Highrise party is saved properly and it didn't exist before, create a new contact map
- if hr_party.save! && new_hr_party
+ if hr_party.save! && is_new_hr_party
new_cm = ContactMap.new(:user_map_id => user_map.id, :rg_contact_id => rg_contact.id, :hr_party_id => hr_party.id)
new_cm.hr_party_type = case hr_party
when Highrise::Person then 'Person'
@@ -407,6 +397,22 @@ def self.update_rg_to_hr(user_map, user_rg_feed)
end
end
end
+
+
+ def self.prepare_hr_party(rg_contact, is_new_hr_party)
+ # if the contact was already mapped to Highrise, update it there
+ if (cm = ContactMap.find_by_rg_contact_id(rg_contact.id))
+ hr_party = cm.hr_resource_party
+ self.rg_contact_to_hr_party(rg_contact,hr_party)
+ is_new_hr_party = false
+ else
+ # if the contact is new, create it in Highrise (always as a Person, Ringio GUI does not allow creating a Company) and map it
+ hr_party = Highrise::Person.new
+ self.rg_contact_to_hr_party(rg_contact,hr_party)
+ is_new_hr_party = true
+ end
+ hr_party
+ end
def self.delete_rg_to_hr(user_map, rg_deleted_contacts_ids)
@@ -473,7 +479,7 @@ def self.set_anonymous_person_in_hr(hr_person)
def self.rg_contact_to_hr_party(rg_contact, hr_party)
-
+ # the author of the Highrise party is set by Highrise as the current authenticated user
case hr_party
when Highrise::Person
if rg_contact.name.present?
View
0 app/models/api_operations/hashing.rb → lib/api_operations/hashing.rb
File renamed without changes.
View
0 app/models/api_operations/notes.rb → lib/api_operations/notes.rb
File renamed without changes.
View
0 app/models/api_operations/rings.rb → lib/api_operations/rings.rb
File renamed without changes.
View
0 app/models/api_operations/session.rb → lib/api_operations/session.rb
File renamed without changes.
View
15 lib/tasks/synchronization.rake
@@ -16,25 +16,18 @@ end
desc "Synchronize all resources between Ringio and Highrise CRM - version for debugging"
task :synchronize_all_debugging => :environment do
- # store the previous logger configuration
+ # get the previous logger configuration
previous_level = Rails.logger.level
previous_flushing = Rails.logger.auto_flushing
# set the logger properly for debugging
Rails.logger.level = 0
Rails.logger.auto_flushing = true
- ApiOperations::Common.log(:info,nil,"Started complete synchronization event")
-
- begin
- ApiOperations::Common.complete_synchronization
- rescue Exception => e
- ApiOperations::Common.log(:error,e,"\nProblem with the initializing of the synchronization")
- end
-
- ApiOperations::Common.log(:info,nil,"Finished complete synchronization event\n")
+ # run the synchronization
+ Rake::Task['synchronize_all'].invoke
# restore the previous logger configuration
Rails.logger.level = previous_level
Rails.logger.auto_flushing = previous_flushing
-end
+end
View
18 spec/lib/api_operations/common_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe ApiOperations::Common do
+
+ before(:each) do
+
+ end
+
+ it "should only update timestamps when synchronizing an empty account" do
+ assert_equal 1, 2
+ end
+
+ after(:each) do
+ #remove all the stuff created
+
+ end
+
+end
View
27 spec/spec_helper.rb
@@ -0,0 +1,27 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+end

0 comments on commit c48bf64

Please sign in to comment.
Something went wrong with that request. Please try again.