leap_salesforce 0.1.0

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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.idea/dictionaries/iqa.xml +9 -0
  4. data/.idea/leap-salesforce.iml +93 -0
  5. data/.idea/markdown-navigator/profiles_settings.xml +3 -0
  6. data/.idea/markdown-navigator.xml +86 -0
  7. data/.idea/misc.xml +12 -0
  8. data/.idea/modules.xml +8 -0
  9. data/.idea/vcs.xml +6 -0
  10. data/.idea/workspace.xml +992 -0
  11. data/.leap_salesforce.yml +10 -0
  12. data/.rspec +3 -0
  13. data/.rubocop.yml +3 -0
  14. data/CODE_OF_CONDUCT.md +74 -0
  15. data/Gemfile +6 -0
  16. data/LICENSE.txt +21 -0
  17. data/README.md +56 -0
  18. data/Rakefile +21 -0
  19. data/bin/console +12 -0
  20. data/bin/setup +8 -0
  21. data/exe/leap-salesforce +7 -0
  22. data/leap_salesforce.gemspec +43 -0
  23. data/lib/leap_salesforce/ext/string.rb +34 -0
  24. data/lib/leap_salesforce/ext/time.rb +15 -0
  25. data/lib/leap_salesforce/generator/default_fields.rb +13 -0
  26. data/lib/leap_salesforce/generator/soql_enums.rb +46 -0
  27. data/lib/leap_salesforce/generator/soql_objects.rb +97 -0
  28. data/lib/leap_salesforce/generator/templates/factory.rb.erb +12 -0
  29. data/lib/leap_salesforce/generator/templates/picklist.rb.erb +30 -0
  30. data/lib/leap_salesforce/generator/templates/soql_object.rb.erb +7 -0
  31. data/lib/leap_salesforce/generator/templates/soql_object_field_names.rb.erb +10 -0
  32. data/lib/leap_salesforce/limits.rb +13 -0
  33. data/lib/leap_salesforce/parameters.rb +53 -0
  34. data/lib/leap_salesforce/rake/setup.rake +25 -0
  35. data/lib/leap_salesforce/rake.rb +5 -0
  36. data/lib/leap_salesforce/soql_data/data_relationships.rb +35 -0
  37. data/lib/leap_salesforce/soql_data/meta_data_handler.rb +11 -0
  38. data/lib/leap_salesforce/soql_data/soql_data.rb +173 -0
  39. data/lib/leap_salesforce/soql_data/soql_enum.rb +8 -0
  40. data/lib/leap_salesforce/soql_data/soql_global_data.rb +26 -0
  41. data/lib/leap_salesforce/soql_data/soql_global_object_data.rb +225 -0
  42. data/lib/leap_salesforce/soql_data/soql_handler.rb +39 -0
  43. data/lib/leap_salesforce/soql_data/soql_object_describe.rb +100 -0
  44. data/lib/leap_salesforce/soql_data/soql_settings.rb +31 -0
  45. data/lib/leap_salesforce/users/user.rb +27 -0
  46. data/lib/leap_salesforce/users/users.rb +25 -0
  47. data/lib/leap_salesforce/version.rb +5 -0
  48. data/lib/leap_salesforce.rb +63 -0
  49. metadata +292 -0
