leap_salesforce 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.gitlab-ci.yml +22 -0
  4. data/.idea/.rakeTasks +7 -0
  5. data/.idea/leap-salesforce.iml +73 -83
  6. data/.idea/misc.xml +1 -0
  7. data/.idea/workspace.xml +563 -358
  8. data/.leap_salesforce.yml +2 -2
  9. data/ChangeLog +5 -0
  10. data/README.md +5 -1
  11. data/Rakefile +3 -3
  12. data/config/environments/prod.rb +4 -0
  13. data/config/general.rb +6 -0
  14. data/exe/leap_salesforce +54 -0
  15. data/leap_salesforce.gemspec +1 -2
  16. data/lib/leap_salesforce/ext/string.rb +6 -1
  17. data/lib/leap_salesforce/generator/default.rb +52 -0
  18. data/lib/leap_salesforce/generator/exe_helpers.rb +29 -0
  19. data/lib/leap_salesforce/generator/generator.rb +60 -0
  20. data/lib/leap_salesforce/generator/soql_enums.rb +4 -2
  21. data/lib/leap_salesforce/generator/soql_objects.rb +29 -44
  22. data/lib/leap_salesforce/generator/templates/.leap_salesforce.yml.erb +9 -0
  23. data/lib/leap_salesforce/generator/templates/.rspec.erb +3 -0
  24. data/lib/leap_salesforce/generator/templates/Gemfile.erb +4 -0
  25. data/lib/leap_salesforce/generator/templates/Rakefile.erb +8 -0
  26. data/lib/leap_salesforce/generator/templates/config/credentials/salesforce_oauth2.yml.erb +3 -0
  27. data/lib/leap_salesforce/generator/templates/config/environments/specific_file.rb.erb +4 -0
  28. data/lib/leap_salesforce/generator/templates/config/general.rb.erb +6 -0
  29. data/lib/leap_salesforce/generator/templates/factory.rb.erb +3 -3
  30. data/lib/leap_salesforce/generator/templates/soql_object.rb.erb +5 -5
  31. data/lib/leap_salesforce/generator/templates/soql_object_field_names.rb.erb +2 -2
  32. data/lib/leap_salesforce/generator/templates/spec/crud_eg_spec.rb.erb +24 -0
  33. data/lib/leap_salesforce/generator/templates/spec/limit_spec.rb.erb +14 -0
  34. data/lib/leap_salesforce/generator/templates/spec/spec_helper.rb.erb +5 -0
  35. data/lib/leap_salesforce/limits.rb +3 -2
  36. data/lib/leap_salesforce/parameters.rb +13 -1
  37. data/lib/leap_salesforce/rake/setup.rake +0 -2
  38. data/lib/leap_salesforce/soql_data/data_relationships.rb +4 -4
  39. data/lib/leap_salesforce/soql_data/soql_data.rb +2 -2
  40. data/lib/leap_salesforce/soql_data/soql_global_data.rb +2 -0
  41. data/lib/leap_salesforce/soql_data/soql_global_object_data.rb +13 -8
  42. data/lib/leap_salesforce/soql_object.rb +49 -0
  43. data/lib/leap_salesforce/users/user.rb +12 -0
  44. data/lib/leap_salesforce/users/users.rb +14 -4
  45. data/lib/leap_salesforce/version.rb +1 -1
  46. data/lib/leap_salesforce.rb +13 -3
  47. metadata +36 -33
  48. data/exe/leap-salesforce +0 -7
  49. data/lib/leap_salesforce/generator/default_fields.rb +0 -13
data/.leap_salesforce.yml CHANGED
@@ -1,4 +1,4 @@
1
- environment: uat
1
+ environment: prod
2
2
  lib_folder: spec/support
3
3
  soql_objects:
4
4
  - Case
@@ -6,5 +6,5 @@ soql_objects:
6
6
  - Document: ContentDocument
7
7
  - User:
8
8
  create_enum: false
9
- - Role: Role__c
9
+ - Broker: Broker__c
10
10
  - Account
data/ChangeLog ADDED
@@ -0,0 +1,5 @@
1
+ Version 0.1.1
2
+ * Enhancements
3
+ * Suggestions for generated factory
4
+ * Begin unit tests
5
+ * Handle Macrons by ensuring they're not copied into Ruby names / Modules
data/README.md CHANGED
@@ -25,6 +25,10 @@ Or install it yourself as:
25
25
 
