Skip to content

Commit

Permalink
Update all gem to support rails 5 (#21)
Browse files Browse the repository at this point in the history
* - Update all gem to support rails 5
- Ruby version support only for >= 2
- Better handling for nulldb
- Add bin/console for better console access
- Add support for scoped in all version of Rails >= 3
- Fix time parsing bug

* Fix travis
  • Loading branch information
vishalvijay committed Jan 30, 2018
1 parent 1122d29 commit a4e3382
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 75 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sudo: false
language: ruby
rvm:
- 2.1.5
before_install: gem install bundler -v 1.15.1
- 2.2.2
before_install: gem install bundler -v 1.16.1
81 changes: 41 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
PATH
remote: .
specs:
salesforce-orm (1.2.6)
activerecord (~> 3)
activerecord-nulldb-adapter (~> 0)
restforce (~> 2.5)
salesforce-orm (1.3.0)
activerecord
activerecord-nulldb-adapter
restforce

GEM
remote: https://rubygems.org/
specs:
activemodel (3.2.22.5)
activesupport (= 3.2.22.5)
builder (~> 3.0.0)
activerecord (3.2.22.5)
activemodel (= 3.2.22.5)
activesupport (= 3.2.22.5)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activemodel (5.1.4)
activesupport (= 5.1.4)
activerecord (5.1.4)
activemodel (= 5.1.4)
activesupport (= 5.1.4)
arel (~> 8.0)
activerecord-nulldb-adapter (0.3.7)
activerecord (>= 2.0.0)
activesupport (3.2.22.5)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
arel (3.0.3)
builder (3.0.4)
byebug (9.0.5)
activesupport (5.1.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (8.0.0)
byebug (10.0.0)
concurrent-ruby (1.0.5)
diff-lcs (1.3)
faraday (0.13.1)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
hashie (3.5.6)
i18n (0.9.1)
hashie (3.5.7)
i18n (0.9.3)
concurrent-ruby (~> 1.0)
json (2.1.0)
multi_json (1.12.2)
minitest (5.11.3)
multipart-post (2.0.0)
rake (10.4.2)
rake (12.3.0)
restforce (2.5.3)
faraday (>= 0.9.0, <= 1.0)
faraday_middleware (>= 0.8.8, <= 1.0)
hashie (>= 1.2.0, < 4.0)
json (>= 1.7.5)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
tzinfo (0.3.53)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
thread_safe (0.3.6)
tzinfo (1.2.4)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.15)
byebug (~> 9)
rake (~> 10.0)
rspec (~> 3.0)
bundler
byebug
rake
rspec
salesforce-orm!

BUNDLED WITH
1.15.1
1.16.1
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ In rails, write below code in application.rb or environment specific file

Other projects, run it before you use SaleforceOrm

```
```ruby
SaleforceOrm::Configuration.restforce_config = {
... # Restforce configuration
}
Expand All @@ -41,7 +41,7 @@ Other projects, run it before you use SaleforceOrm

Create object class

```
```ruby
class SampleObject < SalesforceOrm::ObjectBase
end
```
Expand All @@ -50,13 +50,13 @@ end

Default object name is `class.name`

```
```ruby
SampleObject
```

If you have a custom object name,

```
```ruby
class SampleObject < SalesforceOrm::ObjectBase
self.object_name = 'SampleObject__c'
end
Expand All @@ -68,7 +68,7 @@ Field map is used for create, update actions. This can be used for aliasing the

Default field map for `SampleObject`

```
```ruby
{
id: :Id,
created_at: :CreatedAt,
Expand All @@ -78,7 +78,7 @@ Default field map for `SampleObject`

If you wanna map more fields for an object

```
```ruby
class SampleObject < SalesforceOrm::ObjectBase
self.field_map = {
field_one: :FieldOne,
Expand All @@ -102,7 +102,7 @@ Default is same data type of given value

Default data type map for `SampleObject`

```
```ruby
{
created_at: :datetime,
updated_at: :datetime
Expand All @@ -111,7 +111,7 @@ Default data type map for `SampleObject`

If you wanna change the data type of some fields

```
```ruby
class SampleObject < SalesforceOrm::ObjectBase
self.data_type_map = {
field_one: :datetime,
Expand All @@ -128,7 +128,7 @@ By default there is no record type configured for any object

To specify a record type,

```
```ruby
class SampleObject < SalesforceOrm::ObjectBase
self.record_type = 'Xyz' # DeveloperName in RecordType object
end
Expand All @@ -146,7 +146,7 @@ Methods are similar to ActiveRecord::Base

Class methods

```
```ruby
SampleObject.[
:create!,
:update_all!,
Expand All @@ -169,7 +169,7 @@ SampleObject.[
```

eg:
```
```ruby
SampleObject.where(id: 'qd')

SampleObject.where(id: ['eqd', 'qqwd'])
Expand All @@ -193,7 +193,7 @@ SampleObject.select('count(id)').all

Instance methods

```
```ruby
SampleObject.[
:update_attributes,
:destroy
Expand All @@ -206,15 +206,15 @@ Other class methods (Specific to SalesforceOrm)

To update an object by id

```
```ruby
SampleObject.update_by_id!('some_id', {feild_one: 'some_value', field_two: 'some_other_value'})
```

#### destroy_by_id!

To destroy an object by id

```
```ruby
SampleObject.destroy_by_id!('some_id')
```

Expand All @@ -226,7 +226,7 @@ To generate, SOQL query (Equavalent to `to_sql`)

To create a new instance of SampleObject

```
```ruby
SampleObject.build({id: 'some id', field_one: 'Some value'})
```

Expand Down
15 changes: 15 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "salesforce-orm"
require "byebug"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
IRB.start
9 changes: 6 additions & 3 deletions lib/salesforce-orm.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Dir[File.expand_path('salesforce-orm/*.rb', File.dirname(__FILE__))].each do |file|
require file
module SalesforceOrm
def self.root
File.dirname __dir__
end
end

module SalesforceOrm
Dir[File.expand_path('salesforce-orm/*.rb', File.dirname(__FILE__))].each do |file|
require file
end
6 changes: 5 additions & 1 deletion lib/salesforce-orm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def select(*args)
end

[
:scoped,
:except,
:where,
:group,
Expand All @@ -99,6 +98,11 @@ def select(*args)
end
end

def scoped(*args)
where(nil)
self
end

def all(*args)
make_query
end
Expand Down
3 changes: 2 additions & 1 deletion lib/salesforce-orm/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class QueryBuilder < ActiveRecord::Base
self.table_name = DUMMY_TABLE_NAME

establish_connection(
adapter: :nulldb
adapter: :nulldb,
schema: (File.join SalesforceOrm.root, 'support', 'schema.rb')
)
end
end
5 changes: 3 additions & 2 deletions lib/salesforce-orm/sql_to_soql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def boolean_data_type_conversion(sql)
end

# TODO: optimize this method
def sql_to_soql(sql)
def sql_to_soql(frozen_sql)
sql = frozen_sql.dup
# Unescape column and table names
sql.gsub!('`', '')

Expand All @@ -50,7 +51,7 @@ def sql_to_soql(sql)
sql.gsub!(/\s+IS\s+/i, ' = ')

# Convert datatime to salesforce format
sql.gsub!(/'(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})'/, '\1T\2Z')
sql.gsub!(/'(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)?'/, '\1T\2Z')

# Convert date to salesforce format
sql.gsub!(/'(\d{4}-\d{2}-\d{2})'/, '\1')
Expand Down
2 changes: 1 addition & 1 deletion lib/salesforce-orm/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SalesforceOrm
VERSION = '1.2.6'.freeze
VERSION = '1.3.0'.freeze
end
16 changes: 8 additions & 8 deletions salesforce-orm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Gem::Specification.new do |s|
s.homepage = 'https://github.com/NestAway/salesforce-orm'
s.license = 'Apache License 2.0'

s.required_ruby_version = '>= 1.9.8'
s.required_ruby_version = '>= 2'
s.require_paths = ['lib']

s.add_dependency 'activerecord', '~> 3'
s.add_dependency 'activerecord-nulldb-adapter', '~> 0'
s.add_dependency 'restforce', '~> 2.5'
s.add_dependency 'activerecord'
s.add_dependency 'activerecord-nulldb-adapter'
s.add_dependency 'restforce'

s.add_development_dependency 'byebug', '~> 9'
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'bundler', '~> 1.15'
s.add_development_dependency 'rake', '~> 10.0'
s.add_development_dependency 'byebug'
s.add_development_dependency 'rspec'
s.add_development_dependency 'bundler'
s.add_development_dependency 'rake'
end
4 changes: 2 additions & 2 deletions spec/object_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ def assign_field_map(new_field_map = nil)
describe 'order' do
it 'should add order by to query' do
soql = SampleObject.scoped.order(:id).to_soql
expect(soql).to eq('SELECT Id, CreatedDate, LastModifiedDate FROM SampleObject ORDER BY Id')
expect(soql).to eq('SELECT Id, CreatedDate, LastModifiedDate FROM SampleObject ORDER BY Id ASC')
end
end

describe 'reorder' do
it 'should reset the previous order' do
soql = SampleObject.scoped.order(:id).reorder(:created_at).to_soql
expect(soql).to eq('SELECT Id, CreatedDate, LastModifiedDate FROM SampleObject ORDER BY CreatedDate')
expect(soql).to eq('SELECT Id, CreatedDate, LastModifiedDate FROM SampleObject ORDER BY CreatedDate ASC')
end
end

Expand Down
File renamed without changes.

0 comments on commit a4e3382

Please sign in to comment.