openstax_salesforce 3.0.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -46
- data/Rakefile +2 -5
- data/config/initializers/openstax_salesforce.rb +11 -36
- data/db/migrate/0_install_openstax_salesforce.rb +1 -0
- data/db/migrate/1_drop_openstax_salesforce_users.rb +14 -0
- data/lib/openstax/salesforce/active_force.rb +0 -4
- data/lib/openstax/salesforce/client.rb +11 -17
- data/lib/openstax/salesforce/engine.rb +5 -3
- data/lib/openstax/salesforce/remote/campaign.rb +0 -2
- data/lib/openstax/salesforce/remote/campaign_member.rb +0 -1
- data/lib/openstax/salesforce/remote/contact.rb +1 -0
- data/lib/openstax/salesforce/remote/opportunity.rb +0 -2
- data/lib/openstax/salesforce/remote/school.rb +5 -1
- data/lib/openstax/salesforce/remote/term_year.rb +0 -2
- data/lib/openstax/salesforce/remote/tutor_course_period.rb +0 -2
- data/lib/openstax/salesforce/spec_helpers.rb +142 -26
- data/lib/openstax/salesforce/version.rb +1 -1
- data/lib/openstax_salesforce.rb +13 -29
- data/lib/tasks/openstax_salesforce_tasks.rake +1 -26
- metadata +16 -179
- data/app/controllers/openstax/salesforce/application_controller.rb +0 -7
- data/app/controllers/openstax/salesforce/settings_controller.rb +0 -20
- data/app/helpers/openstax/salesforce/application_helper.rb +0 -11
- data/app/models/openstax/salesforce/user.rb +0 -31
- data/app/views/openstax/salesforce/settings/show.html.erb +0 -33
- data/config/initializers/omniauth.rb +0 -8
- data/config/routes.rb +0 -11
- data/lib/openstax/salesforce/spec_helpers/salesforce_proxy.rb +0 -121
- data/lib/openstax/salesforce/user_missing.rb +0 -3
- data/spec/client_spec.rb +0 -10
- data/spec/dummy/README.md +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -25
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -79
- data/spec/dummy/config/environments/test.rb +0 -42
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -4
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +0 -25
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -15
- data/spec/dummy/log/test.log +0 -1915
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/user.rb +0 -17
- data/spec/openstax/salesforce/controllers/application_controller_spec.rb +0 -22
- data/spec/openstax/salesforce/controllers/settings_controller_spec.rb +0 -80
- data/spec/openstax/salesforce/remote/opportunity_spec.rb +0 -11
- data/spec/openstax/salesforce/remote/term_year_spec.rb +0 -81
- data/spec/openstax/salesforce/remote/tutor_course_period_spec.rb +0 -30
- data/spec/openstax/salesforce/spec_helpers_spec.rb +0 -31
- data/spec/rails_helper.rb +0 -99
- data/spec/routing_spec.rb +0 -9
- data/spec/spec_helper.rb +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3e95723e60a5ef4c192f0fdd72a60adcb297ecd74898b66b9d5da7717ff0da2
|
4
|
+
data.tar.gz: ae495414e4c8aeb283987f40d9877d5805274ffad92ca396caffa5fc57ff9ed2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d25955fc494e054d17b94738f5a495f9681082a496577d90171d205583f58c8353526ca7dfdf63d9b31b0d5772ba48eb511effdd22343f05afa9ec4e4a25984e
|
7
|
+
data.tar.gz: 38fe1cfa437ee9de0f7ebd148b5d5e9fb8b94543f2a2b5900283fe81c28cfd93bda313ccee8cdc536c5d2363efb3022e9dfdf2f632abbc1e00f35e37dbbe3f8c
|
data/README.md
CHANGED
@@ -4,17 +4,15 @@
|
|
4
4
|
[![Build Status](https://travis-ci.org/openstax/openstax_salesforce.svg?branch=master)](https://travis-ci.org/openstax/openstax_salesforce)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/openstax/openstax_salesforce/badges/gpa.svg)](https://codeclimate.com/github/openstax/openstax_salesforce)
|
6
6
|
|
7
|
-
OpenStax::Salesforce is a Rails engine used by OpenStax projects to communicate
|
7
|
+
OpenStax::Salesforce is a Rails engine used by OpenStax projects to communicate
|
8
|
+
with the OpenStax Salesforce instance.
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
11
|
-
Add
|
12
|
+
Add this line to your application's Gemfile:
|
12
13
|
|
13
14
|
```rb
|
14
15
|
gem 'openstax_salesforce'
|
15
|
-
|
16
|
-
# ActiveForce fork that supports Ruby >= 2.1 and stubbable stdout
|
17
|
-
gem 'active_force', git: 'https://github.com/openstax/active_force', ref: '7caac17'
|
18
16
|
```
|
19
17
|
|
20
18
|
And then execute:
|
@@ -29,65 +27,38 @@ Or install it yourself:
|
|
29
27
|
$ gem install openstax_salesforce
|
30
28
|
```
|
31
29
|
|
32
|
-
Then execute the following command to copy the necessary
|
30
|
+
Then execute the following command to copy the necessary initializer to your application:
|
33
31
|
|
34
32
|
```sh
|
35
33
|
$ rake openstax_salesforce:install
|
36
34
|
```
|
37
35
|
|
38
|
-
And then migrate your database:
|
39
|
-
|
40
|
-
```sh
|
41
|
-
$ rake db:migrate
|
42
|
-
```
|
43
|
-
|
44
|
-
Also add OpenStax::Salesforce to your application's routes:
|
45
|
-
|
46
|
-
```rb
|
47
|
-
mount OpenStax::Salesforce::Engine, at: "/salesforce"
|
48
|
-
OpenStax::Salesforce.set_top_level_routes(self)
|
49
|
-
```
|
50
|
-
|
51
|
-
The `set_top_level_routes` should be called at the top level inside `routes.rb`. It adds oauth callback
|
52
|
-
routes at the top level.
|
53
|
-
|
54
|
-
And provide a link on your site for administrators to access the engine.
|
55
|
-
|
56
|
-
```erb
|
57
|
-
<%= link_to 'Salesforce Setup', openstax_salesforce_path %>
|
58
|
-
```
|
59
|
-
|
60
36
|
## Configuration
|
61
37
|
|
62
38
|
After installation, the initializer for OpenStax::Salesforce will be located under
|
63
|
-
`config/initializers/openstax_salesforce.rb`. Make sure to configure it to suit
|
64
|
-
|
65
|
-
|
66
|
-
|
39
|
+
`config/initializers/openstax_salesforce.rb`. Make sure to configure it to suit your needs.
|
40
|
+
|
41
|
+
You will need the following information from Salesforce:
|
42
|
+
- Your username (append .sandboxname if using a sandbox)
|
43
|
+
- Your password
|
44
|
+
- Your security token
|
45
|
+
- Connected App's client key
|
46
|
+
- Connected App's client secret
|
47
|
+
Enter all the above information in the initializer, secrets.yml or environment variables.
|
67
48
|
|
68
49
|
## Testing
|
69
50
|
|
70
|
-
From the gem's main folder, run `bundle install
|
71
|
-
`bundle exec rake db:migrate` and then
|
72
|
-
`bundle exec rake` to run all the specs.
|
51
|
+
From the gem's main folder, run `bundle install` and then `bundle exec rake` to run all the specs.
|
73
52
|
|
74
|
-
|
53
|
+
### Specs in Parent App
|
75
54
|
|
76
|
-
There's a helper you can include in your parent app's salesforce specs.
|
77
|
-
required by this engine, so you have to do it manually in your spec:
|
55
|
+
There's a helper you can include in your parent app's salesforce specs.
|
56
|
+
It isn't automatically required by this engine, so you have to do it manually in your spec:
|
78
57
|
|
79
58
|
```ruby
|
80
59
|
require 'openstax/salesforce/spec_helper'
|
81
60
|
```
|
82
61
|
|
83
|
-
If the oauth token in `OpenStax::Salesforce::User.first` expires, you can update it with
|
84
|
-
|
85
|
-
```ruby
|
86
|
-
OpenStax::Salesforce::User.first.refresh_oauth_token!
|
87
|
-
```
|
88
|
-
|
89
|
-
and then copy that token into your spec setup.
|
90
|
-
|
91
62
|
## Contributing
|
92
63
|
|
93
64
|
1. Fork it
|
data/Rakefile
CHANGED
@@ -14,9 +14,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
17
|
-
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
-
load 'rails/tasks/engine.rake'
|
19
|
-
|
20
17
|
load 'rails/tasks/statistics.rake'
|
21
18
|
|
22
19
|
Bundler::GemHelper.install_tasks
|
@@ -25,6 +22,6 @@ require 'rspec/core'
|
|
25
22
|
require 'rspec/core/rake_task'
|
26
23
|
|
27
24
|
desc 'Run all specs in spec directory (excluding plugin specs)'
|
28
|
-
RSpec::Core::RakeTask.new
|
25
|
+
RSpec::Core::RakeTask.new :spec
|
29
26
|
|
30
|
-
task :
|
27
|
+
task default: :spec
|
@@ -2,45 +2,20 @@
|
|
2
2
|
# also be copied to the application's initializers by running the install
|
3
3
|
# task. Because this code can get run multiple times, make sure to only put
|
4
4
|
# code here that is amenable to that.
|
5
|
-
|
6
5
|
OpenStax::Salesforce.configure do |config|
|
7
|
-
|
8
|
-
config.layout = 'application'
|
9
|
-
|
10
|
-
# Proc called with an argument of the controller where this is called.
|
11
|
-
# This proc is called when a user tries to access the engine's controllers.
|
12
|
-
# Should raise an exception, render or redirect unless the user is a manager
|
13
|
-
# or admin. The default renders 403 Forbidden for all users.
|
14
|
-
config.authenticate_admin_proc = ->(controller) {
|
15
|
-
controller.head(:forbidden)
|
16
|
-
}
|
17
|
-
|
18
|
-
# Consumer key and secret for connecting to the Salesforce app
|
19
|
-
config.salesforce_client_key = 'put_real_key_value_here'
|
20
|
-
config.salesforce_client_secret = 'put_real_secret_value_here'
|
21
|
-
|
22
|
-
# Uncomment this to override the login site for sandbox instances; ok to be nil
|
23
|
-
# config.salesforce_login_site = 'https://test.salesforce.com'
|
6
|
+
salesforce_secrets = Rails.application.secrets.salesforce
|
24
7
|
|
25
|
-
|
26
|
-
|
27
|
-
if Rails.env.test?
|
28
|
-
config.sandbox_oauth_token = 'put_real_value_here'
|
29
|
-
config.sandbox_refresh_token = 'put_real_value_here'
|
30
|
-
config.sandbox_instance_url = 'put_real_value_here'
|
8
|
+
if salesforce_secrets.nil?
|
9
|
+
raise "Add a `salesforce` section to your Rails secrets!"
|
31
10
|
end
|
32
11
|
|
33
|
-
#
|
34
|
-
config.
|
12
|
+
# Username, client id, instance url and private key for connecting to the Salesforce app
|
13
|
+
config.username = salesforce_secrets[:username]
|
14
|
+
config.password = salesforce_secrets[:password]
|
15
|
+
config.security_token = salesforce_secrets[:security_token]
|
16
|
+
config.consumer_key = salesforce_secrets[:consumer_key]
|
17
|
+
config.consumer_secret = salesforce_secrets[:consumer_secret]
|
35
18
|
|
36
|
-
|
37
|
-
|
38
|
-
# indicates that the instance is a sandbox.
|
39
|
-
config.check_sandbox_instance_url = true
|
40
|
-
|
41
|
-
# A way to customize page headings. Sometimes apps fold the page heading
|
42
|
-
# into the layout in different ways.
|
43
|
-
config.page_heading_proc = ->(view, text) { "<h2>#{text}</h2>".html_safe }
|
19
|
+
config.api_version = salesforce_secrets.fetch :api_version, '37.0'
|
20
|
+
config.login_domain = salesforce_secrets.fetch :login_domain, 'test.salesforce.com'
|
44
21
|
end
|
45
|
-
|
46
|
-
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# TODO: Remove after all servers have been migrated
|
2
|
+
class DropOpenStaxSalesforceUsers < ActiveRecord::Migration[4.2]
|
3
|
+
def change
|
4
|
+
drop_table :openstax_salesforce_users do |t|
|
5
|
+
t.string :name
|
6
|
+
t.string :uid, null: false
|
7
|
+
t.string :oauth_token, null: false
|
8
|
+
t.string :refresh_token, null: false
|
9
|
+
t.string :instance_url, null: false
|
10
|
+
|
11
|
+
t.timestamps null: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
# Monkey patching
|
2
2
|
|
3
3
|
module ActiveForce
|
4
|
-
|
5
4
|
class << self
|
6
|
-
|
7
5
|
# Use a lazy setting of the client so that migrations etc are in place
|
8
6
|
# to allow the Client to be successfully instantiated.
|
9
7
|
alias_method :original_sfdc_client, :sfdc_client
|
@@ -17,7 +15,6 @@ module ActiveForce
|
|
17
15
|
def clear_sfdc_client!
|
18
16
|
self.sfdc_client = nil
|
19
17
|
end
|
20
|
-
|
21
18
|
end
|
22
19
|
|
23
20
|
class SObject
|
@@ -34,5 +31,4 @@ module ActiveForce
|
|
34
31
|
# access to the original implementation
|
35
32
|
singleton_class.send(:alias_method, :original_query, :query)
|
36
33
|
end
|
37
|
-
|
38
34
|
end
|
@@ -1,25 +1,19 @@
|
|
1
1
|
module OpenStax::Salesforce
|
2
2
|
class Client < ::Restforce::Data::Client
|
3
|
-
|
4
3
|
def initialize
|
5
|
-
|
6
|
-
|
7
|
-
raise(UserMissing, "The Salesforce client was requested but no user is available.") if user.nil?
|
4
|
+
configuration = OpenStax::Salesforce.configuration
|
8
5
|
|
9
|
-
|
10
|
-
client_secret = OpenStax::Salesforce.configuration.salesforce_client_secret
|
6
|
+
configuration.validate!
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
api_version: '37.0')
|
8
|
+
super(
|
9
|
+
username: configuration.username,
|
10
|
+
password: configuration.password,
|
11
|
+
security_token: configuration.security_token,
|
12
|
+
client_id: configuration.consumer_key,
|
13
|
+
client_secret: configuration.consumer_secret,
|
14
|
+
api_version: configuration.api_version,
|
15
|
+
host: configuration.login_domain
|
16
|
+
)
|
22
17
|
end
|
23
|
-
|
24
18
|
end
|
25
19
|
end
|
@@ -2,8 +2,10 @@ ActiveSupport::Inflector.inflections do |inflect|
|
|
2
2
|
inflect.acronym 'OpenStax'
|
3
3
|
end
|
4
4
|
|
5
|
-
module OpenStax
|
6
|
-
|
7
|
-
|
5
|
+
module OpenStax
|
6
|
+
module Salesforce
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
isolate_namespace OpenStax::Salesforce
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
@@ -16,6 +16,7 @@ module OpenStax::Salesforce::Remote
|
|
16
16
|
field :send_faculty_verification_to, from: "SendFacultyVerificationTo__c"
|
17
17
|
field :all_emails, from: "All_Emails__c"
|
18
18
|
field :confirmed_emails, from: "Confirmed_Emails__c"
|
19
|
+
field :adoption_status, from: "Adoption_Status__c"
|
19
20
|
|
20
21
|
self.table_name = 'Contact'
|
21
22
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module OpenStax::Salesforce::Remote
|
2
2
|
class Opportunity < ActiveForce::SObject
|
3
|
-
|
4
3
|
field :term_year, from: "TermYear__c"
|
5
4
|
field :book_name, from: "Book_Text__c"
|
6
5
|
field :contact_id, from: "Contact__c"
|
@@ -11,6 +10,5 @@ module OpenStax::Salesforce::Remote
|
|
11
10
|
def term_year_object
|
12
11
|
@term_year_object ||= OpenStax::Salesforce::Remote::TermYear.from_string(term_year)
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
16
14
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module OpenStax::Salesforce::Remote
|
2
2
|
class School < ActiveForce::SObject
|
3
|
-
field :name,
|
3
|
+
field :name, from: 'Name'
|
4
|
+
field :type, from: 'Type'
|
5
|
+
field :school_location, from: 'School_Location__c'
|
6
|
+
field :is_kip, from: 'K_I_P__c', as: :boolean
|
7
|
+
field :is_child_of_kip, from: 'child_of_kip__c', as: :boolean
|
4
8
|
|
5
9
|
self.table_name = 'Account'
|
6
10
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module OpenStax::Salesforce::Remote
|
2
2
|
class TermYear
|
3
|
-
|
4
3
|
# TermYear strings in Salesforce look like:
|
5
4
|
# 2015 - 16 Fall
|
6
5
|
# 2015 - 16 Spring
|
@@ -75,6 +74,5 @@ module OpenStax::Salesforce::Remote
|
|
75
74
|
end
|
76
75
|
|
77
76
|
class ParseError < StandardError; end
|
78
|
-
|
79
77
|
end
|
80
78
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module OpenStax::Salesforce::Remote
|
2
2
|
class TutorCoursePeriod < ActiveForce::SObject
|
3
|
-
|
4
3
|
field :num_teachers, from: "Active_Teachers__c", as: :int
|
5
4
|
field :base_year, from: "Base_Year__c", as: :int
|
6
5
|
field :book_name, from: "Book_Name__c"
|
@@ -44,6 +43,5 @@ module OpenStax::Salesforce::Remote
|
|
44
43
|
|
45
44
|
STATUS_APPROVED = "Approved"
|
46
45
|
STATUS_ARCHIVED = "ArchivedPeriod"
|
47
|
-
|
48
46
|
end
|
49
47
|
end
|
@@ -1,30 +1,4 @@
|
|
1
|
-
require 'openstax/salesforce/spec_helpers/salesforce_proxy'
|
2
|
-
|
3
1
|
module OpenStax::Salesforce::SpecHelpers
|
4
|
-
|
5
|
-
def load_salesforce_user
|
6
|
-
clear_salesforce_user
|
7
|
-
|
8
|
-
config = OpenStax::Salesforce.configuration
|
9
|
-
sf_user = OpenStax::Salesforce::User.new
|
10
|
-
|
11
|
-
sf_user.name = "some name"
|
12
|
-
sf_user.uid = "whatever"
|
13
|
-
sf_user.oauth_token = config.sandbox_oauth_token
|
14
|
-
sf_user.refresh_token = config.sandbox_refresh_token
|
15
|
-
sf_user.instance_url = config.sandbox_instance_url.tap do |url|
|
16
|
-
if config.check_sandbox_instance_url && !url.match(/\/\/cs/)
|
17
|
-
raise "Salesforce sandbox instance URL (#{url}) does not have the expected form!"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
sf_user.save!
|
22
|
-
end
|
23
|
-
|
24
|
-
def clear_salesforce_user
|
25
|
-
OpenStax::Salesforce::User.destroy_all
|
26
|
-
end
|
27
|
-
|
28
2
|
# Uses knowledge of how `SalesforceProxy` methods create new SF records using its
|
29
3
|
# `unique_token` to create the conditions you'd otherwise have to manually set
|
30
4
|
# when calling `limit_salesforce_queries`.
|
@@ -81,4 +55,146 @@ module OpenStax::Salesforce::SpecHelpers
|
|
81
55
|
end
|
82
56
|
end
|
83
57
|
|
58
|
+
class SalesforceProxy
|
59
|
+
include OpenStax::Salesforce::Remote
|
60
|
+
|
61
|
+
def initialize
|
62
|
+
# For cassette consistency, to ensure specs always get new tokens
|
63
|
+
ActiveForce.clear_sfdc_client!
|
64
|
+
end
|
65
|
+
|
66
|
+
# Used to filter records to the scope of one spec
|
67
|
+
def reset_unique_token(token = SecureRandom.hex(10))
|
68
|
+
@unique_token = token
|
69
|
+
end
|
70
|
+
|
71
|
+
def clear_unique_token
|
72
|
+
@unique_token = nil
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_contact(first_name: nil, last_name: nil, school_name: "JP University",
|
76
|
+
email: nil, email_alt: nil, faculty_verified: nil, school_type: nil)
|
77
|
+
ensure_schools_exist([school_name])
|
78
|
+
|
79
|
+
Contact.new(
|
80
|
+
first_name: first_name || Faker::Name.first_name,
|
81
|
+
last_name: last_name!(last_name),
|
82
|
+
school_id: school_id(school_name),
|
83
|
+
email: email,
|
84
|
+
email_alt: email_alt,
|
85
|
+
faculty_verified: faculty_verified,
|
86
|
+
school_type: school_type
|
87
|
+
).tap do |contact|
|
88
|
+
if !contact.save
|
89
|
+
raise "Could not save SF contact: #{contact.errors}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def new_lead(email:, status: nil, last_name: nil, source: nil, school_name: "JP University")
|
95
|
+
Lead.new(
|
96
|
+
email: email,
|
97
|
+
status: status,
|
98
|
+
last_name: last_name!(last_name),
|
99
|
+
school: school_name,
|
100
|
+
source: source
|
101
|
+
).tap do |lead|
|
102
|
+
if !lead.save
|
103
|
+
raise "Could not save SF lead: #{lead.errors}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def new_campaign(name: SecureRandom.hex(8))
|
109
|
+
Campaign.new(
|
110
|
+
name: name
|
111
|
+
).tap do |campaign|
|
112
|
+
if !campaign.save
|
113
|
+
raise "Could not save SF Campaign: #{campaign.errors}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def new_campaign_member(contact_id:, campaign_id:)
|
119
|
+
CampaignMember.new(
|
120
|
+
contact_id: contact_id,
|
121
|
+
campaign_id: campaign_id
|
122
|
+
).tap do |campaign_member|
|
123
|
+
if !campaign_member.save
|
124
|
+
raise "Could not save SF Campaign Member: #{campaign_member.errors}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def last_name!(input)
|
130
|
+
"#{input || Faker::Name.last_name}#{@unique_token if @unique_token.present?}"
|
131
|
+
end
|
132
|
+
|
133
|
+
def ensure_books_exist(book_names)
|
134
|
+
@books = OpenStax::Salesforce::Remote::Book.where(name: book_names).to_a
|
135
|
+
|
136
|
+
(book_names - books.map(&:name)).each do |book_name|
|
137
|
+
OpenStax::Salesforce::Remote::Book.new(name: book_name).save!
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def ensure_schools_exist(school_names)
|
142
|
+
@schools = OpenStax::Salesforce::Remote::School.where(name: school_names).to_a
|
143
|
+
|
144
|
+
(school_names - schools.map(&:name)).each do |school_name|
|
145
|
+
OpenStax::Salesforce::Remote::School.new(name: school_name).save!
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def books
|
150
|
+
@books ||= OpenStax::Salesforce::Remote::Book.all
|
151
|
+
end
|
152
|
+
|
153
|
+
def book(name)
|
154
|
+
books.find { |bb| bb.name == name }
|
155
|
+
end
|
156
|
+
|
157
|
+
def book_id(name)
|
158
|
+
book(name).id
|
159
|
+
end
|
160
|
+
|
161
|
+
def schools
|
162
|
+
@schools ||= OpenStax::Salesforce::Remote::School.all
|
163
|
+
end
|
164
|
+
|
165
|
+
def school_id(name)
|
166
|
+
school(name).try(:id)
|
167
|
+
end
|
168
|
+
|
169
|
+
def school(name)
|
170
|
+
schools.find { |ss| ss.name == name }
|
171
|
+
end
|
172
|
+
|
173
|
+
def setup_cassette
|
174
|
+
VCR.configure do |config|
|
175
|
+
config.define_cassette_placeholder('<salesforce_instance_url>') do
|
176
|
+
'https://example.salesforce.com'
|
177
|
+
end
|
178
|
+
config.define_cassette_placeholder('<salesforce_instance_url_lower>') do
|
179
|
+
'https://example.salesforce.com'
|
180
|
+
end
|
181
|
+
authentication = ActiveForce.sfdc_client.authenticate!
|
182
|
+
config.define_cassette_placeholder('<salesforce_instance_url>') do
|
183
|
+
authentication.instance_url
|
184
|
+
end
|
185
|
+
config.define_cassette_placeholder('<salesforce_instance_url_lower>') do
|
186
|
+
authentication.instance_url.downcase
|
187
|
+
end
|
188
|
+
config.define_cassette_placeholder('<salesforce_id>') do
|
189
|
+
authentication.id
|
190
|
+
end
|
191
|
+
config.define_cassette_placeholder('<salesforce_access_token>') do
|
192
|
+
authentication.access_token
|
193
|
+
end
|
194
|
+
config.define_cassette_placeholder('<salesforce_signature>') do
|
195
|
+
authentication.signature
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
84
200
|
end
|