26
26
  TODO: Write usage instructions here
27
27
 
28
+ ## Docs
29
+
30
+ Technical docs [here](https://www.rubydoc.info/gems/leap_salesforce)
31
+
28
32
  ## Development
29
33
 
30
34
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -41,7 +45,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
41
45
 
42
46
  ## Code of Conduct
43
47
 
44
- Everyone interacting in the SfTest project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/leap-dojo/leap_salesforce/blob/master/CODE_OF_CONDUCT.md).
48
+ Everyone interacting in the LeapSalesforce project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/leap-dojo/leap_salesforce/blob/master/CODE_OF_CONDUCT.md).
45
49
 
46
50
  # Examples
47
51
 
data/Rakefile CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
+ require 'rake/clean'
5
6
 
6
7
  require 'leap_salesforce/rake'
7
8
 
9
+ CLEAN.include 'tmp/*'
8
10
 
9
11
  RSpec::Core::RakeTask.new(:spec)
10
12
 
11
- task default: :spec
13
+ task default: %i[clean spec]
12
14
 
13
- # TODO: This needs to be in one place
14
15
  require 'leap_salesforce'
15
- LeapSalesforce.api_user = LeapSalesforce::Users.where(key: :cet)
16
16
 
17
17
  desc "Create stubs for dynamic methods so they're picked up by the IDE"
18
18
  task :stub do
@@ -0,0 +1,4 @@
1
+ # Files with the format 'env.rb' should be used if
2
+
3
+ Soaspec::OAuth2.debug_oauth = false # Turn this true if you need debug authentication
4
+ Soaspec::SpecLogger.output_to_terminal = false # Turn this to true if you want to see API traffic on the terminal
data/config/general.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add users to LeapSalesforce context. First user is the default
4
+ module LeapSalesforce
5
+ Users.add User.new :admin, 'samuel.garratt@brave-otter-ttxype.com'
6
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+
6
+ require 'thor'
7
+ require 'leap_salesforce/parameters'
8
+ require 'leap_salesforce/generator/generator'
9
+
10
+ module LeapSalesforce
11
+ # Executable for setting up Leap Salesforce
12
+ class Exe < Thor
13
+ include LeapSalesforce::Generator
14
+ include LeapSalesforce::ExeHelpers
15
+
16
+ OAUTH_WIKI = 'https://gitlab.com/leap-dojo/leap_salesforce/wikis/SetUpOAuthApp'
17
+
18
+ desc 'init', 'Create new leap salesforce repository'
19
+ option :setup_done, default: false, type: :boolean, banner: 'Whether setup is done'
20
+ option :client_id, banner: 'OAuth2 client id'
21
+ option :client_secret, banner: 'OAuth2 client secret'
22
+ option :username, banner: 'Username'
23
+ option :user_key, banner: 'Key to identify user by'
24
+ option :password, banner: 'User password'
25
+ option :environment, banner: 'Environment to set automation code up for'
26
+ def init
27
+ # Ask user to create OAuth application by following
28
+ unless options[:setup_done]
29
+ oauth_setup = input_for "Have you set up OAuth application by following #{OAUTH_WIKI} (y/n)?"
30
+ exit if oauth_setup.downcase == 'n'
31
+ end
32
+
33
+ query_for_parameters
34
+ generate_files binding, ['Gemfile', 'Rakefile', '.leap_salesforce.yml', '.rspec',
35
+ { config: ['general.rb', { credentials: 'salesforce_oauth2.yml' }] },
36
+ { spec: %w[spec_helper.rb limit_spec.rb crud_eg_spec.rb] }]
37
+
38
+ environment_content = read_template File.join('config', 'environments', 'specific_file.rb.erb'),
39
+ binding
40
+ generate_file File.join('config', 'environments', "#{@environment}.rb"), environment_content,
41
+ overwrite: false
42
+
43
+ puts 'Initial files created!'
44
+ puts 'Installing gems'
45
+ puts `bundle install`
46
+ puts 'Creating initial Soql objects. See ".leap_salesforce.yml" for list'
47
+ puts `rake leaps:create_soql_objects`
48
+ puts 'Creating enums'
49
+ puts `rake leaps:create_enums`
50
+ end
51
+ end
52
+ end
53
+
54
+ LeapSalesforce::Exe.start(ARGV)
@@ -27,13 +27,12 @@ It reads the Metadata from Salesforce and creates the foundation for API tests.'
27
27
  spec.require_paths = ['lib']
