activesalesforce 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/activesalesforce.rb +13 -19
- data/lib/asf_adapter.rb +46 -30
- data/lib/column_definition.rb +13 -19
- data/lib/mock_binding.rb +13 -19
- data/lib/relationship_definition.rb +13 -19
- data/lib/rforce.rb +12 -9
- data/test/unit/basic_test.rb +41 -1
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_batch_insert.recording +1176 -0
- data/test/unit/recorded_test_case.rb +16 -22
- metadata +3 -2
data/lib/activesalesforce.rb
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
=begin
|
2
2
|
ActiveSalesforce
|
3
|
-
Copyright
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
3
|
+
Copyright 2006 Doug Chasman
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
22
16
|
=end
|
23
17
|
|
24
18
|
require 'asf_adapter'
|
data/lib/asf_adapter.rb
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
=begin
|
2
2
|
ActiveSalesforce
|
3
|
-
Copyright
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
3
|
+
Copyright 2006 Doug Chasman
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
22
16
|
=end
|
23
17
|
|
24
18
|
require 'rubygems'
|
@@ -189,12 +183,31 @@ module ActiveRecord
|
|
189
183
|
end
|
190
184
|
|
191
185
|
|
186
|
+
# TRANSACTIOn SUPPORT (Boxcarring really because the salesforce.com api does not support transactions)
|
187
|
+
|
188
|
+
# Begins the transaction (and turns off auto-committing).
|
189
|
+
def begin_db_transaction()
|
190
|
+
log('Opening boxcar', 'begin_db_transaction()')
|
191
|
+
end
|
192
|
+
|
193
|
+
# Commits the transaction (and turns on auto-committing).
|
194
|
+
def commit_db_transaction()
|
195
|
+
log('Committing boxcar', 'commit_db_transaction()')
|
196
|
+
end
|
197
|
+
|
198
|
+
# Rolls back the transaction (and turns on auto-committing). Must be
|
199
|
+
# done if the transaction block raises an exception or returns false.
|
200
|
+
def rollback_db_transaction()
|
201
|
+
log('Rolling back boxcar', 'rollback_db_transaction()')
|
202
|
+
end
|
203
|
+
|
204
|
+
|
192
205
|
# DATABASE STATEMENTS ======================================
|
193
206
|
|
194
207
|
def select_all(sql, name = nil) #:nodoc:
|
195
208
|
log(sql, name) {
|
196
209
|
# Check for SELECT COUNT(*) FROM query
|
197
|
-
selectCountMatch = sql.match(/SELECT
|
210
|
+
selectCountMatch = sql.match(/SELECT\s+COUNT\(\*\)\s+FROM/i)
|
198
211
|
if selectCountMatch
|
199
212
|
soql = "SELECT id FROM#{selectCountMatch.post_match}"
|
200
213
|
end
|
@@ -209,21 +222,24 @@ module ActiveRecord
|
|
209
222
|
# Always (unless COUNT*)'ing) select all columns (required for the AR attributes mechanism to work correctly
|
210
223
|
soql = sql.sub(/SELECT .+ FROM/i, "SELECT #{column_names.join(', ')} FROM") unless selectCountMatch
|
211
224
|
|
212
|
-
soql.sub!(
|
225
|
+
soql.sub!(/\s+FROM\s+\w+/i, " FROM #{entity_def.api_name}")
|
213
226
|
|
214
227
|
# Look for a LIMIT clause
|
215
|
-
soql.sub!(/LIMIT
|
228
|
+
soql.sub!(/LIMIT\s+1/i, "")
|
216
229
|
|
217
230
|
# Look for an OFFSET clause
|
218
|
-
soql.sub!(/\d+
|
231
|
+
soql.sub!(/\d+\s+OFFSET\s+\d+/i, "")
|
219
232
|
|
220
233
|
# Fixup column references to use api names
|
221
234
|
columns = columns_map(table_name)
|
222
|
-
|
223
|
-
|
235
|
+
soql.gsub!(/((?:\w+\.)?\w+)(?=\s*(?:=|!=|<|>|<=|>=)\s*(?:'[^']*'|NULL|TRUE|FALSE))/mi) do |column_name|
|
236
|
+
# strip away any table alias
|
237
|
+
column_name.sub!(/\w+\./, '')
|
224
238
|
|
225
239
|
column = columns[column_name]
|
226
|
-
|
240
|
+
raise SalesforceError.new(@logger, "Column not found for #{column_name}!") unless column
|
241
|
+
|
242
|
+
column.api_name
|
227
243
|
end
|
228
244
|
|
229
245
|
# Update table name references
|
@@ -283,12 +299,12 @@ module ActiveRecord
|
|
283
299
|
def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
|
284
300
|
log(sql, name) {
|
285
301
|
# Convert sql to sobject
|
286
|
-
table_name = sql.match(/INSERT
|
302
|
+
table_name = sql.match(/INSERT\s+INTO\s+(\w+)\s+/i)[1].singularize
|
287
303
|
entity_name = entity_name_from_table(table_name)
|
288
304
|
columns = columns_map(table_name)
|
289
305
|
|
290
306
|
# Extract array of column names
|
291
|
-
names = sql.match(/\((.+)\)
|
307
|
+
names = sql.match(/\((.+)\)\s+VALUES/i)[1].scan(/\w+/i)
|
292
308
|
|
293
309
|
# Extract arrays of values
|
294
310
|
values = sql.match(/VALUES\s*\((.+)\)/i)[1]
|
@@ -308,7 +324,7 @@ module ActiveRecord
|
|
308
324
|
def update(sql, name = nil) #:nodoc:
|
309
325
|
log(sql, name) {
|
310
326
|
# Convert sql to sobject
|
311
|
-
table_name = sql.match(/UPDATE
|
327
|
+
table_name = sql.match(/UPDATE\s+(\w+)\s+/i)[1].singularize
|
312
328
|
entity_name = entity_name_from_table(table_name)
|
313
329
|
columns = columns_map(table_name)
|
314
330
|
|
@@ -499,7 +515,7 @@ module ActiveRecord
|
|
499
515
|
klass.belongs_to referenceName.to_sym, :class_name => reference_to, :foreign_key => foreign_key, :dependent => false
|
500
516
|
end
|
501
517
|
|
502
|
-
|
518
|
+
#@logger.debug(" Created one-to-#{one_to_many ? 'many' : 'one' } relationship '#{referenceName}' from #{entity_name} to #{relationship.reference_to} using #{foreign_key}")
|
503
519
|
|
504
520
|
end
|
505
521
|
end
|
data/lib/column_definition.rb
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
=begin
|
2
2
|
ActiveSalesforce
|
3
|
-
Copyright
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
3
|
+
Copyright 2006 Doug Chasman
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
22
16
|
=end
|
23
17
|
|
24
18
|
require 'rubygems'
|
data/lib/mock_binding.rb
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
=begin
|
2
2
|
ActiveSalesforce
|
3
|
-
Copyright
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
3
|
+
Copyright 2006 Doug Chasman
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
22
16
|
=end
|
23
17
|
|
24
18
|
require 'yaml'
|
@@ -1,24 +1,18 @@
|
|
1
1
|
=begin
|
2
2
|
ActiveSalesforce
|
3
|
-
Copyright
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
3
|
+
Copyright 2006 Doug Chasman
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
22
16
|
=end
|
23
17
|
|
24
18
|
require 'rubygems'
|
data/lib/rforce.rb
CHANGED
@@ -1,12 +1,3 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'uri'
|
3
|
-
require 'zlib'
|
4
|
-
require 'stringio'
|
5
|
-
require 'rexml/document'
|
6
|
-
require 'rexml/xpath'
|
7
|
-
require 'rubygems'
|
8
|
-
require_gem 'builder'
|
9
|
-
|
10
1
|
=begin
|
11
2
|
RForce v0.1
|
12
3
|
Copyright (c) 2005 Ian Dees
|
@@ -55,6 +46,18 @@ require_gem 'builder'
|
|
55
46
|
#
|
56
47
|
# binding.create 'sObject {"xsi:type" => "Opportunity"}' => opportunity
|
57
48
|
#
|
49
|
+
|
50
|
+
|
51
|
+
require 'net/https'
|
52
|
+
require 'uri'
|
53
|
+
require 'zlib'
|
54
|
+
require 'stringio'
|
55
|
+
require 'rexml/document'
|
56
|
+
require 'rexml/xpath'
|
57
|
+
require 'rubygems'
|
58
|
+
require_gem 'builder'
|
59
|
+
|
60
|
+
|
58
61
|
module RForce
|
59
62
|
|
60
63
|
#Allows indexing hashes like method calls: hash.key
|
data/test/unit/basic_test.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
=begin
|
2
|
+
ActiveSalesforce
|
3
|
+
Copyright 2006 Doug Chasman
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
|
1
18
|
require 'rubygems'
|
2
19
|
|
3
20
|
#require_gem 'activesalesforce', '>= 0.2.6'
|
@@ -25,7 +42,7 @@ module Asf
|
|
25
42
|
def initialize(test_method_name)
|
26
43
|
super(test_method_name)
|
27
44
|
|
28
|
-
#force_recording :
|
45
|
+
#force_recording :test_batch_insert
|
29
46
|
end
|
30
47
|
|
31
48
|
def setup
|
@@ -106,6 +123,29 @@ module Asf
|
|
106
123
|
|
107
124
|
department.destroy
|
108
125
|
end
|
126
|
+
|
127
|
+
def test_batch_insert
|
128
|
+
c1 = Contact.new(:first_name => 'FN1', :last_name => 'LN1')
|
129
|
+
c2 = Contact.new(:first_name => 'FN2', :last_name => 'LN2')
|
130
|
+
|
131
|
+
Contact.transaction(c1, c2) do
|
132
|
+
c1.save
|
133
|
+
c2.save
|
134
|
+
end
|
135
|
+
|
136
|
+
c1.first_name << '_2'
|
137
|
+
c2.first_name << '_2'
|
138
|
+
|
139
|
+
Contact.transaction(c1, c2) do
|
140
|
+
c1.save
|
141
|
+
c2.save
|
142
|
+
end
|
143
|
+
|
144
|
+
Contact.transaction(c1, c2) do
|
145
|
+
c2.destroy
|
146
|
+
c1.destroy
|
147
|
+
end
|
148
|
+
end
|
109
149
|
|
110
150
|
end
|
111
151
|
|