restforce-db 0.4.0 → 0.5.0
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.
- checksums.yaml +4 -4
- data/lib/file_daemon.rb +42 -0
- data/lib/restforce/db/accumulator.rb +41 -0
- data/lib/restforce/db/attribute_map.rb +132 -0
- data/lib/restforce/db/collector.rb +79 -0
- data/lib/restforce/db/initializer.rb +62 -0
- data/lib/restforce/db/instances/base.rb +1 -14
- data/lib/restforce/db/instances/salesforce.rb +7 -0
- data/lib/restforce/db/mapping.rb +33 -79
- data/lib/restforce/db/record_types/base.rb +0 -30
- data/lib/restforce/db/runner.rb +80 -0
- data/lib/restforce/db/synchronizer.rb +29 -37
- data/lib/restforce/db/version.rb +1 -1
- data/lib/restforce/db/worker.rb +53 -40
- data/lib/restforce/db.rb +6 -0
- data/test/cassettes/{Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_an_associated_database_record/when_synchronization_is_stale/updates_the_database_record.yml → Restforce_DB_Collector/_run/given_a_Salesforce_record_with_an_associated_database_record/returns_the_attributes_from_both_records.yml} +36 -36
- data/test/cassettes/Restforce_DB_Collector/_run/given_an_existing_Salesforce_record/returns_the_attributes_from_the_Salesforce_record.yml +197 -0
- data/test/cassettes/Restforce_DB_Collector/_run/given_an_existing_database_record/returns_the_attributes_from_the_database_record.yml +81 -0
- data/test/cassettes/Restforce_DB_Initializer/_run/given_an_existing_Salesforce_record/for_a_non-root_mapping/does_not_create_a_database_record.yml +119 -0
- data/test/cassettes/{Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_an_associated_database_record/when_synchronization_is_up-to-date/does_not_update_the_database_record.yml → Restforce_DB_Initializer/_run/given_an_existing_Salesforce_record/for_a_root_mapping/creates_a_matching_database_record.yml} +28 -28
- data/test/cassettes/{Restforce_DB_Synchronizer/_run/given_an_existing_database_record → Restforce_DB_Initializer/_run/given_an_existing_database_record/for_a_root_mapping}/populates_Salesforce_with_the_new_record.yml +44 -44
- data/test/cassettes/{Restforce_DB_Synchronizer/_run/given_an_existing_Salesforce_record/for_a_non-root_mapping/does_not_create_a_database_record.yml → Restforce_DB_Instances_Salesforce/_synced_/when_a_matching_database_record_exists/returns_true.yml} +30 -30
- data/test/cassettes/{Restforce_DB_Synchronizer/_run/given_an_existing_Salesforce_record/for_a_root_mapping/creates_a_matching_database_record.yml → Restforce_DB_Instances_Salesforce/_synced_/when_no_matching_database_record_exists/returns_false.yml} +30 -30
- data/test/cassettes/Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_an_associated_database_record/updates_the_database_record.yml +194 -0
- data/test/cassettes/Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_an_associated_database_record/updates_the_salesforce_record.yml +233 -0
- data/test/lib/restforce/db/accumulator_test.rb +71 -0
- data/test/lib/restforce/db/attribute_map_test.rb +70 -0
- data/test/lib/restforce/db/collector_test.rb +91 -0
- data/test/lib/restforce/db/initializer_test.rb +92 -0
- data/test/lib/restforce/db/instances/active_record_test.rb +0 -13
- data/test/lib/restforce/db/instances/salesforce_test.rb +20 -13
- data/test/lib/restforce/db/mapping_test.rb +1 -37
- data/test/lib/restforce/db/record_types/active_record_test.rb +0 -40
- data/test/lib/restforce/db/runner_test.rb +40 -0
- data/test/lib/restforce/db/synchronizer_test.rb +26 -86
- metadata +23 -7
@@ -8,46 +8,6 @@ describe Restforce::DB::RecordTypes::ActiveRecord do
|
|
8
8
|
let(:record_type) { mapping.database_record_type }
|
9
9
|
let(:salesforce_id) { "a001a000001E1vREAL" }
|
10
10
|
|
11
|
-
describe "#sync!" do
|
12
|
-
let(:sync_from) do
|
13
|
-
Struct.new(:id, :last_update, :attributes).new(
|
14
|
-
salesforce_id,
|
15
|
-
Time.now,
|
16
|
-
name: "Some name",
|
17
|
-
example: "Some text",
|
18
|
-
)
|
19
|
-
end
|
20
|
-
let(:instance) { record_type.sync!(sync_from).record }
|
21
|
-
|
22
|
-
describe "without an existing database record" do
|
23
|
-
|
24
|
-
it "creates a new database record from the passed Salesforce record" do
|
25
|
-
expect(instance.salesforce_id).to_equal salesforce_id
|
26
|
-
expect(instance.name).to_equal sync_from.attributes[:name]
|
27
|
-
expect(instance.example).to_equal sync_from.attributes[:example]
|
28
|
-
expect(instance.synchronized_at).to_not_be_nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "with an existing database record" do
|
33
|
-
let!(:sync_to) do
|
34
|
-
database_model.create!(
|
35
|
-
name: "Existing name",
|
36
|
-
example: "Existing sample text",
|
37
|
-
salesforce_id: salesforce_id,
|
38
|
-
synchronized_at: Time.now,
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "updates the existing database record" do
|
43
|
-
expect(instance).to_equal sync_to.reload
|
44
|
-
expect(instance.name).to_equal sync_from.attributes[:name]
|
45
|
-
expect(instance.example).to_equal sync_from.attributes[:example]
|
46
|
-
expect(instance.synchronized_at).to_not_be_nil
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
11
|
describe "#create!" do
|
52
12
|
let(:attributes) do
|
53
13
|
{
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative "../../../test_helper"
|
2
|
+
|
3
|
+
describe Restforce::DB::Runner do
|
4
|
+
before { Restforce::DB.last_run = Time.now }
|
5
|
+
after { Restforce::DB.last_run = nil }
|
6
|
+
|
7
|
+
let(:runner) { Restforce::DB::Runner.new }
|
8
|
+
|
9
|
+
describe "#initialize" do
|
10
|
+
|
11
|
+
it "prefills the Collector's last_run timestamp with the global configuration" do
|
12
|
+
expect(runner.last_run).to_equal Restforce::DB.last_run
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#tick!" do
|
17
|
+
|
18
|
+
it "updates the run timestamps" do
|
19
|
+
prior_run = runner.last_run
|
20
|
+
new_run = runner.tick!
|
21
|
+
|
22
|
+
expect(runner.last_run).to_equal new_run
|
23
|
+
expect(runner.before).to_equal new_run
|
24
|
+
expect(runner.after).to_equal prior_run
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "with a configured delay" do
|
28
|
+
let(:delay) { 5 }
|
29
|
+
let(:runner) { Restforce::DB::Runner.new(delay) }
|
30
|
+
|
31
|
+
it "offsets the timestamps" do
|
32
|
+
prior_run = runner.last_run
|
33
|
+
new_run = runner.tick!
|
34
|
+
|
35
|
+
expect(runner.before).to_equal new_run - delay
|
36
|
+
expect(runner.after).to_equal prior_run - delay
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -5,16 +5,7 @@ describe Restforce::DB::Synchronizer do
|
|
5
5
|
configure!
|
6
6
|
mappings!
|
7
7
|
|
8
|
-
let(:synchronizer) { mapping
|
9
|
-
|
10
|
-
describe "#initialize" do
|
11
|
-
before { Restforce::DB.last_run = Time.now }
|
12
|
-
after { Restforce::DB.last_run = nil }
|
13
|
-
|
14
|
-
it "prefills the Synchronizer's last_run timestamp with the global configuration" do
|
15
|
-
expect(synchronizer.last_run).to_equal Restforce::DB.last_run
|
16
|
-
end
|
17
|
-
end
|
8
|
+
let(:synchronizer) { Restforce::DB::Synchronizer.new(mapping) }
|
18
9
|
|
19
10
|
describe "#run", vcr: { match_requests_on: [:method, VCR.request_matchers.uri_without_param(:q)] } do
|
20
11
|
let(:attributes) do
|
@@ -30,59 +21,8 @@ describe Restforce::DB::Synchronizer do
|
|
30
21
|
)
|
31
22
|
end
|
32
23
|
|
33
|
-
describe "given an existing Salesforce record" do
|
34
|
-
before do
|
35
|
-
salesforce_id
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "for a root mapping" do
|
39
|
-
before do
|
40
|
-
synchronizer.run
|
41
|
-
end
|
42
|
-
|
43
|
-
it "creates a matching database record" do
|
44
|
-
record = database_model.last
|
45
|
-
|
46
|
-
expect(record.name).to_equal attributes[:name]
|
47
|
-
expect(record.example).to_equal attributes[:example]
|
48
|
-
expect(record.salesforce_id).to_equal salesforce_id
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "for a non-root mapping" do
|
53
|
-
let(:through) { "SomeField__c" }
|
54
|
-
|
55
|
-
before do
|
56
|
-
synchronizer.run
|
57
|
-
end
|
58
|
-
|
59
|
-
it "does not create a database record" do
|
60
|
-
expect(database_model.last).to_be_nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "given an existing database record" do
|
66
|
-
let(:database_record) { database_model.create!(attributes) }
|
67
|
-
let(:salesforce_id) { database_record.reload.salesforce_id }
|
68
|
-
|
69
|
-
before do
|
70
|
-
database_record
|
71
|
-
synchronizer.run
|
72
|
-
|
73
|
-
Salesforce.records << [salesforce_model, salesforce_id]
|
74
|
-
end
|
75
|
-
|
76
|
-
it "populates Salesforce with the new record" do
|
77
|
-
record = mapping.salesforce_record_type.find(salesforce_id).record
|
78
|
-
|
79
|
-
expect(record.Name).to_equal attributes[:name]
|
80
|
-
expect(record.Example_Field__c).to_equal attributes[:example]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
24
|
describe "given a Salesforce record with an associated database record" do
|
85
|
-
let
|
25
|
+
let(:database_attributes) do
|
86
26
|
{
|
87
27
|
name: "Some existing name",
|
88
28
|
example: "Some existing sample text",
|
@@ -93,36 +33,36 @@ describe Restforce::DB::Synchronizer do
|
|
93
33
|
database_model.create!(database_attributes.merge(salesforce_id: salesforce_id))
|
94
34
|
end
|
95
35
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
36
|
+
let(:changes) { { [salesforce_id, salesforce_model] => accumulator } }
|
37
|
+
let(:new_attributes) do
|
38
|
+
{
|
39
|
+
"Name" => "Some new name",
|
40
|
+
"Example_Field__c" => "New sample text",
|
41
|
+
}
|
42
|
+
end
|
43
|
+
let(:accumulator) do
|
44
|
+
Restforce::DB::Accumulator.new.tap do |accumulator|
|
45
|
+
accumulator.store(Time.now, new_attributes)
|
104
46
|
end
|
47
|
+
end
|
105
48
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
expect(record.name).to_equal attributes[:name]
|
110
|
-
expect(record.example).to_equal attributes[:example]
|
111
|
-
end
|
49
|
+
before do
|
50
|
+
database_record
|
51
|
+
synchronizer.run(changes)
|
112
52
|
end
|
113
53
|
|
114
|
-
|
115
|
-
|
116
|
-
database_record.touch(:synchronized_at)
|
117
|
-
synchronizer.run
|
118
|
-
end
|
54
|
+
it "updates the database record" do
|
55
|
+
record = database_record.reload
|
119
56
|
|
120
|
-
|
121
|
-
|
57
|
+
expect(record.name).to_equal new_attributes["Name"]
|
58
|
+
expect(record.example).to_equal new_attributes["Example_Field__c"]
|
59
|
+
end
|
122
60
|
|
123
|
-
|
124
|
-
|
125
|
-
|
61
|
+
it "updates the salesforce record" do
|
62
|
+
record = mapping.salesforce_record_type.find(salesforce_id).record
|
63
|
+
|
64
|
+
expect(record.Name).to_equal new_attributes["Name"]
|
65
|
+
expect(record.Example_Field__c).to_equal new_attributes["Example_Field__c"]
|
126
66
|
end
|
127
67
|
end
|
128
68
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restforce-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -214,15 +214,20 @@ files:
|
|
214
214
|
- Rakefile
|
215
215
|
- bin/console
|
216
216
|
- bin/setup
|
217
|
+
- lib/file_daemon.rb
|
217
218
|
- lib/generators/restforce/install_generator.rb
|
218
219
|
- lib/generators/restforce/migration_generator.rb
|
219
220
|
- lib/generators/templates/config.yml
|
220
221
|
- lib/generators/templates/migration.rb.tt
|
221
222
|
- lib/generators/templates/script
|
222
223
|
- lib/restforce/db.rb
|
224
|
+
- lib/restforce/db/accumulator.rb
|
223
225
|
- lib/restforce/db/associations/active_record.rb
|
226
|
+
- lib/restforce/db/attribute_map.rb
|
227
|
+
- lib/restforce/db/collector.rb
|
224
228
|
- lib/restforce/db/command.rb
|
225
229
|
- lib/restforce/db/configuration.rb
|
230
|
+
- lib/restforce/db/initializer.rb
|
226
231
|
- lib/restforce/db/instances/active_record.rb
|
227
232
|
- lib/restforce/db/instances/base.rb
|
228
233
|
- lib/restforce/db/instances/salesforce.rb
|
@@ -231,6 +236,7 @@ files:
|
|
231
236
|
- lib/restforce/db/record_types/active_record.rb
|
232
237
|
- lib/restforce/db/record_types/base.rb
|
233
238
|
- lib/restforce/db/record_types/salesforce.rb
|
239
|
+
- lib/restforce/db/runner.rb
|
234
240
|
- lib/restforce/db/synchronizer.rb
|
235
241
|
- lib/restforce/db/tracker.rb
|
236
242
|
- lib/restforce/db/version.rb
|
@@ -238,7 +244,15 @@ files:
|
|
238
244
|
- lib/restforce/extensions.rb
|
239
245
|
- restforce-db.gemspec
|
240
246
|
- test/cassettes/Restforce_DB/accessing_Salesforce/uses_the_configured_credentials.yml
|
247
|
+
- test/cassettes/Restforce_DB_Collector/_run/given_a_Salesforce_record_with_an_associated_database_record/returns_the_attributes_from_both_records.yml
|
248
|
+
- test/cassettes/Restforce_DB_Collector/_run/given_an_existing_Salesforce_record/returns_the_attributes_from_the_Salesforce_record.yml
|
249
|
+
- test/cassettes/Restforce_DB_Collector/_run/given_an_existing_database_record/returns_the_attributes_from_the_database_record.yml
|
250
|
+
- test/cassettes/Restforce_DB_Initializer/_run/given_an_existing_Salesforce_record/for_a_non-root_mapping/does_not_create_a_database_record.yml
|
251
|
+
- test/cassettes/Restforce_DB_Initializer/_run/given_an_existing_Salesforce_record/for_a_root_mapping/creates_a_matching_database_record.yml
|
252
|
+
- test/cassettes/Restforce_DB_Initializer/_run/given_an_existing_database_record/for_a_root_mapping/populates_Salesforce_with_the_new_record.yml
|
241
253
|
- test/cassettes/Restforce_DB_Instances_Salesforce/_copy_/updates_the_record_with_the_attributes_from_the_copied_object.yml
|
254
|
+
- test/cassettes/Restforce_DB_Instances_Salesforce/_synced_/when_a_matching_database_record_exists/returns_true.yml
|
255
|
+
- test/cassettes/Restforce_DB_Instances_Salesforce/_synced_/when_no_matching_database_record_exists/returns_false.yml
|
242
256
|
- test/cassettes/Restforce_DB_Instances_Salesforce/_update_/updates_the_local_record_with_the_passed_attributes.yml
|
243
257
|
- test/cassettes/Restforce_DB_Instances_Salesforce/_update_/updates_the_record_in_Salesforce_with_the_passed_attributes.yml
|
244
258
|
- test/cassettes/Restforce_DB_RecordTypes_Salesforce/_create_/creates_a_record_in_Salesforce_from_the_passed_database_record_s_attributes.yml
|
@@ -248,19 +262,21 @@ files:
|
|
248
262
|
- test/cassettes/Restforce_DB_RecordTypes_Salesforce/_find/given_a_set_of_mapping_conditions/when_a_record_does_not_meet_the_conditions/does_not_find_the_record.yml
|
249
263
|
- test/cassettes/Restforce_DB_RecordTypes_Salesforce/_find/given_a_set_of_mapping_conditions/when_a_record_meets_the_conditions/finds_the_record.yml
|
250
264
|
- test/cassettes/Restforce_DB_RecordTypes_Salesforce/_find/returns_nil_when_no_matching_record_exists.yml
|
251
|
-
- test/cassettes/Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_an_associated_database_record/
|
252
|
-
- test/cassettes/Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_an_associated_database_record/
|
253
|
-
- test/
|
254
|
-
- test/cassettes/Restforce_DB_Synchronizer/_run/given_an_existing_Salesforce_record/for_a_root_mapping/creates_a_matching_database_record.yml
|
255
|
-
- test/cassettes/Restforce_DB_Synchronizer/_run/given_an_existing_database_record/populates_Salesforce_with_the_new_record.yml
|
265
|
+
- test/cassettes/Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_an_associated_database_record/updates_the_database_record.yml
|
266
|
+
- test/cassettes/Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_an_associated_database_record/updates_the_salesforce_record.yml
|
267
|
+
- test/lib/restforce/db/accumulator_test.rb
|
256
268
|
- test/lib/restforce/db/associations/active_record_test.rb
|
269
|
+
- test/lib/restforce/db/attribute_map_test.rb
|
270
|
+
- test/lib/restforce/db/collector_test.rb
|
257
271
|
- test/lib/restforce/db/configuration_test.rb
|
272
|
+
- test/lib/restforce/db/initializer_test.rb
|
258
273
|
- test/lib/restforce/db/instances/active_record_test.rb
|
259
274
|
- test/lib/restforce/db/instances/salesforce_test.rb
|
260
275
|
- test/lib/restforce/db/mapping_test.rb
|
261
276
|
- test/lib/restforce/db/model_test.rb
|
262
277
|
- test/lib/restforce/db/record_types/active_record_test.rb
|
263
278
|
- test/lib/restforce/db/record_types/salesforce_test.rb
|
279
|
+
- test/lib/restforce/db/runner_test.rb
|
264
280
|
- test/lib/restforce/db/synchronizer_test.rb
|
265
281
|
- test/lib/restforce/db/tracker_test.rb
|
266
282
|
- test/lib/restforce/db_test.rb
|