28
28
 
29
29
  spec.add_development_dependency 'bundler', '~> 2.0'
30
- spec.add_development_dependency 'faker'
31
30
  spec.add_development_dependency 'pry'
32
- spec.add_development_dependency 'rake', '~> 10.0'
33
31
  spec.add_development_dependency 'rspec', '~> 3.0'
34
32
  spec.add_development_dependency 'topoisomerase'
35
33
  spec.add_dependency 'activerecord'
36
34
  spec.add_dependency 'factory_bot'
35
+ spec.add_dependency 'faker'
37
36
  spec.add_dependency 'rake'
38
37
  spec.add_dependency 'require_all'
39
38
  spec.add_dependency 'rubocop'
@@ -8,7 +8,12 @@ class String
8
8
  # @todo: Have method of replacing all
9
9
  # @return [String] Remove many complex characters to make a key for a Ruby Hash that is usable
10
10
  def to_key_name
11
- tr(' ,', '_').tr("'/()-:", '').tr('&', '').gsub('<', 'gt').tr('ā', 'a').snakecase.gsub('__', '_')
11
+ tr(' ,-', '_').tr("'/():", '').tr('&', '').gsub('<', 'gt').remove_macrons.snakecase.gsub('__', '_')
12
+ end
13
+
14
+ # @return [String] Return string without macrons, used for filenames and ruby methods
15
+ def remove_macrons
16
+ tr('ā', 'a').tr('ē', 'e').tr('ō', 'o').tr('ī', 'i').tr('ū', 'u')
12
17
  end
13
18
 
