openstax_salesforce 3.1.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -46
  3. data/Rakefile +2 -5
  4. data/config/initializers/openstax_salesforce.rb +11 -36
  5. data/db/migrate/0_install_openstax_salesforce.rb +1 -0
  6. data/db/migrate/1_drop_openstax_salesforce_users.rb +14 -0
  7. data/lib/openstax/salesforce/active_force.rb +0 -4
  8. data/lib/openstax/salesforce/client.rb +11 -17
  9. data/lib/openstax/salesforce/engine.rb +5 -3
  10. data/lib/openstax/salesforce/remote/campaign.rb +0 -2
  11. data/lib/openstax/salesforce/remote/campaign_member.rb +0 -1
  12. data/lib/openstax/salesforce/remote/opportunity.rb +0 -2
  13. data/lib/openstax/salesforce/remote/school.rb +5 -1
  14. data/lib/openstax/salesforce/remote/term_year.rb +0 -2
  15. data/lib/openstax/salesforce/remote/tutor_course_period.rb +0 -2
  16. data/lib/openstax/salesforce/spec_helpers.rb +142 -26
  17. data/lib/openstax/salesforce/version.rb +1 -1
  18. data/lib/openstax_salesforce.rb +13 -29
  19. data/lib/tasks/openstax_salesforce_tasks.rake +1 -26
  20. metadata +15 -182
  21. data/app/controllers/openstax/salesforce/application_controller.rb +0 -7
  22. data/app/controllers/openstax/salesforce/settings_controller.rb +0 -20
  23. data/app/helpers/openstax/salesforce/application_helper.rb +0 -11
  24. data/app/models/openstax/salesforce/user.rb +0 -31
  25. data/app/views/openstax/salesforce/settings/show.html.erb +0 -33
  26. data/config/initializers/omniauth.rb +0 -8
  27. data/config/routes.rb +0 -11
  28. data/lib/openstax/salesforce/spec_helpers/salesforce_proxy.rb +0 -121
  29. data/lib/openstax/salesforce/user_missing.rb +0 -3
  30. data/spec/client_spec.rb +0 -10
  31. data/spec/dummy/README.md +0 -28
  32. data/spec/dummy/Rakefile +0 -6
  33. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  34. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  35. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  36. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  37. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  38. data/spec/dummy/bin/bundle +0 -3
  39. data/spec/dummy/bin/rails +0 -4
  40. data/spec/dummy/bin/rake +0 -4
  41. data/spec/dummy/bin/setup +0 -29
  42. data/spec/dummy/config.ru +0 -4
  43. data/spec/dummy/config/application.rb +0 -25
  44. data/spec/dummy/config/boot.rb +0 -5
  45. data/spec/dummy/config/database.yml +0 -25
  46. data/spec/dummy/config/environment.rb +0 -5
  47. data/spec/dummy/config/environments/development.rb +0 -41
  48. data/spec/dummy/config/environments/production.rb +0 -79
  49. data/spec/dummy/config/environments/test.rb +0 -42
  50. data/spec/dummy/config/initializers/assets.rb +0 -11
  51. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  52. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  53. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  54. data/spec/dummy/config/initializers/inflections.rb +0 -16
  55. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  56. data/spec/dummy/config/initializers/session_store.rb +0 -3
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  58. data/spec/dummy/config/locales/en.yml +0 -23
  59. data/spec/dummy/config/routes.rb +0 -4
  60. data/spec/dummy/config/secrets.yml +0 -22
  61. data/spec/dummy/db/schema.rb +0 -25
  62. data/spec/dummy/db/test.sqlite3 +0 -0
  63. data/spec/dummy/log/test.log +0 -2673
  64. data/spec/dummy/public/404.html +0 -67
  65. data/spec/dummy/public/422.html +0 -67
  66. data/spec/dummy/public/500.html +0 -66
  67. data/spec/dummy/public/favicon.ico +0 -0
  68. data/spec/factories/user.rb +0 -17
  69. data/spec/openstax/salesforce/controllers/application_controller_spec.rb +0 -22
  70. data/spec/openstax/salesforce/controllers/settings_controller_spec.rb +0 -80
  71. data/spec/openstax/salesforce/remote/opportunity_spec.rb +0 -11
  72. data/spec/openstax/salesforce/remote/term_year_spec.rb +0 -81
  73. data/spec/openstax/salesforce/remote/tutor_course_period_spec.rb +0 -30
  74. data/spec/openstax/salesforce/spec_helpers_spec.rb +0 -31
  75. data/spec/rails_helper.rb +0 -99
  76. data/spec/routing_spec.rb +0 -9
  77. data/spec/spec_helper.rb +0 -86
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 642a295664f442b241aebad664e8be049d7502b7214692b68e2c78453878b9d5
4
- data.tar.gz: 226065fdabfaa97921ac1421fc2a7c695d14bcb00c0df14f030d98b5d7fa25ea
3
+ metadata.gz: 14c81d5276f1b4546a71576f11a51bcbbece688179ecece3c1a16eb5ce1e0505
4
+ data.tar.gz: b36cd9baf5221bafdcf0249af842f652bd6b14cf17c95baa93d6204d73834bc6
5
5
  SHA512:
