active_force 0.1.1 → 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.
- checksums.yaml +4 -4
- data/.travis.yml +9 -1
- data/Gemfile +1 -0
- data/README.md +13 -1
- data/active_force.gemspec +6 -4
- data/lib/active_force/association.rb +12 -27
- data/lib/active_force/association/association.rb +30 -0
- data/lib/active_force/association/belongs_to_association.rb +21 -0
- data/lib/active_force/association/has_many_association.rb +37 -0
- data/lib/active_force/finders.rb +37 -0
- data/lib/active_force/query.rb +25 -12
- data/lib/active_force/sobject.rb +27 -15
- data/lib/active_force/version.rb +1 -1
- data/spec/active_force/association_spec.rb +56 -36
- data/spec/active_force/sobject_spec.rb +25 -0
- data/spec/active_query/query_spec.rb +51 -3
- data/spec/spec_helper.rb +4 -0
- metadata +15 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e99615e3d168755a419d7264acc03d5e8d230301
|
4
|
+
data.tar.gz: a38eec002c02ced5930ba02da66efbdf833a01a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb06e3a6de2e82d2f0aa0f86965a1199ce4be71b66709482954fb0e685ac4765d08bf925d7c0ee5ee015ab5663dc54f584d85a6a15655442b6d230e47e14671
|
7
|
+
data.tar.gz: 6ca95ce88edcaf1568c6e4db643b8acdcaea075020f1fc40f1ae6c3ef5e9d3ae0ad278f800a17a726275dbda9bc65b580b862a5e02421f54d41754a690cbf884
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
[](http://badge.fury.io/rb/active_force)
|
2
|
-
[](https://travis-ci.org/ionia-corporation/active_force)
|
3
|
+
[](https://codeclimate.com/github/ionia-corporation/active_force)
|
4
|
+
[](https://gemnasium.com/ionia-corporation/active_force)
|
5
|
+
[](https://codeclimate.com/github/ionia-corporation/active_force)
|
6
|
+
|
3
7
|
|
4
8
|
# ActiveForce
|
5
9
|
|
@@ -19,6 +23,14 @@ And then execute:
|
|
19
23
|
Or install it yourself as:
|
20
24
|
|
21
25
|
$ gem install active_force
|
26
|
+
|
27
|
+
Rails:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
#Add this to initializers/restforce.rb
|
31
|
+
Restforce.log = true if Rails.env.development?
|
32
|
+
::Client = Restforce.new
|
33
|
+
```
|
22
34
|
|
23
35
|
## Usage
|
24
36
|
|
data/active_force.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = "eloyesp@gmail.com"
|
11
11
|
spec.description = %q{Use SalesForce as an ActiveModel}
|
12
12
|
spec.summary = %q{Help you implement models persisting on Sales Force within Rails using RESTForce}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/ionia-corporation/active_force"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -18,10 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.required_ruby_version = '~> 2.0'
|
22
|
+
|
21
23
|
spec.add_dependency 'active_attr', '~> 0.8'
|
22
24
|
spec.add_dependency 'restforce', '~> 1.4'
|
23
25
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
-
spec.add_development_dependency 'rake'
|
25
|
-
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency 'pry'
|
26
|
+
spec.add_development_dependency 'rake', '~> 0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 0'
|
28
|
+
spec.add_development_dependency 'pry', '~> 0'
|
27
29
|
end
|
@@ -1,39 +1,24 @@
|
|
1
|
-
require 'active_force/
|
1
|
+
require 'active_force/association/association'
|
2
|
+
require 'active_force/association/has_many_association'
|
3
|
+
require 'active_force/association/belongs_to_association'
|
2
4
|
|
3
5
|
module ActiveForce
|
4
6
|
module Association
|
5
7
|
module ClassMethods
|
6
|
-
def has_many relation_name, options = {}
|
7
|
-
model = options[:model] || relation_model(relation_name)
|
8
|
-
association_name = options[:table] || model.table_name || "#{ model }__c"
|
9
|
-
foreing_key = options[:foreing_key] || default_foreing_key(model, self.name) || table_name
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
query.fields model.fields
|
14
|
-
query.where(options[:where]) if options[:where]
|
15
|
-
query.order(options[:order]) if options[:order]
|
16
|
-
query.limit(options[:limit]) if options[:limit]
|
17
|
-
query.where("#{ foreing_key } = '#{ id }'")
|
18
|
-
query
|
19
|
-
end
|
9
|
+
def has_many relation_name, options = {}
|
10
|
+
HasManyAssociation.new(self, relation_name, options)
|
20
11
|
end
|
21
12
|
|
22
|
-
def
|
23
|
-
|
13
|
+
def belongs_to relation_name, options = {}
|
14
|
+
BelongsToAssociation.new(self, relation_name, options)
|
24
15
|
end
|
25
16
|
|
26
|
-
|
27
|
-
relation_model.mappings["#{model.downcase}_id".to_sym]
|
28
|
-
end
|
17
|
+
end
|
29
18
|
|
30
|
-
|
31
|
-
|
32
|
-
foreing_key = options[:foreing_key] || "#{ relation_name }_id".to_sym
|
33
|
-
define_method "#{ relation_name }" do
|
34
|
-
model.find(self.send foreing_key)
|
35
|
-
end
|
36
|
-
end
|
19
|
+
def self.included mod
|
20
|
+
mod.extend ClassMethods
|
37
21
|
end
|
22
|
+
|
38
23
|
end
|
39
|
-
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActiveForce
|
2
|
+
module Association
|
3
|
+
class Association
|
4
|
+
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize parent, relation_name, options
|
8
|
+
@parent = parent
|
9
|
+
@relation_name = relation_name
|
10
|
+
@options = options
|
11
|
+
build
|
12
|
+
end
|
13
|
+
|
14
|
+
def relation_model
|
15
|
+
@options[:model] || @relation_name.to_s.singularize.camelcase.constantize
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def build
|
21
|
+
define_relation_method
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_sfdc_foreign_key
|
25
|
+
relation_model.mappings["#{ @parent.name.downcase }_id".to_sym]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveForce
|
2
|
+
module Association
|
3
|
+
|
4
|
+
class BelongsToAssociation < Association
|
5
|
+
|
6
|
+
def foreign_key
|
7
|
+
options[:foreign_key] || "#{ @relation_name }_id".to_sym
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def define_relation_method
|
13
|
+
association = self
|
14
|
+
@parent.send :define_method, @relation_name do
|
15
|
+
association.relation_model.find(self.send association.foreign_key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ActiveForce
|
2
|
+
module Association
|
3
|
+
class HasManyAssociation < Association
|
4
|
+
|
5
|
+
def foreign_key
|
6
|
+
@options[:foreign_key] || default_sfdc_foreign_key || @parent.table_name
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def build
|
12
|
+
super
|
13
|
+
define_query_method
|
14
|
+
end
|
15
|
+
|
16
|
+
def define_query_method
|
17
|
+
association = self
|
18
|
+
@parent.send :define_method, query_method_name do
|
19
|
+
query = association.relation_model.query
|
20
|
+
query.options association.options
|
21
|
+
query.where "#{ association.foreign_key } = '#{ self.id }'"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def define_relation_method
|
26
|
+
association = self
|
27
|
+
@parent.send :define_method, @relation_name do
|
28
|
+
association.relation_model.send_query send(association.query_method_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def query_method_name
|
33
|
+
"#{ @relation_name }_query"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ActiveForce
|
2
|
+
module Finders
|
3
|
+
module ClassMethods
|
4
|
+
def find_by conditions
|
5
|
+
query = self.query
|
6
|
+
query_conditions(conditions).each do |query_condition|
|
7
|
+
query = query.where query_condition
|
8
|
+
end
|
9
|
+
send_query(query).first
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
#maps a hash key => value to a string 'key = value'
|
15
|
+
def query_conditions conditions
|
16
|
+
conditions.map do |key, value|
|
17
|
+
"#{ mappings[key] } = #{ enclose_value value }"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# encloses the value in quotes if it's a string
|
22
|
+
def enclose_value value
|
23
|
+
if value.is_a? String
|
24
|
+
"'#{value}'"
|
25
|
+
else
|
26
|
+
value.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.included mod
|
33
|
+
mod.extend ClassMethods
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/active_force/query.rb
CHANGED
@@ -2,8 +2,6 @@ module ActiveForce
|
|
2
2
|
class Query
|
3
3
|
attr_reader :table
|
4
4
|
|
5
|
-
attr_accessor :table_id
|
6
|
-
|
7
5
|
def initialize table
|
8
6
|
@table = table
|
9
7
|
@conditions = []
|
@@ -20,7 +18,7 @@ module ActiveForce
|
|
20
18
|
end
|
21
19
|
|
22
20
|
def to_s
|
23
|
-
|
21
|
+
<<-SOQL.gsub(/\s+/, " ").strip
|
24
22
|
SELECT
|
25
23
|
#{ @query_fields.uniq.join(', ') }
|
26
24
|
FROM
|
@@ -30,21 +28,20 @@ module ActiveForce
|
|
30
28
|
#{ build_limit }
|
31
29
|
#{ build_offset }
|
32
30
|
SOQL
|
33
|
-
query
|
34
31
|
end
|
35
32
|
|
36
33
|
def where condition
|
37
|
-
@conditions << condition
|
34
|
+
@conditions << condition if condition
|
38
35
|
self
|
39
36
|
end
|
40
37
|
|
41
38
|
def order order
|
42
|
-
@order = order
|
39
|
+
@order = order if order
|
43
40
|
self
|
44
41
|
end
|
45
42
|
|
46
43
|
def limit size
|
47
|
-
@size = size
|
44
|
+
@size = size if size
|
48
45
|
self
|
49
46
|
end
|
50
47
|
|
@@ -64,7 +61,14 @@ module ActiveForce
|
|
64
61
|
def find id
|
65
62
|
where "#{ @table_id } = '#{ id }'"
|
66
63
|
limit 1
|
67
|
-
|
64
|
+
end
|
65
|
+
|
66
|
+
def first
|
67
|
+
limit 1
|
68
|
+
end
|
69
|
+
|
70
|
+
def last
|
71
|
+
order("Id DESC").limit(1)
|
68
72
|
end
|
69
73
|
|
70
74
|
def join object_query
|
@@ -72,11 +76,20 @@ module ActiveForce
|
|
72
76
|
self
|
73
77
|
end
|
74
78
|
|
79
|
+
def count
|
80
|
+
@query_fields = ["count(Id)"]
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
def options args
|
85
|
+
where args[:where]
|
86
|
+
limit args[:limit]
|
87
|
+
order args[:order]
|
88
|
+
end
|
89
|
+
|
75
90
|
protected
|
76
91
|
def build_where
|
77
|
-
unless @conditions.empty?
|
78
|
-
"WHERE #{ @conditions.join(' AND ') }"
|
79
|
-
end
|
92
|
+
"WHERE #{ @conditions.join(' AND ') }" unless @conditions.empty?
|
80
93
|
end
|
81
94
|
|
82
95
|
def build_limit
|
@@ -91,4 +104,4 @@ module ActiveForce
|
|
91
104
|
"OFFSET #{ @offset }" if @offset
|
92
105
|
end
|
93
106
|
end
|
94
|
-
end
|
107
|
+
end
|
data/lib/active_force/sobject.rb
CHANGED
@@ -3,6 +3,7 @@ require 'active_attr'
|
|
3
3
|
require 'active_attr/dirty'
|
4
4
|
require 'active_force/query'
|
5
5
|
require 'active_force/association'
|
6
|
+
require 'active_force/finders'
|
6
7
|
require 'yaml'
|
7
8
|
|
8
9
|
module ActiveForce
|
@@ -10,8 +11,7 @@ module ActiveForce
|
|
10
11
|
include ActiveAttr::Model
|
11
12
|
include ActiveAttr::Dirty
|
12
13
|
include ActiveForce::Association
|
13
|
-
|
14
|
-
extend ClassMethods
|
14
|
+
include ActiveForce::Finders
|
15
15
|
|
16
16
|
STANDARD_TYPES = %w[ Account Contact Opportunity Campaign]
|
17
17
|
|
@@ -27,16 +27,8 @@ module ActiveForce
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.has_many relation_name, options = {}
|
31
|
-
super
|
32
|
-
model = options[:model] || relation_model(relation_name)
|
33
|
-
define_method relation_name do
|
34
|
-
model.send_query(self.send "#{ relation_name }_query".to_sym)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
30
|
def self.build sobject
|
39
|
-
return
|
31
|
+
return unless sobject
|
40
32
|
model = new
|
41
33
|
mappings.each do |attr, sf_field|
|
42
34
|
model[attr] = sobject[sf_field]
|
@@ -51,12 +43,24 @@ module ActiveForce
|
|
51
43
|
query
|
52
44
|
end
|
53
45
|
|
46
|
+
def self.first
|
47
|
+
send_query(query.first).first
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.last
|
51
|
+
send_query(query.last).first
|
52
|
+
end
|
53
|
+
|
54
54
|
def self.all
|
55
55
|
send_query query
|
56
56
|
end
|
57
57
|
|
58
|
+
def self.count
|
59
|
+
sfdc_client.query(query.count).first.expr0
|
60
|
+
end
|
61
|
+
|
58
62
|
def self.send_query query
|
59
|
-
|
63
|
+
sfdc_client.query(query.to_s).to_a.map do |mash|
|
60
64
|
build mash
|
61
65
|
end
|
62
66
|
end
|
@@ -72,7 +76,7 @@ module ActiveForce
|
|
72
76
|
changed.each do |field|
|
73
77
|
sobject_hash[mappings[field.to_sym]] = read_attribute(field)
|
74
78
|
end
|
75
|
-
result =
|
79
|
+
result = sfdc_client.update! table_name, sobject_hash
|
76
80
|
changed_attributes.clear
|
77
81
|
result
|
78
82
|
end
|
@@ -96,7 +100,7 @@ module ActiveForce
|
|
96
100
|
value = read_value field
|
97
101
|
hash[name_in_sfdc] = value if value.present?
|
98
102
|
end
|
99
|
-
self.id =
|
103
|
+
self.id = sfdc_client.create! table_name, hash
|
100
104
|
changed_attributes.clear
|
101
105
|
end
|
102
106
|
|
@@ -145,10 +149,18 @@ module ActiveForce
|
|
145
149
|
end
|
146
150
|
|
147
151
|
def self.picklist field
|
148
|
-
picks =
|
152
|
+
picks = sfdc_client.picklist_values(table_name, mappings[field])
|
149
153
|
picks.map do |value|
|
150
154
|
[value[:label], value[:value]]
|
151
155
|
end
|
152
156
|
end
|
157
|
+
|
158
|
+
def self.sfdc_client
|
159
|
+
Client
|
160
|
+
end
|
161
|
+
|
162
|
+
def sfdc_client
|
163
|
+
self.class.sfdc_client
|
164
|
+
end
|
153
165
|
end
|
154
166
|
end
|
data/lib/active_force/version.rb
CHANGED
@@ -3,6 +3,23 @@ require 'active_force/association'
|
|
3
3
|
|
4
4
|
describe ActiveForce::SObject do
|
5
5
|
|
6
|
+
let :post do
|
7
|
+
post = Post.new
|
8
|
+
post.stub(:id).and_return "1"
|
9
|
+
post
|
10
|
+
end
|
11
|
+
|
12
|
+
let :comment do
|
13
|
+
comment = Comment.new
|
14
|
+
comment.stub(:id).and_return "1"
|
15
|
+
comment.stub(:post_id).and_return "1"
|
16
|
+
comment
|
17
|
+
end
|
18
|
+
|
19
|
+
let :client do
|
20
|
+
double("sfdc_client")
|
21
|
+
end
|
22
|
+
|
6
23
|
before do
|
7
24
|
class Post < ActiveForce::SObject
|
8
25
|
self.table_name = "Post__c"
|
@@ -11,6 +28,8 @@ describe ActiveForce::SObject do
|
|
11
28
|
class Comment < ActiveForce::SObject
|
12
29
|
self.table_name = "Comment__c"
|
13
30
|
end
|
31
|
+
|
32
|
+
ActiveForce::SObject.stub(:sfdc_client).and_return client
|
14
33
|
end
|
15
34
|
|
16
35
|
describe "has_many_query" do
|
@@ -19,18 +38,19 @@ describe ActiveForce::SObject do
|
|
19
38
|
class Post < ActiveForce::SObject
|
20
39
|
has_many :comments
|
21
40
|
end
|
41
|
+
end
|
22
42
|
|
23
|
-
|
24
|
-
|
43
|
+
it "should respond to relation method" do
|
44
|
+
expect(post).to respond_to(:comments)
|
25
45
|
end
|
26
46
|
|
27
47
|
it "should return a Query object" do
|
28
|
-
|
48
|
+
post.comments_query.class.should be ActiveForce::Query
|
29
49
|
end
|
30
50
|
|
31
51
|
describe 'to_s' do
|
32
52
|
it "should retrun a OSQL statment" do
|
33
|
-
|
53
|
+
post.comments_query.to_s.should ==
|
34
54
|
"SELECT Id FROM Comment__c WHERE Post__c = '1'"
|
35
55
|
end
|
36
56
|
end
|
@@ -39,48 +59,48 @@ describe ActiveForce::SObject do
|
|
39
59
|
describe 'has_many(options)' do
|
40
60
|
|
41
61
|
it 'should allow to send a different query table name' do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@post = Post.new
|
46
|
-
@post.stub(:id).and_return("1")
|
47
|
-
@post.comments_query.to_s.should ==
|
48
|
-
"SELECT Id FROM Comment WHERE Post__c = '1'"
|
62
|
+
Post.has_many :ugly_comments, { model: Comment }
|
63
|
+
post.comments_query.to_s.should ==
|
64
|
+
"SELECT Id FROM Comment__c WHERE Post__c = '1'"
|
49
65
|
end
|
50
66
|
|
51
|
-
it 'should allow to change the
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
@post = Post.new
|
56
|
-
@post.stub(:id).and_return("1")
|
57
|
-
@post.comments_query.to_s.should ==
|
67
|
+
it 'should allow to change the foreign key' do
|
68
|
+
Post.has_many :comments, { foreign_key: 'Post' }
|
69
|
+
post.comments_query.to_s.should ==
|
58
70
|
"SELECT Id FROM Comment__c WHERE Post = '1'"
|
59
71
|
end
|
60
72
|
|
61
73
|
it 'should allow to add a where condition' do
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
@post = Post.new
|
66
|
-
@post.stub(:id).and_return("1")
|
67
|
-
@post.comments_query.to_s.should ==
|
74
|
+
Post.has_many :comments, { where: '1 = 1' }
|
75
|
+
post.comments_query.to_s.should ==
|
68
76
|
"SELECT Id FROM Comment__c WHERE 1 = 1 AND Post__c = '1'"
|
69
77
|
end
|
70
78
|
|
71
|
-
it 'should use a convention name for the
|
72
|
-
|
73
|
-
|
74
|
-
|
79
|
+
it 'should use a convention name for the foreign key' do
|
80
|
+
Comment.field :post_id, from: 'PostId'
|
81
|
+
Post.has_many :comments
|
82
|
+
post.comments_query.to_s.should ==
|
83
|
+
"SELECT Id FROM Comment__c WHERE PostId = '1'"
|
84
|
+
end
|
85
|
+
end
|
75
86
|
|
76
|
-
|
77
|
-
has_many :comments
|
78
|
-
end
|
87
|
+
describe "belongs_to" do
|
79
88
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
89
|
+
before do
|
90
|
+
Comment.belongs_to :post
|
91
|
+
client.stub(:query).and_return Restforce::Mash.new(id: 1)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should get the resource it belongs to" do
|
95
|
+
expect(comment.post).to be_instance_of(Post)
|
84
96
|
end
|
97
|
+
|
98
|
+
it "should allow to pass a foreign key as options" do
|
99
|
+
Comment.belongs_to :post, foreign_key: :fancy_post_id
|
100
|
+
comment.stub(:fancy_post_id).and_return "1"
|
101
|
+
client.should_receive(:query).with("SELECT Id FROM Post__c WHERE Id = '1' LIMIT 1")
|
102
|
+
comment.post
|
103
|
+
end
|
104
|
+
|
85
105
|
end
|
86
|
-
end
|
106
|
+
end
|
@@ -64,4 +64,29 @@ describe ActiveForce::SObject do
|
|
64
64
|
|
65
65
|
end
|
66
66
|
|
67
|
+
describe "#count" do
|
68
|
+
let(:count_response){ [Restforce::Mash.new(expr0: 1)] }
|
69
|
+
|
70
|
+
it "responds to count" do
|
71
|
+
Whizbang.should respond_to(:count)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "sends the query to the client" do
|
75
|
+
Client.should_receive(:query).and_return(count_response)
|
76
|
+
expect(Whizbang.count).to eq(1)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#find_by" do
|
82
|
+
it "responds to find_by" do
|
83
|
+
Whizbang.should respond_to(:find_by)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should query the client, with the SFDC field names and correctly enclosed values" do
|
87
|
+
Client.should_receive(:query).with("SELECT Id FROM Whizbang__c WHERE Id = 123 AND Text_Label = 'foo'")
|
88
|
+
Whizbang.find_by id: 123, text: "foo"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
67
92
|
end
|
@@ -81,7 +81,7 @@ describe ActiveForce::Query do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should add a order condition in the statment with WHERE and LIMIT" do
|
84
|
-
@query.where("condition1 = 1").order("name desc").limit(1).to_s.should ==
|
84
|
+
@query.where("condition1 = 1").order("name desc").limit(1).to_s.should ==
|
85
85
|
"SELECT Id, name, etc FROM table_name WHERE condition1 = 1 ORDER BY name desc LIMIT 1"
|
86
86
|
end
|
87
87
|
end
|
@@ -93,9 +93,57 @@ describe ActiveForce::Query do
|
|
93
93
|
@join.fields ['name', 'etc']
|
94
94
|
end
|
95
95
|
|
96
|
-
it '
|
96
|
+
it 'should add another select statment on the current select' do
|
97
97
|
@query.join(@join).to_s.should ==
|
98
98
|
'SELECT Id, name, etc, (SELECT Id, name, etc FROM join_table_name) FROM table_name'
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
|
+
describe '.first' do
|
103
|
+
it 'should return the query for the first record' do
|
104
|
+
@query.first.to_s.should ==
|
105
|
+
'SELECT Id, name, etc FROM table_name LIMIT 1'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '.last' do
|
110
|
+
it 'should return the query for the last record' do
|
111
|
+
@query.last.to_s.should ==
|
112
|
+
'SELECT Id, name, etc FROM table_name ORDER BY Id DESC LIMIT 1'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe ".count" do
|
117
|
+
it "should return the query for getting the row count" do
|
118
|
+
@query.count.to_s.should ==
|
119
|
+
'SELECT count(Id) FROM table_name'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should work with a condition" do
|
123
|
+
@query.where("name = 'cool'").count.to_s.should ==
|
124
|
+
"SELECT count(Id) FROM table_name WHERE name = 'cool'"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '.options' do
|
129
|
+
it 'should add a where if the option has a where condition' do
|
130
|
+
@query.options(where: 'var = 1').to_s.should ==
|
131
|
+
"SELECT Id, name, etc FROM table_name WHERE var = 1"
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should add a limit if the option has a limit condition' do
|
135
|
+
@query.options(limit: 1).to_s.should ==
|
136
|
+
"SELECT Id, name, etc FROM table_name LIMIT 1"
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should add a order if the option has a order condition' do
|
140
|
+
@query.options(order: 'name desc').to_s.should ==
|
141
|
+
"SELECT Id, name, etc FROM table_name ORDER BY name desc"
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should work with multiples options' do
|
145
|
+
@query.options(where: 'var = 1', order: 'name desc', limit: 1).to_s.should ==
|
146
|
+
"SELECT Id, name, etc FROM table_name WHERE var = 1 ORDER BY name desc LIMIT 1"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
data/spec/spec_helper.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.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eloy Espinaco
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_attr
|
@@ -57,42 +57,42 @@ dependencies:
|
|
57
57
|
name: rake
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: pry
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - "
|
88
|
+
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - "
|
95
|
+
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
description: Use SalesForce as an ActiveModel
|
@@ -113,6 +113,10 @@ files:
|
|
113
113
|
- lib/active_attr/dirty.rb
|
114
114
|
- lib/active_force.rb
|
115
115
|
- lib/active_force/association.rb
|
116
|
+
- lib/active_force/association/association.rb
|
117
|
+
- lib/active_force/association/belongs_to_association.rb
|
118
|
+
- lib/active_force/association/has_many_association.rb
|
119
|
+
- lib/active_force/finders.rb
|
116
120
|
- lib/active_force/query.rb
|
117
121
|
- lib/active_force/sobject.rb
|
118
122
|
- lib/active_force/version.rb
|
@@ -128,7 +132,7 @@ files:
|
|
128
132
|
- spec/spec_helper.rb
|
129
133
|
- spec/support/fixture_helpers.rb
|
130
134
|
- spec/support/whizbang.rb
|
131
|
-
homepage:
|
135
|
+
homepage: https://github.com/ionia-corporation/active_force
|
132
136
|
licenses:
|
133
137
|
- MIT
|
134
138
|
metadata: {}
|
@@ -138,9 +142,9 @@ require_paths:
|
|
138
142
|
- lib
|
139
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
140
144
|
requirements:
|
141
|
-
- - "
|
145
|
+
- - "~>"
|
142
146
|
- !ruby/object:Gem::Version
|
143
|
-
version: '0'
|
147
|
+
version: '2.0'
|
144
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
149
|
requirements:
|
146
150
|
- - ">="
|