14
19
  # A ruby friendly method name that is not taken by keywords like 'class', 'alias'
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LeapSalesforce
4
+ module Default
5
+ # Defaults for various objects within a Factory
6
+ module Factory
7
+ class << self
8
+ # @return [String] String to set Factory field to value specified
9
+ def set(value, use_quotes: nil)
10
+ if use_quotes
11
+ "#{@field['label'].unused_ruby_name} { '#{value}' }"
12
+ else
13
+ "#{@field['label'].unused_ruby_name} { #{value} }"
14
+ end
15
+ end
16
+
17
+ # @return [String] Default value for Factory
18
+ def value_for(field, class_name)
19
+ @field = field
20
+ case field['type']
21
+ when 'string' then set("Faker::Lorem.paragraph_by_chars(#{field['length']})")
22
+ when 'id' then set('Best to not hard code this', use_quotes: true)
23
+ when 'boolean' then set('true')
24
+ when 'picklist' then set("#{class_name}::#{field['name']}.sample")
25
+ when 'reference'
26
+ soql_obj = LeapSalesforce.soql_objects.find { |so| so.backend_name == field['relationshipName'] }&.reference
27
+ if soql_obj
28
+ "association :#{@field['label'].unused_ruby_name}, factory: :#{soql_obj}"
29
+ else
30
+ "# Please add #{field['relationshipName']} to .leap_salesforce.yml to create association for #{field}"
31
+ end
32
+ else
33
+ set("Content depending on #{field['type']}", use_quotes: true)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ # Contains default fields for various out of the box entities to be included in Factory
40
+ module Fields
41
+ class << self
42
+ def contact
43
+ %w[FirstName LastName]
44
+ end
45
+
46
+ def account
47
+ ['Name']
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LeapSalesforce
4
+ # Helpers for LeapSalesforce executable
5
+ module ExeHelpers
6
+ # Return input for query
7
+ # @param [String] query Query to ask on terminal
8
+ # @return [String] User input to store
9
+ def input_for(query)
10
+ puts query
11
+ $stdin.gets.strip
12
+ end
13
+
14
+ # Ask user to enter parameters specific to their Salesforce environment
15
+ def query_for_parameters
16
+ puts 'Please enter the following information to generate files for a new leap_salesforce testing repo'
17
+ # Ask for OAuth credential details
18
+ @client_id = options[:client_id] || input_for('Enter the client id')
19
+ @client_secret = options[:client_secret] || input_for('Enter the client secret')
20
+ @username = options[:username] || input_for('Enter the Salesforce username. It is ideal to start with a System admin' \
21
+ ' so that any necessary metadata can be read')
22
+ @user_key = options[:user_key] || input_for('Enter a key to refer to this user (This will be stored as a Symbol)')
23
+ @password = options[:password] || input_for('Enter password for this user. Recommendation is that 1 password be shared across' \
24
+ ' all test users to be easier to manage')
25
+ @environment = options[:environment] || input_for('Enter the environment you want to set things up for ' \
26
+ '(This will be parameterised so can be changed later)')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+ require 'erb'
3
+ require 'fileutils'
4
+ require_relative 'exe_helpers'
5
+
6
+ module LeapSalesforce
7
+ # Generators for creating code
8
+ module Generator
9
+ # @param [String] filename Relative filename to this file
10
+ # @param [Binding] binding Binding object used for ERB variables
11
+ # @return [String] Interpreted file after calculating ERB for template file passed
12
+ def read_template(filename, binding)
13
+ ERB.new(File.read(File.join(__dir__, 'templates', filename))).result(binding)
14
+ end
15
+
16
+ # Generate file creating necessary folder if necessary
17
+ # @param [String] filename Name of file to generate
18
+ # @param [String] content Content to put within file
19
+ def generate_file(filename, content, overwrite: true)
20
+ FileUtils.mkdir_p File.dirname filename unless File.directory? File.dirname(filename)
21
+ return puts "File '#{filename}' already exists, skipping..." if (File.exist?(filename) && !overwrite)
22
+
23
+ File.write filename, content
24
+ puts "Created file at #{filename}"
25
+ end
26
+
27
+ # @example Create a spec_helper file and test file in spec folder
28
+ # generate_files [ { spec: [ 'spec_helper.rb', 'limit_spec.rb' ] } ]
29
+ # @param [Hash] list_of_files Hash of files to generate for
30
+ def generate_files(binding, list_of_files, folder: nil)
31
+ return create_inner_file(folder, list_of_files, binding) unless list_of_files.respond_to? :each
32
+
33
+ list_of_files.each do |item|
34
+ if item.is_a? Hash # Go one level deeper
35
+ item.each do |inner_folder, sub_files|
36
+ inner_folder = inner_folder.to_s
37
+ current_folder = folder ? File.join(folder, inner_folder) : inner_folder
38
+ generate_files binding, sub_files, folder: current_folder
39
+ end
40
+ else
41
+ create_inner_file folder, item, binding
42
+ end
43
+ end
44
+ end
45
+
46
+ def create_inner_file(folder, name, binding)
47
+ item = name.to_s
48
+ path = folder ? File.join(folder, item) : item
49
+ generate_from_template path, binding
50
+ end
51
+
52
+ # Generate file from template
53
+ # @param [String] template_name Path to file with templates folder to use as template
54
+ # @param [Binding] binding Binding object used for ERB variables
55
+ def generate_from_template(template_name, binding)
56
+ content = read_template "#{template_name}.erb", binding
57
+ generate_file template_name, content, overwrite: false
58
+ end
59
+ end
60
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'soql_objects'
2
4
 
3
5
  module LeapSalesforce
@@ -29,8 +31,8 @@ module LeapSalesforce
29
31
  puts "#{picklists.count} picklists found"
30
32
  picklists.each do |picklist|
31
33
  @picklist = picklist
32
- @enum_name = picklist.tr(" '/()-", '')
33
- picklist_name = picklist.snakecase.tr(' ', '_')
34
+ @enum_name = picklist.tr(" '/()-", '').remove_macrons
35
+ picklist_name = picklist.to_key_name
34
36
  values = entity.picklist_for picklist
35
37
  @enum_values = {}
36
38
  values.each { |value| @enum_values[value.to_key_name] = value }
@@ -1,25 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
- require_relative 'default_fields'
4
+ require_relative 'default'
5
+ require_relative 'generator'
3
6
 
4
7
  module LeapSalesforce
5
8
  # Generators for creating code
6
9
  module Generator
