active_force 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +7 -2
- data/lib/active_force/sobject.rb +17 -5
- data/lib/active_force/version.rb +1 -1
- data/spec/active_force/sobject_spec.rb +53 -36
- data/spec/support/whizbang.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f78cd5f272f46a14d23431270acbfa2d6b8226b3
|
4
|
+
data.tar.gz: e38b5c4f75717978e8862e974a0f8464b52fc1cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3953499253bd6e0adbb2b5f9aaf8dc1a2d33d3b08048284b2f4e517954870ae48f83694fb6e4243b1c3d98c3375f2238ad238f420c523ebea65306f64dafa329
|
7
|
+
data.tar.gz: 4cf78d28885b7b7562c6f21a1f457680d2006709f3b2f8ea89c5ee4ed9c72b5f7f74843cd7ccdd35a82e661687263cfa284d1df14c5f9eb3a68caf52adb97082
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
3
|
## Not released
|
4
|
+
* SObject#destroy method.
|
5
|
+
|
6
|
+
## 0.6.1
|
7
|
+
|
8
|
+
* Fix missing require of 'restforce'. Now clients don't need to add an initializer.
|
9
|
+
|
10
|
+
## 0.6.0
|
4
11
|
|
5
12
|
* Add select statement functionality. ([Pablo Oldani][], [#33][])
|
6
13
|
* Add callback functionality ([Pablo Oldani][], [#20][])
|
data/README.md
CHANGED
@@ -27,12 +27,11 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
$ gem install active_force
|
29
29
|
|
30
|
-
|
30
|
+
If you want restforce logging on a rails app:
|
31
31
|
|
32
32
|
```ruby
|
33
33
|
#Add this to initializers/restforce.rb
|
34
34
|
Restforce.log = true if Rails.env.development?
|
35
|
-
::Client = Restforce.new
|
36
35
|
```
|
37
36
|
|
38
37
|
## Usage
|
@@ -114,6 +113,12 @@ class Page < ActiveForce::SObject
|
|
114
113
|
end
|
115
114
|
```
|
116
115
|
|
116
|
+
### Model generator
|
117
|
+
|
118
|
+
When using rails, you can generate a model with all the fields you have on your SFDC table by running:
|
119
|
+
|
120
|
+
rails g active_force:model <table name>
|
121
|
+
|
117
122
|
## Contributing
|
118
123
|
|
119
124
|
1. Fork it
|
data/lib/active_force/sobject.rb
CHANGED
@@ -7,6 +7,7 @@ require 'active_force/table'
|
|
7
7
|
require 'yaml'
|
8
8
|
require 'forwardable'
|
9
9
|
require 'logger'
|
10
|
+
require 'restforce'
|
10
11
|
|
11
12
|
module ActiveForce
|
12
13
|
class SObject
|
@@ -105,6 +106,10 @@ module ActiveForce
|
|
105
106
|
logger_output __method__
|
106
107
|
end
|
107
108
|
|
109
|
+
def destroy
|
110
|
+
sfdc_client.destroy! self.class.table_name, id
|
111
|
+
end
|
112
|
+
|
108
113
|
def self.create args
|
109
114
|
new(args).save
|
110
115
|
end
|
@@ -134,7 +139,7 @@ module ActiveForce
|
|
134
139
|
end
|
135
140
|
|
136
141
|
def persisted?
|
137
|
-
id
|
142
|
+
!!id
|
138
143
|
end
|
139
144
|
|
140
145
|
def self.field field_name, args = {}
|
@@ -170,11 +175,18 @@ module ActiveForce
|
|
170
175
|
end
|
171
176
|
|
172
177
|
def attributes_for_sfdb
|
173
|
-
|
174
|
-
|
175
|
-
|
178
|
+
if persisted?
|
179
|
+
attrs = changed_mappings.map do |attr, sf_field|
|
180
|
+
value = read_value(attr)
|
181
|
+
[sf_field, value]
|
182
|
+
end
|
183
|
+
attrs << ['Id', id]
|
184
|
+
else
|
185
|
+
attrs = mappings.map do |attr, sf_field|
|
186
|
+
value = read_value(attr)
|
187
|
+
[sf_field, value] unless value.nil?
|
188
|
+
end
|
176
189
|
end
|
177
|
-
attrs << ['Id', id] if persisted?
|
178
190
|
Hash[attrs.compact]
|
179
191
|
end
|
180
192
|
|
data/lib/active_force/version.rb
CHANGED
@@ -83,57 +83,56 @@ describe ActiveForce::SObject do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
describe
|
87
|
-
|
86
|
+
describe "CRUD" do
|
88
87
|
subject do
|
89
88
|
Whizbang.new(id: '1')
|
90
89
|
end
|
91
90
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
91
|
+
describe '#update' do
|
92
|
+
before do
|
93
|
+
expected_args = [
|
94
|
+
Whizbang.table_name,
|
95
|
+
{'Text_Label' => 'some text', 'Boolean_Label' => false, 'Id' => '1'}
|
96
|
+
]
|
97
|
+
expect(client).to receive(:update!).with(*expected_args).and_return('id')
|
98
|
+
end
|
99
99
|
|
100
|
-
|
101
|
-
|
100
|
+
it 'delegates to the Client with create!' do
|
101
|
+
expect(subject.update({ text: 'some text', boolean: false })).to be_a Whizbang
|
102
|
+
end
|
102
103
|
end
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
subject do
|
109
|
-
Whizbang.new
|
110
|
-
end
|
105
|
+
describe '#create' do
|
106
|
+
before do
|
107
|
+
expect(client).to receive(:create!).and_return('id')
|
108
|
+
end
|
111
109
|
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
it 'delegates to the Client with create!' do
|
111
|
+
subject.create
|
112
|
+
end
|
115
113
|
|
116
|
-
|
117
|
-
|
114
|
+
it 'sets the id' do
|
115
|
+
subject.create
|
116
|
+
expect(subject.id).to eq('id')
|
117
|
+
end
|
118
118
|
end
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
describe "#destroy" do
|
121
|
+
it "should send client :destroy! with its id" do
|
122
|
+
expect(client).to receive(:destroy!).with 'Whizbang__c', '1'
|
123
|
+
subject.destroy
|
124
|
+
end
|
123
125
|
end
|
124
126
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
before do
|
130
|
-
expect(client).to receive(:create!).with(Whizbang.table_name, 'Text_Label' => 'some text').and_return('id')
|
131
|
-
end
|
127
|
+
describe 'self.create' do
|
128
|
+
before do
|
129
|
+
expect(client).to receive(:create!).with(Whizbang.table_name, 'Text_Label' => 'some text').and_return('id')
|
130
|
+
end
|
132
131
|
|
133
|
-
|
134
|
-
|
132
|
+
it 'should create a new instance' do
|
133
|
+
expect(Whizbang.create({ text: 'some text' })).to be_a Whizbang
|
134
|
+
end
|
135
135
|
end
|
136
|
-
|
137
136
|
end
|
138
137
|
|
139
138
|
describe "#count" do
|
@@ -195,4 +194,22 @@ describe ActiveForce::SObject do
|
|
195
194
|
expect(territory.reload).to eql expected
|
196
195
|
end
|
197
196
|
end
|
197
|
+
|
198
|
+
describe '#persisted?' do
|
199
|
+
context 'with an id' do
|
200
|
+
let(:instance){ Territory.new(id: '00QV0000004jeqNMAT') }
|
201
|
+
|
202
|
+
it 'returns true' do
|
203
|
+
expect(instance).to be_persisted
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'without an id' do
|
208
|
+
let(:instance){ Territory.new }
|
209
|
+
|
210
|
+
it 'returns false' do
|
211
|
+
expect(instance).to_not be_persisted
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
198
215
|
end
|
data/spec/support/whizbang.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_force
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eloy Espinaco
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-09-
|
14
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: active_attr
|