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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36f3376b1b60bba8f226a7b811550b16fc4fccf2
4
- data.tar.gz: 8c5f72016eb4139055f141858d7377d6dc93a84c
3
+ metadata.gz: f78cd5f272f46a14d23431270acbfa2d6b8226b3
4
+ data.tar.gz: e38b5c4f75717978e8862e974a0f8464b52fc1cb
5
5
  SHA512:
6
- metadata.gz: 7ec85db056728c1365e39f2934726daa912d67b6fae0865dcfbe1b88313c991dac416a24ba0c6bf516955125cc2471550ca38d427485d894078d477e0bf05c4a
7
- data.tar.gz: 1b9263f3bdaab14b9ce0abe6c366684032dbeb7d01f5a1718003f5d7b0c640163722849ec69eebff1e2f57f48a1c9fda9ffc36a145ec87938b5e5173476a0457
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
- Rails:
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
@@ -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
- attrs = mappings.map do |attr, sf_field|
174
- value = read_value(attr)
175
- [sf_field, value] if value
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
 
@@ -1,3 +1,3 @@
1
1
  module ActiveForce
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -83,57 +83,56 @@ describe ActiveForce::SObject do
83
83
  end
84
84
  end
85
85
 
86
- describe '#update' do
87
-
86
+ describe "CRUD" do
88
87
  subject do
89
88
  Whizbang.new(id: '1')
90
89
  end
91
90
 
92
- before do
93
- expected_args = [
94
- Whizbang.table_name,
95
- {'Text_Label' => 'some text', 'Id' => '1'}
96
- ]
97
- expect(client).to receive(:update!).with(*expected_args).and_return('id')
98
- end
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
- it 'delegates to the Client with create!' do
101
- expect(subject.update({ text: 'some text' })).to be_a Whizbang
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
- end
105
-
106
- describe '#create' do
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
- before do
113
- expect(client).to receive(:create!).and_return('id')
114
- end
110
+ it 'delegates to the Client with create!' do
111
+ subject.create
112
+ end
115
113
 
116
- it 'delegates to the Client with create!' do
117
- subject.create
114
+ it 'sets the id' do
115
+ subject.create
116
+ expect(subject.id).to eq('id')
117
+ end
118
118
  end
119
119
 
120
- it 'sets the id' do
121
- subject.create
122
- expect(subject.id).to eq('id')
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
- end
126
-
127
- describe 'self.create' do
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
- it 'should create a new instance' do
134
- expect(Whizbang.create({ text: 'some text' })).to be_a Whizbang
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
@@ -6,6 +6,7 @@ class Whizbang < ActiveForce::SObject
6
6
  field :date, from: 'Date_Label'
7
7
  field :datetime, from: 'DateTime_Label'
8
8
  field :picklist_multiselect, from: 'Picklist_Multiselect_Label'
9
+ field :boolean, from: 'Boolean_Label'
9
10
  field :estimated_close_date
10
11
 
11
12
  end
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.0
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-01 00:00:00.000000000 Z
14
+ date: 2014-09-03 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: active_attr