7
- # @param [String] filename Relative filename to this file
8
- # @param [Binding] binding Binding object used for ERB variables
9
- # @return [String] Interpreted file after calculating ERB for template file passed
10
- def read_template(filename, binding)
11
- ERB.new(File.read(File.join(__dir__, 'templates', filename))).result(binding)
12
- end
13
-
14
- # Generate file creating necessary folder if necessary
15
- # @param [String] filename Name of file to generate
16
- # @param [String] content Content to put within file
17
- def generate_file(filename, content)
18
- FileUtils.mkdir_p File.dirname filename unless File.directory? File.dirname(filename)
19
- File.write filename, content
20
- puts "Created file at #{filename}"
21
- end
22
-
23
10
  # Creates SoqlObjects and related modules
24
11
  class SoqlObjects
25
12
  include Generator
@@ -27,23 +14,12 @@ module LeapSalesforce
27
14
  SOQL_OBJECT_FOLDER = File.join(LeapSalesforce.lib_folder, 'soql_data').freeze
28
15
  FACTORY_FOLDER = File.join(LeapSalesforce.lib_folder, 'factories').freeze
29
16
 
30
- # Extracts the soql_object defined in '.leap_salesforce.yml' and assigns instance variables
31
- def extract_info_from_object(soql_object)
32
- @class_name, @soql_object = case soql_object
33
- when Hash
34
- @create_enum = soql_object['create_enum'].nil? ? true : soql_object['create_enum']
35
- [soql_object.keys[0], soql_object.values[0] || soql_object.keys[0]]
36
- else
37
- [soql_object.to_s, soql_object.to_s]
38
- end
39
- end
40
-
41
17
  # Create temporary class for building API requests on
42
18
  def ensure_class_defined
43
- @soql_class = Object.const_get @class_name
19
+ @soql_class = Object.const_get @soql_object.class_name
44
20
  rescue NameError
45
- @soql_class = Object.const_set @class_name, Class.new(SoqlData)
46
- @soql_class.instance_variable_set(:@soql_object_name, @soql_object)
21
+ @soql_class = Object.const_set @soql_object.class_name, Class.new(SoqlData)
22
+ @soql_class.instance_variable_set(:@soql_object_name, @soql_object.backend_name)
47
23
  end
48
24
 
49
25
  # Generate Soql object file
@@ -52,10 +28,10 @@ module LeapSalesforce
52
28
  desc = @soql_class.description
53
29
  unless desc.soql_fields?
54
30
  raise LeapSalesforce::SetupError, "Error producing Soql data for '#{@soql_class}', soql table " \
55
- " '#{@soql_object}'. Error message: '#{desc.error_message}'"
31
+ " '#{@soql_object.backend_name}'. Error message: '#{desc.error_message}'"
56
32
  end
57
33
  content = read_template 'soql_object.rb.erb', binding
58
- file = File.join(SOQL_OBJECT_FOLDER, "#{@class_name.snakecase}.rb")
34
+ file = File.join(SOQL_OBJECT_FOLDER, "#{@soql_object.reference}.rb")
59
35
  generate_file file, content
60
36
  end
61
37
 
@@ -68,23 +44,19 @@ module LeapSalesforce
68
44
 
69
45
  # Generate factory for mass generating objects using FactoryBot
70
46
  def generate_factory
71
- class_method_name = @class_name.snakecase
72
- all_fields = @soql_class.fields
73
- @default_fields, @other_fields = if DefaultFields.respond_to? class_method_name
74
- all_fields.partition { |field| DefaultFields.send(class_method_name).include? field['name'] }
75
- else
76
- [[], all_fields]
77
- end
47
+ @default_fields, @other_fields = filter_fields
78
48
  content = read_template 'factory.rb.erb', binding
79
- file = File.join(FACTORY_FOLDER, "#{@class_name.snakecase}.rb")
49
+ file = File.join(FACTORY_FOLDER, "#{@soql_object.reference}.rb")
80
50
  generate_file file, content
81
51
  end
82
52
 
83
53
  # Generate soql_object and it's related modules, factories
84
54
  def create_all
85
- LeapSalesforce.soql_objects.each do |soql_object|
86
- extract_info_from_object soql_object
87
- @field_name_file = "#{@class_name.snakecase}_field_names"
55
+ puts "Generating Soql objects for #{LeapSalesforce.soql_objects.count} objects"
56
+ LeapSalesforce.soql_objects.each do |soql_object| # Soql object is now special class
57
+ # extract_info_from_object soql_object
58
+ @soql_object = soql_object
59
+ @field_name_file = "#{soql_object.reference}_field_names"
88
60
  generate_soql_object
