activesalesforce 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/asf_adapter.rb +53 -31
- data/lib/column_definition.rb +3 -2
- data/lib/mock_binding.rb +76 -0
- data/lib/relationship_definition.rb +21 -8
- data/lib/rforce.rb +4 -4
- data/test/unit/basic_test.rb +99 -0
- data/test/unit/config.yml +4 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_add_notes_to_contact.recording +1332 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_count_contacts.recording +1161 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_create_a_contact.recording +1045 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_a_contact.recording +1045 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_a_contact_by_first_name.recording +1099 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_a_contact_by_id.recording +1099 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_get_created_by_from_contact.recording +3019 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_read_all_content_columns.recording +1045 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_save_a_contact.recording +1045 -0
- data/test/unit/recorded_test_case.rb +118 -0
- metadata +16 -3
- data/test/unit/account_test.rb +0 -107
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'mock_binding'
|
3
|
+
|
4
|
+
|
5
|
+
=begin
|
6
|
+
ActiveSalesforce
|
7
|
+
Copyright (c) 2006 Doug Chasman
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
11
|
+
in the Software without restriction, including without limitation the rights
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
14
|
+
furnished to do so, subject to the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
17
|
+
all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25
|
+
SOFTWARE.
|
26
|
+
=end
|
27
|
+
|
28
|
+
require 'set'
|
29
|
+
|
30
|
+
require 'pp'
|
31
|
+
|
32
|
+
|
33
|
+
module Asf
|
34
|
+
module UnitTests
|
35
|
+
|
36
|
+
module RecordedTestCase
|
37
|
+
@@config = YAML.load_file(File.dirname(__FILE__) + '/config.yml').symbolize_keys
|
38
|
+
|
39
|
+
attr_reader :connection
|
40
|
+
|
41
|
+
|
42
|
+
def recording?
|
43
|
+
@recording
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def config
|
48
|
+
@@config
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def initialize(test_method_name)
|
53
|
+
super(test_method_name)
|
54
|
+
|
55
|
+
@force_recording = Set.new
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def force_recording(method)
|
60
|
+
@force_recording.add(method)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def unforce_recording(method)
|
65
|
+
@force_recording.delete(method)
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def setup
|
70
|
+
url = 'https://www.salesforce.com/services/Soap/u/7.0'
|
71
|
+
|
72
|
+
@recording = (((not File.exists?(recording_file_name)) or config[:recording]) or @force_recording.include?(method_name.to_sym))
|
73
|
+
|
74
|
+
@connection = MockBinding.new(url, nil, recording?)
|
75
|
+
|
76
|
+
ActiveRecord::Base.clear_connection_cache!
|
77
|
+
ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
|
78
|
+
ActiveRecord::Base.establish_connection(:adapter => 'activesalesforce', :username => config[:username],
|
79
|
+
:password => config[:password], :binding => connection)
|
80
|
+
|
81
|
+
unless recording?
|
82
|
+
File.open(recording_file_name) do |f|
|
83
|
+
puts "Opening recorded binding #{recording_file_name}"
|
84
|
+
connection.load(f)
|
85
|
+
|
86
|
+
connection.recorded_responses.each do |request, reponse|
|
87
|
+
pp request
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
response = connection.login(config[:username], config[:password])
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def teardown
|
97
|
+
if recording?
|
98
|
+
puts "Saving recorded binding #{recording_file_name}"
|
99
|
+
|
100
|
+
File.open(recording_file_name, "w") do |f|
|
101
|
+
connection.save(f)
|
102
|
+
end
|
103
|
+
|
104
|
+
connection.recorded_responses.each do |request, reponse|
|
105
|
+
pp request
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def recording_file_name
|
112
|
+
File.dirname(__FILE__) + "/recorded_results/#{self.class.name.gsub('::', '')}.#{method_name}.recording"
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activesalesforce
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2006-02-
|
6
|
+
version: 0.2.7
|
7
|
+
date: 2006-02-20 00:00:00 -05:00
|
8
8
|
summary: ActiveSalesforce (ASF) is a Rails connection adapter that provides direct access to Salesforce.com hosted data and metadata via the ActiveRecord model layer. Objects, fields, and relationships are all auto surfaced as active record attributes and rels.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,11 +30,24 @@ authors:
|
|
30
30
|
files:
|
31
31
|
- lib/column_definition.rb
|
32
32
|
- lib/activesalesforce.rb
|
33
|
+
- lib/mock_binding.rb
|
33
34
|
- lib/rforce.rb
|
34
35
|
- lib/asf_adapter.rb
|
35
36
|
- lib/relationship_definition.rb
|
36
37
|
- test/unit
|
37
|
-
- test/unit/
|
38
|
+
- test/unit/recorded_test_case.rb
|
39
|
+
- test/unit/basic_test.rb
|
40
|
+
- test/unit/config.yml
|
41
|
+
- test/unit/recorded_results
|
42
|
+
- test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_a_contact.recording
|
43
|
+
- test/unit/recorded_results/AsfUnitTestsBasicTest.test_read_all_content_columns.recording
|
44
|
+
- test/unit/recorded_results/AsfUnitTestsBasicTest.test_save_a_contact.recording
|
45
|
+
- test/unit/recorded_results/AsfUnitTestsBasicTest.test_add_notes_to_contact.recording
|
46
|
+
- test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_a_contact_by_first_name.recording
|
47
|
+
- test/unit/recorded_results/AsfUnitTestsBasicTest.test_create_a_contact.recording
|
48
|
+
- test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_a_contact_by_id.recording
|
49
|
+
- test/unit/recorded_results/AsfUnitTestsBasicTest.test_count_contacts.recording
|
50
|
+
- test/unit/recorded_results/AsfUnitTestsBasicTest.test_get_created_by_from_contact.recording
|
38
51
|
- README
|
39
52
|
test_files: []
|
40
53
|
|
data/test/unit/account_test.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../../config/boot')
|
2
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
-
|
4
|
-
require 'pp'
|
5
|
-
|
6
|
-
class AccountTest < Test::Unit::TestCase
|
7
|
-
def setup
|
8
|
-
ActiveRecord::Base.allow_concurrency = true
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_create_account
|
12
|
-
dutchCo = Account.new
|
13
|
-
dutchCo.name = "DutchCo"
|
14
|
-
dutchCo.website = "www.dutchco.com"
|
15
|
-
dutchCo.save
|
16
|
-
|
17
|
-
dutchCo2 = Account.new(:name => "DutchCo2", :website => "www.dutchco2.com")
|
18
|
-
dutchCo2.save
|
19
|
-
|
20
|
-
dutchCo3 = Account.create(:name => "DutchCo3", :website => "www.dutchco3.com")
|
21
|
-
|
22
|
-
accounts = Account.create([
|
23
|
-
{ :name => "DutchCo4", :website => "www.dutchco4.com" },
|
24
|
-
{ :name => "DutchCo5", :website => "www.dutchco5.com" }])
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_create_a_contact
|
28
|
-
contact = Contact.find_by_id("0033000000B1LKpAAN")
|
29
|
-
contact.first_name = "DutchieBoy"
|
30
|
-
contact.save
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
def test_create_a_contact
|
35
|
-
contact = Contact.new
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
def test_get_a_case_comment
|
40
|
-
comment = CaseComment.find_by_parent_id('500300000011inJAAQ')
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
def test_one_to_many_relationship
|
45
|
-
cases = Case.find_by_contact_id('0033000000B1LKrAAN')
|
46
|
-
|
47
|
-
cases = [ cases ] unless cases.is_a?(Array)
|
48
|
-
|
49
|
-
cases.each do |c|
|
50
|
-
puts "Case('#{c.id}', '#{c.subject}')"
|
51
|
-
|
52
|
-
comments = c.case_comments
|
53
|
-
comments.each do |comment|
|
54
|
-
puts " CaseComment('#{comment.id}', '#{comment.comment_body}')"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_get_account
|
60
|
-
accounts = Account.find(:all)
|
61
|
-
|
62
|
-
accounts.each { |account| puts "#{account.name}, #{account.id}, #{account.last_modified_by_id}" }
|
63
|
-
|
64
|
-
acme = Account.find(:first, :conditions => ["name = 'Acme'"])
|
65
|
-
|
66
|
-
acme = Account.find_by_id(acme.id)
|
67
|
-
|
68
|
-
acme = Account.find_by_name_and_last_modified_by_id('salesforce.com', acme.last_modified_by_id)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_update_account
|
72
|
-
acme = Account.new
|
73
|
-
acme.name = "Acme"
|
74
|
-
acme.save
|
75
|
-
|
76
|
-
acme = Account.find_by_name('Acme')
|
77
|
-
|
78
|
-
acme.website = "http://www.dutchforce.com/#{Time.now}.jpg"
|
79
|
-
acme.last_modified_date = Time.now
|
80
|
-
|
81
|
-
acme.save
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
def test_destroy_account
|
86
|
-
Account.new
|
87
|
-
|
88
|
-
account = Account.create(:name => "DutchADelete", :website => "www.dutchcodelete.com")
|
89
|
-
account2 = Account.create(:name => "DutchADelete2", :website => "www.dutchcodelete2.com")
|
90
|
-
|
91
|
-
#pp account
|
92
|
-
|
93
|
-
account = Account.find_by_id(account.id)
|
94
|
-
|
95
|
-
pp account.parent
|
96
|
-
|
97
|
-
createdBy = account.created_by
|
98
|
-
createdBy = User.find_by_id(account.created_by_id);
|
99
|
-
puts createdBy.email
|
100
|
-
|
101
|
-
Account.delete([account.id, account2.id])
|
102
|
-
|
103
|
-
account3 = Account.create(:name => "DutchADelete3", :website => "www.dutchcodelete3.com")
|
104
|
-
account3.destroy
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|