6
- metadata.gz: 331d883ba687b7420ced572bc000d9ebe9cf181c1c8296c4b99b1f58cfb2221d2ff54927aaaf1d02eaa0991a49ee87336addd22909d95849638854ca3a8ea086
7
- data.tar.gz: 1faddc1b36e3e2825369c5415c32fd9cb1e675c074d11c0110f7b9acf0b145544fe7df056c070c74c3a6b9a6a37c9e6df127b7b25c8690419363b688dd633a81
6
+ metadata.gz: 0fe8bf95df2a47a2e418559209e369eeab624349b24f27458a8851d1970ce69957970d2f643fc8d1375912438c91494e80be5eaa9f1ee92b2b542e9420f25825
7
+ data.tar.gz: df0905acc8e78cc28482d55cceb0a637a5b7502ef01905a7cd87ee90be2dd1722e34055cce104242375eec7c5726ed870b9a41805f74dd0007a1b0fc7fda0206
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 with the OpenStax Salesforce instance.
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 these line to your application's Gemfile:
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 migration and the initializer to your application:
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
- your needs. Pay particular attention to `authenticate_admin_proc`,
65
- as you will be unable to access the setup pages until this proc is setup to return
66
- `true` for your admins.
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
- ## Specs in Parent App
53
+ ### Specs in Parent App
75
54
 
76
- There's a helper you can include in your parent app's salesforce specs. It isn't automatically
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(:spec => 'app:db:test:prepare')
25
+ RSpec::Core::RakeTask.new :spec
29
26
 
30
- task :default => :spec
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
- # Layout to be used for OpenStax::Salesforce's controllers
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
- # The following sandbox tokens are used for specs to connect to a sandbox Salesforce
26
- # instance.
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
- # Change this to true if you want to call the omniauth setup on your own
34
- config.skip_automatic_omniauth_setup = false
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
- # If `check_sandbox_instance_url` is true (default), the spec helper that
37
- # uses the instance URL will checks that the URL starts with "cs", which
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
-
@@ -1,3 +1,4 @@
1
+ # TODO: Remove after all servers have been migrated
1
2
  class InstallOpenStaxSalesforce < ActiveRecord::Migration[4.2]
2
3
  def change
3
4
  create_table :openstax_salesforce_users do |t|
@@ -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
- user = OpenStax::Salesforce::User.first
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
- client_key = OpenStax::Salesforce.configuration.salesforce_client_key
10
- client_secret = OpenStax::Salesforce.configuration.salesforce_client_secret
6
+ configuration.validate!
11
7
 
12
- raise(IllegalState, "The Salesforce key is missing") if client_key.nil?
13
- raise(IllegalState, "The Salesforce secret is missing") if client_secret.nil?
14
-
15
- super(host: OpenStax::Salesforce.configuration.salesforce_login_domain,
16
- oauth_token: user.oauth_token,
17
- refresh_token: user.refresh_token,
18
- instance_url: user.instance_url,
19
- client_id: client_key,
20
- client_secret: client_secret,
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::Salesforce
6
- class Engine < ::Rails::Engine
7
- isolate_namespace OpenStax::Salesforce
5
+ module OpenStax
6
+ module Salesforce
7
+ class Engine < ::Rails::Engine
8
+ isolate_namespace OpenStax::Salesforce
9
+ end
8
10
  end
9
11
  end
@@ -1,10 +1,8 @@
1
1
  module OpenStax::Salesforce::Remote
2
2
  class Campaign < ActiveForce::SObject
3
-
4
3
  field :is_active, from: "IsActive", as: :boolean
5
4
  field :name, from: "Name"
6
5
 
7
6
  self.table_name = 'Campaign'
8
-
9
7
  end
10
8
  end
@@ -1,6 +1,5 @@
1
1
  module OpenStax::Salesforce::Remote
2
2
  class CampaignMember < ActiveForce::SObject
3
-
4
3
  field :campaign_id, from: "CampaignId"
5
4
  field :contact_id, from: "ContactId"
6
5
  field :accounts_uuid, from: "accounts_uuid__c"
@@ -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, from: "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