89
61
  generate_field_module
90
62
  generate_factory
@@ -92,6 +64,19 @@ module LeapSalesforce
92
64
  `rubocop -a #{SOQL_OBJECT_FOLDER}`
93
65
  `rubocop -a #{FACTORY_FOLDER}`
94
66
  end
67
+
68
+ private
69
+
70
+ # @return [Array] Returns Array with first list being default fields for Factory and the 2nd being
71
+ # all other fields
72
+ def filter_fields
73
+ all_fields = @soql_class.fields
74
+ if Default::Fields.respond_to? @soql_object.reference
75
+ all_fields.partition { |field| Default::Fields.send(@soql_object.reference).include? field['name'] }
76
+ else
77
+ [[], all_fields]
78
+ end
79
+ end
95
80
  end
96
81
  end
97
82
  end
@@ -0,0 +1,9 @@
1
+ environment: <%= @environment %>
2
+ # lib_folder: lib/leap_salesforce # Default folder where assets will be stored
3
+ soql_objects:
4
+ - Case
5
+ - Contact
6
+ - Document: ContentDocument
7
+ - User:
8
+ create_enum: false # Example of indicating that enumerations are not required to be generated for
9
+ - Account
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'leap_salesforce'
4
+ gem 'rspec'
@@ -0,0 +1,8 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'leap_salesforce/rake'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ require 'leap_salesforce'
@@ -0,0 +1,3 @@
1
+ client_id: '<%= @client_id %>'
2
+ client_secret: '<%= @client_secret %>'
3
+ password: '<%= @password %>'
@@ -0,0 +1,4 @@
1
+ # Code specific to setting up the <%= @environment %> environment
2
+
3
+ Soaspec::OAuth2.debug_oauth = false # Turn this true if you need debug authentication
4
+ Soaspec::SpecLogger.output_to_terminal = false # Turn this to true if you want to see API traffic on the terminal
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add users to LeapSalesforce context. First user is the default
4
+ module LeapSalesforce
5
+ Users.add User.new <%= ":#{@user_key}" %>, '<%= @username %>'
6
+ end
@@ -1,12 +1,12 @@
1
1
  # Basic factory settings made according to values defined at
2
2
  # https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_case.htm
3
3
  FactoryBot.define do
4
- <%= "factory :#{@class_name.snakecase} do" %>
4
+ <%= "factory :#{@soql_object.reference} do" %>
5
5
  <% @default_fields.each do |field| %>
6
- <%= "#{field['label'].unused_ruby_name} { 'Content depending on #{field['type']}' }" %> <% end %>
6
+ <%= LeapSalesforce::Default::Factory.value_for(field, @soql_object.class_name) %> <% end %>
7
7
  trait :all do
8
8
  <% @other_fields.each do |field| %>
9
- <%= "#{field['label'].unused_ruby_name} { 'Content depending on #{field['type']}' }" %> <% end %>
9
+ <%= LeapSalesforce::Default::Factory.value_for(field, @soql_object.class_name) %> <% end %>
10
10
  end
11
11
  <%= 'end' %>
12
12
  end
@@ -1,7 +1,7 @@
1
1
  require_relative '<%= @field_name_file %>'
2
- # An <%= @class_name %> object mapping to a SOQL <%= @soql_object %>
3
- class <%= @class_name %> < SoqlData
4
- include <%= @class_name %>::Fields
5
- <%= "soql_object '#{@soql_object}'" unless @soql_object == @class_name %>
6
- <%= "create_enum false" if @create_enum == false %>
2
+ # An <%= @soql_object.class_name %> object mapping to a SOQL <%= @soql_object.backend_name %>
3
+ class <%= @soql_object.class_name %> < SoqlData
4
+ include <%= @soql_object.class_name %>::Fields
5
+ <%= "soql_object '#{@soql_object.backend_name}'" unless @soql_object.backend_name == @soql_object.class_name %>
6
+ <%= "create_enum false" if @soql_object.create_enum == false %>
7
7
  end
@@ -1,5 +1,5 @@
1
- # Fields for <%= @class_name %> mapped from SOQL <%= @soql_object %>
2
- class <%= @class_name %> < SoqlData
1
+ # Fields for <%= @soql_object.class_name %> mapped from SOQL <%= @soql_object.backend_name %>
2
+ class <%= @soql_object.class_name %> < SoqlData
3
3
  module Fields
