Permalink
Browse files

gemfile updates, remove path pushing in favor of explicit inclusion, …

…remove traces of auto_migrate, introduce custom types to ease intercepting BS between the adapter and model layer, test review to think about more than just EY's need.
  • Loading branch information...
1 parent ab9f71b commit f3f87a61ef7f4745bf1440c1ab1750ace7fccdee @ultraninja ultraninja committed Nov 3, 2009
View
18 Gemfile
@@ -3,19 +3,23 @@ source 'http://gems.rubyforge.org'
bin_path 'gbin'
disable_system_gems
+gem "httpclient", "=2.1.5.2"
+gem "extlib", "~> 0.9.9"
+gem "dm-core", "~> 0.10.1"
+gem "dm-validations", "~> 0.10.1"
+gem "dm-types", "~> 0.10.1"
+gem "do_sqlite3", "~> 0.10.0"
+gem "soap4r", "~> 1.5.8", :require_as => [ ]
+
only :test do
gem 'rspec', :require_as => %w(spec)
gem 'rake'
gem 'rcov'
gem 'ruby-debug'
gem 'bundler', '~>0.6.0'
+ gem 'ParseTree', :require_as => 'parse_tree'
+ gem 'dm-sweatshop'
+ gem 'dm-migrations'
end
-gem "httpclient", "=2.1.5.2"
-gem "extlib", "~> 0.9.9"
-gem "dm-core", "~> 0.10.1"
-gem "dm-validations", "~> 0.10.1"
-gem "do_sqlite3", "~> 0.10.0"
-gem "soap4r", "~> 1.5.8", :require_as => [ ]
-
# vim:ft=ruby
View
@@ -1,12 +1,22 @@
-$:.push File.expand_path(File.dirname(__FILE__))
-
+require "fileutils"
require 'dm-core'
require 'dm-validations'
-require 'dm-salesforce/sql'
-require 'dm-salesforce/extensions'
-require 'dm-salesforce/adapter'
-require 'dm-salesforce/connection'
-require 'dm-salesforce/version'
+require 'soap/wsdlDriver'
+require 'soap/header/simplehandler'
+require "rexml/element"
+
+dir = File.expand_path(File.join(File.dirname(__FILE__), 'dm-salesforce'))
+
+require dir / :extensions
+require dir / :resource
+require dir / :connection
+require dir / :connection / :errors
+require dir / :soap_wrapper
+require dir / :sql
+require dir / :types
+require dir / :version
+
+require dir / :adapter
DataMapper::Adapters::SalesforceAdapter = DataMapperSalesforce::Adapter
@@ -95,21 +95,6 @@ def populate_errors_for(records, resources, collection = nil)
end
end
- # A dummy method to allow migrations without upsetting any data
- def destroy_model_storage(*args)
- true
- end
-
- # A dummy method to allow auto_migrate! to run
- def upgrade_model_storage(*args)
- true
- end
-
- # A dummy method to allow migrations without upsetting any data
- def create_model_storage(*args)
- true
- end
-
# Reading responses back from SELECTS:
# In the typical case, response.size reflects the # of records returned.
# In the aggregation case, response.size reflects the count.
@@ -1,8 +1,3 @@
-require 'soap/wsdlDriver'
-require 'soap/header/simplehandler'
-require "rexml/element"
-require 'dm-salesforce/soap_wrapper'
-
module DataMapperSalesforce
class Connection
class HeaderHandler < SOAP::Header::SimpleHandler
@@ -141,5 +136,3 @@ def with_reconnection(&block)
end
end
end
-
-require 'dm-salesforce/connection/errors'
@@ -0,0 +1,10 @@
+module DataMapper
+ module SalesForce
+ module Resource
+ def self.included(model)
+ model.send :include, DataMapper::Resource
+ model.send :include, DataMapper::SalesForce::Types
+ end
+ end
+ end
+end
@@ -1,5 +1,3 @@
-require "fileutils"
-
module DataMapperSalesforce
class SoapWrapper
class ClassesFailedToGenerate < StandardError; end
View
@@ -0,0 +1,14 @@
+module DataMapper::SalesForce
+ class Type < ::DataMapper::Type
+ end
+
+ module Types
+ end
+end
+
+dir = File.expand_path(File.dirname(__FILE__) / :types)
+
+require dir / :serial
+require dir / :boolean
+require dir / :integer
+require dir / :float
@@ -0,0 +1,19 @@
+module DataMapper::SalesForce
+ module Types
+ class Boolean < Type
+ primitive ::String
+ default false
+
+ def self.dump(value, property)
+ value.nil? ? '0' : value
+ end
+
+ def self.load(value, property)
+ case value
+ when TrueClass then value
+ when String then value == '1' || value == 'true'
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,12 @@
+module DataMapper::SalesForce
+ module Types
+ class Float < Type
+ primitive ::Float
+ default 0.0
+
+ def self.load(value, property)
+ value || default
+ end
+ end
+ end
+end
@@ -0,0 +1,12 @@
+module DataMapper::SalesForce
+ module Types
+ class Integer < Type
+ primitive ::Integer
+ default 0
+
+ def self.load(value, property)
+ Integer(value)
+ end
+ end
+ end
+end
@@ -0,0 +1,14 @@
+module DataMapper::SalesForce
+ module Types
+ class Serial < Type
+ primitive ::String
+ min 15
+ max 15
+ serial true
+
+ def self.dump(value, property)
+ value[0..14] unless value.blank?
+ end
+ end
+ end
+end
@@ -1,14 +0,0 @@
-module DataMapperSalesforce
- describe "Running auto_migrate!" do
- it "should not raise errors" do
- pending "not implemented in 0.10.x?"
- lambda { DataMapper.auto_migrate! }.should_not raise_error
- end
- end
- describe "Running auto_upgrade!" do
- it "should not raise errors" do
- pending "not implemented in 0.10.x?"
- lambda { DataMapper.auto_upgrade! }.should_not raise_error
- end
- end
-end
@@ -20,14 +20,15 @@ module DataMapperSalesforce
describe "when authenticating with an organization id" do
describe "with the correct self service credentials" do
it "succeeds" do
- pending
+ pending "self service is no longer supported"
db = DataMapper.repository(:salesforce).adapter.connection
Connection.new(VALID_SELF_SERVICE_USER.username, VALID_SELF_SERVICE_USER.password, db.wsdl_path, db.api_dir, db.organization_id)
end
end
describe "with an invalid password" do
it "fails to login" do
+ pending "self service is no longer supported"
db = DataMapper.repository(:salesforce).adapter.connection
lambda { Connection.new(VALID_SELF_SERVICE_USER.username, "bad-password", db.wsdl_path, db.api_dir, db.organization_id) }.
should raise_error(Connection::LoginFailed)
View
@@ -1,6 +1,6 @@
class Account
- include DataMapper::Resource
-
+ include DataMapper::SalesForce::Resource
+
def self.default_repository_name
:salesforce
end
@@ -9,6 +9,16 @@ def self.salesforce_id_properties
:id
end
- property :id, String, :serial => true
- property :name, String
+ property :id, Serial
+ property :name, String, :nullable => false
+ property :active, Boolean, :field => 'Active_L_C__c'
+ property :annual_revenue, Float
+ property :number_of_employees, Integer
end
+
+Account.fix {{
+ :name => Randgen.first_name,
+ :active => true,
+ :annual_revenue => rand(1_000).to_f / 100,
+ :number_of_employees => (1..10).pick,
+}}
View
@@ -1,5 +1,5 @@
class Contact
- include DataMapper::Resource
+ include DataMapper::SalesForce::Resource
def self.default_repository_name
:salesforce
@@ -9,11 +9,21 @@ def self.salesforce_id_properties
[:id, :account_id]
end
- property :id, String, :serial => true
- property :first_name, String
- property :last_name, String
- property :email, String
- property :account_id, String
+ property :id, Serial
+ property :first_name, String
+ property :last_name, String, :nullable => false
+ property :email, String, :format => :email_address
+ property :account_id, String
+ property :irc_nick, String, :nullable => true, :unique => true
+ property :has_opted_out_of_email, Boolean
belongs_to :account
end
+
+Contact.fix {{
+ :first_name => /\w+/.gen,
+ :last_name => /\w+/.gen,
+ :email => /\w+@example.com/.gen,
+ :account => Account.gen,
+ :has_opted_out_of_email => [true, false].pick,
+}}
@@ -1,13 +1,48 @@
describe "Account" do
- it "return the first element" do
- Account.first.should_not be_nil
+ describe "#first" do
+ #pending "testing first should not be on account"
+ it "return the first element" do
+ Account.first.should_not be_nil
+ end
+ it "has a 15 character long id" do
+ Account.first.id.size.should == 15
+ end
end
- it "has a 15 character long id" do
- Account.first.id.size.should == 15
+ describe ".get" do
+ let(:account_id) { DataMapper.repository(:salesforce) { Account.create(:name => "Adidas Corp").id } }
+
+ it "with a valid id is successfull" do
+ Account.get(account_id).should be_valid
+ end
end
- it "has a 15 character long id" do
- Account.create(:name => "Adidas Corporation").id.size.should == 15
+ describe "#create" do
+ it "has errors when omitting the account name" do
+ a = Account.create(:active => false)
+ a.errors.should have_key(:name)
+ end
+ describe "successful creation" do
+ let(:account) { Account.create(:name => "Adidas Corporation") }
+ it "has a 15 character long id" do
+ account.id.size.should == 15
+ end
+ it 'is not active by default' do
+ account.active.should_not be_true
+ end
+
+ it 'has no annual revenue by default' do
+ account.annual_revenue.should eql(0.0)
+ end
+ end
+ describe "successful creation with on-offs" do
+ let(:account) { Account.create(:name => "Adidas Corporation", :active => true, :annual_revenue => 4000.25) }
+ it 'is active' do
+ account.active.should be_true
+ end
+ it 'has 4000.25 in annual revenue' do
+ account.annual_revenue.should eql(4000.25)
+ end
+ end
end
end
Oops, something went wrong.

0 comments on commit f3f87a6

Please sign in to comment.