@@ -0,0 +1,10 @@
1
+ environment: uat
2
+ lib_folder: spec/support
3
+ soql_objects:
4
+ - Case
5
+ - Contact
6
+ - Document: ContentDocument
7
+ - User:
8
+ create_enum: false
9
+ - Role: Role__c
10
+ - Account
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ # Modifies RuboCop (Static analysis tool)
2
+ Metrics/LineLength:
3
+ Max: 160
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at leap.salesforce@integrationqa.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in leap_salesforce.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 IQA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # LeapSalesforce
2
+
3
+ Welcome to LeapSalesforce gem. This gem helps ones to perform integration tests on Salesforce. It reads the Metadata
4
+ from Salesforce and creates the foundation for API tests.
5
+
6
+ In the future it will also planned to be used to create page objects based on metadata to support UI testing.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'leap_salesforce'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install leap_salesforce
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Development
29
+
30
+ 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.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/leap-dojo/leap_salesforce. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
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).
45
+
46
+ # Examples
47
+
48
+ ```ruby
49
+ # deleting old contacts
50
+ objects = Contact.each_id_with CreatedDate: "<#{5.days.ago}"
51
+ puts objects.count
52
+ objects.each do |id|
53
+ puts "Deleting #{id}"
54
+ Contact.delete id
55
+ end
56
+ ```
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ require 'leap_salesforce/rake'
7
+
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task default: :spec
12
+
13
+ # TODO: This needs to be in one place
14
+ require 'leap_salesforce'
15
+ LeapSalesforce.api_user = LeapSalesforce::Users.where(key: :cet)
16
+
17
+ desc "Create stubs for dynamic methods so they're picked up by the IDE"
18
+ task :stub do
19
+ require 'topoisomerase'
20
+ Topoisomerase.create_stubs_based_on SoqlData
21
+ end
data/bin/console ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'leap_salesforce'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require 'pry'
11
+
12
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'leap/salesforce'
5
+
6
+ # Ask for test user details
7
+ #
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'leap_salesforce/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'leap_salesforce'
9
+ spec.version = LeapSalesforce::VERSION
10
+ spec.authors = ['IQA', 'Samuel Garratt']
11
+ spec.email = %w[samuel.garratt@integrationqa.com leap.salesforce@integrationqa.com]
12
+
13
+ spec.summary = 'Helps with setting up integrated automated test frameworks
14
+ against Salesforce.'
15
+ spec.description = 'This gem helps ones to perform integration tests on Salesforce.
16
+ It reads the Metadata from Salesforce and creates the foundation for API tests.'
17
+ spec.homepage = 'https://gitlab.com/leap-dojo/leap_salesforce'
18
+ spec.license = 'MIT'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 2.0'
30
+ spec.add_development_dependency 'faker'
31
+ spec.add_development_dependency 'pry'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'topoisomerase'
35
+ spec.add_dependency 'activerecord'
36
+ spec.add_dependency 'factory_bot'
37
+ spec.add_dependency 'rake'
38
+ spec.add_dependency 'require_all'
39
+ spec.add_dependency 'rubocop'
40
+ spec.add_dependency 'rubykeyword'
41
+ spec.add_dependency 'soaspec'
42
+ spec.add_dependency 'thor'
43
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nori/core_ext'
4
+ require 'rubykeyword'
5
+
6
+ # Override string object to provide convenience methods for Strings
7
+ class String
8
+ # @todo: Have method of replacing all
9
+ # @return [String] Remove many complex characters to make a key for a Ruby Hash that is usable
10
+ def to_key_name
11
+ tr(' ,', '_').tr("'/()-:", '').tr('&', '').gsub('<', 'gt').tr('ā', 'a').snakecase.gsub('__', '_')
12
+ end
13
+
14
+ # A ruby friendly method name that is not taken by keywords like 'class', 'alias'
15
+ # @return [String] Ruby friendly name that can be used as method name
16
+ def unused_ruby_name
17
+ name = to_key_name
18
+ name.keyword? ? "my_#{name}" : name
19
+ end
20
+
21
+ # @return [String] Zulu time stamp for string
22
+ def to_zulu_date_string
23
+ Time.parse(self).strftime('%Y-%m-%dT%H:%M:%S.000Z')
24
+ end
25
+
26
+ # @return [Boolean] Whether string can be parsed into a time
27
+ def type_of_time?
28
+ Time.parse self
29
+ rescue ArgumentError
30
+ false
31
+ else
32
+ true
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # adding additional methods to inbuit time object
4
+ class Time
5
+ # @return [String] String represents time in salesforce format
6
+ def salesforce_format
7
+ strftime('%Y-%m-%d')
8
+ end
9
+
10
+ # @param [String] date_string Date returned from salesforce
11
+ # @return [Time] Time object created from salesforce date String
12
+ def self.parse_salesforce(date_string)
13
+ mktime(*date_string.split('-'))
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module LeapSalesforce
2
+ module DefaultFields
3
+ class << self
4
+ def contact
5
+ %w[FirstName LastName]
6
+ end
7
+
8
+ def account
9
+ ['Name']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ require_relative 'soql_objects'
2
+
3
+ module LeapSalesforce
4
+ # Generators for creating code
5
+ module Generator
6
+ # Creates Soql Enumerations / Picklists
7
+ class SoqlEnums
8
+ include Generator
9
+
10
+ ENUM_FOLDER = File.join(LeapSalesforce.lib_folder, 'metadata', 'enum').freeze
11
+
12
+ # Create Soql enumerations for all objects specified to verify
13
+ def create
14
+ if LeapSalesforce.objects_to_verify.empty?
15
+ raise LeapSalesforce::SetupError, 'LeapSalesforce.objects_to_verify is empty. ' \
16
+ 'Please set the list of objects you want to verify in .leap_salesforce:soql_objects ' \
17
+ 'and then run task "leaps:create_soql_objects" to create objects'
18
+ end
19
+
20
+ LeapSalesforce.objects_to_verify.each do |entity|
21
+ unless entity.create_enum?
22
+ puts "Skipping picklists for #{entity}"
23
+ next
24
+ end
25
+
26
+ puts "Creating picklists for #{entity}"
27
+ @entity_name = entity
28
+ picklists = entity.picklists
29
+ puts "#{picklists.count} picklists found"
30
+ picklists.each do |picklist|
31
+ @picklist = picklist
32
+ @enum_name = picklist.tr(" '/()-", '')
33
+ picklist_name = picklist.snakecase.tr(' ', '_')
34
+ values = entity.picklist_for picklist
35
+ @enum_values = {}
36
+ values.each { |value| @enum_values[value.to_key_name] = value }
37
+ content = read_template 'picklist.rb.erb', binding
38
+ file = File.join(ENUM_FOLDER, entity.to_s.snakecase, "#{picklist_name}.rb")
39
+ generate_file file, content
40
+ end
41
+ end
42
+ `rubocop -a #{ENUM_FOLDER}`
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,97 @@
1
+ require 'fileutils'
2
+ require_relative 'default_fields'
3
+
4
+ module LeapSalesforce
5
+ # Generators for creating code
6
+ 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
+ # Creates SoqlObjects and related modules
24
+ class SoqlObjects
25
+ include Generator
26
+
27
+ SOQL_OBJECT_FOLDER = File.join(LeapSalesforce.lib_folder, 'soql_data').freeze
28
+ FACTORY_FOLDER = File.join(LeapSalesforce.lib_folder, 'factories').freeze
29
+
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
+ # Create temporary class for building API requests on
42
+ def ensure_class_defined
43
+ @soql_class = Object.const_get @class_name
44
+ rescue NameError
45
+ @soql_class = Object.const_set @class_name, Class.new(SoqlData)
46
+ @soql_class.instance_variable_set(:@soql_object_name, @soql_object)
47
+ end
48
+
49
+ # Generate Soql object file
50
+ def generate_soql_object
51
+ ensure_class_defined
52
+ desc = @soql_class.description
53
+ unless desc.soql_fields?
54
+ raise LeapSalesforce::SetupError, "Error producing Soql data for '#{@soql_class}', soql table " \
55
+ " '#{@soql_object}'. Error message: '#{desc.error_message}'"
56
+ end
57
+ content = read_template 'soql_object.rb.erb', binding
58
+ file = File.join(SOQL_OBJECT_FOLDER, "#{@class_name.snakecase}.rb")
59
+ generate_file file, content
60
+ end
61
+
62
+ # Generate module with fields for Soql Object
63
+ def generate_field_module
64
+ field_content = read_template 'soql_object_field_names.rb.erb', binding
65
+ field_file = File.join(SOQL_OBJECT_FOLDER, "#{@field_name_file}.rb")
66
+ generate_file field_file, field_content
67
+ end
68
+
69
+ # Generate factory for mass generating objects using FactoryBot
70
+ 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
78
+ content = read_template 'factory.rb.erb', binding
79
+ file = File.join(FACTORY_FOLDER, "#{@class_name.snakecase}.rb")
80
+ generate_file file, content
81
+ end
82
+
83
+ # Generate soql_object and it's related modules, factories
84
+ 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"
88
+ generate_soql_object
89
+ generate_field_module
90
+ generate_factory
91
+ end
92
+ `rubocop -a #{SOQL_OBJECT_FOLDER}`
93
+ `rubocop -a #{FACTORY_FOLDER}`
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,12 @@
1
+ # Basic factory settings made according to values defined at
2
+ # https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_case.htm
3
+ FactoryBot.define do
4
+ <%= "factory :#{@class_name.snakecase} do" %>
5
+ <% @default_fields.each do |field| %>
6
+ <%= "#{field['label'].unused_ruby_name} { 'Content depending on #{field['type']}' }" %> <% end %>
7
+ trait :all do
8
+ <% @other_fields.each do |field| %>
9
+ <%= "#{field['label'].unused_ruby_name} { 'Content depending on #{field['type']}' }" %> <% end %>
10
+ end
11
+ <%= 'end' %>
12
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helps handle picklist values for <%= "#{@entity_name}, #{@enum_name}" %>
4
+ class <%= @entity_name %> < SoqlData
5
+ # Enumeration for <%= @enum_name %>
6
+ module <%= @enum_name %>
7
+ include SoqlEnum
8
+ <% @enum_values.each do |name, value| %>
9
+ @<%= name.to_s %> = "<%= value %>"
10
+ <% end %>
11
+ class << self
12
+ # @return [String] Sample value from Enum
13
+ def sample
14
+ values.sample
15
+ end
16
+
17
+ # @return [String] Name of picklist as returned from Metadata
18
+ def name
19
+ '<%= @picklist %>'
20
+ end
21
+
22
+ # @return [Array] List of values for <%= @enum_name %>
23
+ def values
24
+ <%= @enum_values.values %>
25
+ end
26
+
27
+ attr_reader <%= @enum_values.keys.collect(&:to_sym).to_s.tr('[]','') %>
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,7 @@
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 %>
7
+ end
@@ -0,0 +1,10 @@
1
+ # Fields for <%= @class_name %> mapped from SOQL <%= @soql_object %>
2
+ class <%= @class_name %> < SoqlData
3
+ module Fields
4
+ extend SoqlGlobalObjectData
5
+ <% @soql_class.fields.each do |field| %>
6
+ # Element for '<%= field['label'] %>', type '<%= field['type'] %>'
7
+ soql_element :<%= field['label'].unused_ruby_name %>, '<%= field['name'] %>'
8
+ <% end %>
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module LeapSalesforce
2
+ # Handles retrieving limits of a Salesforce instance
3
+ class Limits
4
+ class << self
5
+ # @param [Symbol, String] limit_name Name of limit to find remaining amount for
6
+ # @return [Integer] Finds remaining amount for a Salesforce limit
7
+ def remaining_for(limit_name)
8
+ limit_data = SoqlData.limits[limit_name]
9
+ limit_data['Max'] - limit_data['Remaining']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'users/users'
4
+
5
+ # Adding parameters to set for authentication
6
+ module LeapSalesforce
7
+ @config_folder = 'config'
8
+ @lib_folder = File.join('lib', 'leap_salesforce').freeze
9
+ @objects_to_verify = []
10
+ @soql_objects = []
11
+ class << self
12
+ # @return [String] Environment to use for tests. This can be accessed to change the username used to login
13
+ # to test.salesforce with. This can be set on the command line with 'LEAP_ENV'
14
+ def environment
15
+ ENV['LEAP_ENV'] || @environment
16
+ end
17
+
18
+ # @param [String, LeapSalesforce::User] user User or email address of user
19
+ def api_user=(user)
20
+ @api_user = case user
21
+ when String then user
22
+ when LeapSalesforce::User then user.username
23
+ when :default then nil # Will then use first user defined
24
+ else
25
+ raise ArgumentError, "Unable to use class '#{user.class}' to set api_user"
26
+ end
27
+ end
28
+
29
+ # @return [String] Salesforce username used to execute API tests. This can be changed during tests
30
+ def api_user
31
+ @api_user || LeapSalesforce::Users.list.first.username
32
+ end
33
+
34
+ # @return [String] Folder where all configuration is stored. By default this is 'config'
35
+ attr_accessor :config_folder
36
+ # @return [String] Environment to use for tests. This can be accessed to change the username used to login
37
+ # to test.salesforce with
38
+ attr_writer :environment
39
+ # @return [String] Common API password. This assumes all users use the same password
40
+ attr_accessor :password
41
+ # @return [String] Client id in Salesforce OAuth app
42
+ attr_accessor :client_id
43
+ # @return [String] Client secret in Salesforce OAuth app
44
+ attr_accessor :client_secret
45
+ # @return [String] Path where library generated assets are stored. By default lib/leap_salesforce
46
+ attr_accessor :lib_folder
47
+ # @return [Array] List of objects to verify metadata for. This includes enums, required values
48
+ # Changes to these values will need to be version controlled
49
+ attr_accessor :objects_to_verify
50
+ # @return [Array] List of Soql Objects identified for Leap Salesforce to maintain
51
+ attr_accessor :soql_objects
52
+ end
53
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+
5
+ namespace :leaps do
6
+ desc 'Create Enumeration objects for picklists from Salesforce Metadata'
7
+ task :create_enums do
8
+ require_relative '../generator/soql_enums'
9
+ LeapSalesforce::Generator::SoqlEnums.new.create
10
+ end
11
+
12
+ desc 'Create Soql Data objects'
13
+ task :create_soql_objects do
14
+ require_relative '../generator/soql_objects'
15
+ LeapSalesforce::Generator::SoqlObjects.new.create_all
16
+ end
17
+
18
+ # TODO: This does not work
19
+ desc 'Create objects, fields, enums'
20
+ task create_all: :create_soql_objects do
21
+ # require_all LeapSalesforce.lib_folder
22
+ LeapSalesforce.objects_to_verify = SoqlData.descendants
23
+ Rake::Task['leaps:create_enums'].invoke
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ import File.join(__dir__, 'rake', 'setup.rake')
4
+
5
+ # Dir.glob('rake/*.rake').each(&method(:import))