4
4
  extend SoqlGlobalObjectData
5
5
  <% @soql_class.fields.each do |field| %>
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ # This file demonstrates how simple creation, reading updating and deletion (CRUD)
3
+ # can be done through LeapSalesforce classes
4
+ # Depending on validation rules and mandatory fields this may or may not work
5
+
6
+ RSpec.describe 'Contact CRUD' do
7
+ let(:uniq_value) { 'UNIQ FIRST NAME' }
8
+ let(:updated_value) { 'New Value' }
9
+ it 'Create using factory bot' do
10
+ @contact = FactoryBot.create(:contact)
11
+ end
12
+ it 'Read contact by name' do
13
+ FactoryBot.create(:contact, first_name: uniq_value)
14
+ @contact = Contact.find(FirstName: uniq_value)
15
+ retrieved_first_name = @contact.first_name
16
+ expect(retrieved_first_name).to eq uniq_value
17
+ end
18
+ it 'Updates contacts name' do
19
+ @contact = FactoryBot.create(:contact, first_name: uniq_value)
20
+ @contact.first_name = updated_value
21
+ expect(@contact.find.first_name).to eq updated_value
22
+ end
23
+ after { @contact.delete } # Delete data after each action. Comment out if you want data to remain
24
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ # This test demonstrates how limits can be checked for an organisation to ensure that memory is not run out of
3
+
4
+ RSpec.describe 'Limits' do
5
+ let(:soql_limits) { SoqlData.limits }
6
+ context 'Storage > 4MB' do
7
+ it 'data storage' do
8
+ expect(LeapSalesforce::Limits.remaining_for(:DataStorageMB)).to be > 4
9
+ end
10
+ it 'file storage' do
11
+ expect(LeapSalesforce::Limits.remaining_for(:FileStorageMB)).to be > 4
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'leap_salesforce'
4
+
5
+ LeapSalesforce.api_user = LeapSalesforce::Users.where(key: <%= ":#{@user_key}" %>)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LeapSalesforce
2
4
  # Handles retrieving limits of a Salesforce instance
3
5
  class Limits
@@ -5,8 +7,7 @@ module LeapSalesforce
5
7
  # @param [Symbol, String] limit_name Name of limit to find remaining amount for
6
8
  # @return [Integer] Finds remaining amount for a Salesforce limit
7
9
  def remaining_for(limit_name)
8
- limit_data = SoqlData.limits[limit_name]
9
- limit_data['Max'] - limit_data['Remaining']
10
+ SoqlData.limits[limit_name]['Remaining']
10
11
  end
11
12
  end
12
13
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'users/users'
4
+ require_relative 'soql_object'
4
5
 
5
6
  # Adding parameters to set for authentication
6
7
  module LeapSalesforce
@@ -8,6 +9,10 @@ module LeapSalesforce
8
9
  @lib_folder = File.join('lib', 'leap_salesforce').freeze
9
10
  @objects_to_verify = []
10
11
  @soql_objects = []
12
+ @client_id = ENV['client_id']
13
+ @client_secret = ENV['client_secret']
14
+ @password = ENV['password']
15
+ @environment = nil
11
16
  class << self
12
17
  # @return [String] Environment to use for tests. This can be accessed to change the username used to login
13
18
  # to test.salesforce with. This can be set on the command line with 'LEAP_ENV'
@@ -48,6 +53,13 @@ module LeapSalesforce
48
53
  # Changes to these values will need to be version controlled
49
54
  attr_accessor :objects_to_verify
50
55
  # @return [Array] List of Soql Objects identified for Leap Salesforce to maintain
51
- attr_accessor :soql_objects
56
+ attr_reader :soql_objects
57
+
58
+ # @return [Array] list_of_soql_objects Array describing Soql objects taken from .leap_salesforce.yml
59
+ def soql_objects=(list_of_soql_objects)
60
+ @soql_objects = list_of_soql_objects.collect do |soql_object_desc|
61
+ SoqlObject.new(soql_object_desc)
62
+ end
63
+ end
52
64
  end
53
65
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
-
5
3
  namespace :leaps do
6
4
  desc 'Create Enumeration objects for picklists from Salesforce Metadata'
7
5
  task :create_enums do