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
@@ -9,27 +9,27 @@ module DataRelationships
9
9
  def organisation
10
10
  raise '"Organisation" class not yet defined' unless defined? Organisation
11
11
 
12
- Organisation.get(Id: self['AccountId'])
12
+ Organisation.find(Id: self['AccountId'])
13
13
  end
14
14
 
15
15
  # @example Get user name
16
16
  # record.owner.name
17
17
  # @return [Exchange] object representing owner of object
18
18
  def owner
19
- User.get(Id: self[:owner_id])
19
+ User.find(Id: self[:owner_id])
20
20
  end
21
21
 
22
22
  # @example Get user name
23
23
  # record.queue.name
24
24
  # @return [Exchange] object representing owner of object
25
25
  def queue
26
- Group.get(Id: self[:owner_id])
26
+ Group.find(Id: self[:owner_id])
27
27
  end
28
28
 
29
29
  # Retrieve record type for current object
30
30
  def record_type
31
31
  raise '"RecordType" class not yet defined' unless defined? RecordType
32
32
 
33
- RecordType.get(Id: self['RecordTypeId'])
33
+ RecordType.find(Id: self['RecordTypeId'])
34
34
  end
35
35
  end
@@ -79,8 +79,8 @@ class SoqlData < Exchange
79
79
  # Get details of itself by searching for it's id
80
80
  # Store response within itself
81
81
  # @return [Exchange] Exchange with details of data
82
- def get
83
- @response = self.class.get(Id: id).response # Make get call and store result
82
+ def find
83
+ @response = self.class.find(Id: id).response # Make get call and store result
84
84
  self
85
85
  end
86
86
 
@@ -19,6 +19,8 @@ module SoqlGlobalData
19
19
  # objects.size
20
20
  # @example Find description of object with label Organisation
21
21
  # org_desc = SoqlData.global_describe['sobjects'].find { |obj| obj['label'] == 'Organisation' }
22
+ # @example Find names of all objects that include 'File' in their label
23
+ # SoqlData.global_describe['sobjects'].find_all { |obj| obj['label'].include? 'File' }.collect { |f| f['name'] }
22
24
  # @return [Exchange] Global describe of salesforce Objects
23
25
  def global_describe
24
26
  @global_describe ||= new('Global describe of sobjects', method: :get, suburl: 'sobjects/')
@@ -63,21 +63,26 @@ module SoqlGlobalObjectData
63
63
  query
64
64
  end
65
65
 
66
- # Get the response data for a SoqlObject using the calling class's table.
66
+ # Find the data for a single SoqlObject using the calling class's table.
67
67
  # Will get the latest created date.
68
- # @example
69
- # # Get a contact where LastName is 'Bob'
70
- # Contact.get(LastName: 'Bob')
68
+ # @example Get a contact where LastName is 'Bob'
69
+ # Contact.find(LastName: 'Bob')
70
+ # @example Get a contact that includes 'Test' in their first name
71
+ # Contact.find(~FirstName: '~%Test%')
72
+ # @example Get a contact created 10 days ago
73
+ # Contact.find CreatedDate: "<#{10.days.ago}"
71
74
  # @param [Hash] lookup Key value pair unique to Salesforce to query for
72
75
  # @option lookup [Boolean] :teardown Whether to remove id after scenario finished
73
76
  # @return [SoqlData]
74
- def get(lookup)
77
+ def find(lookup)
75
78
  teardown = lookup.delete(:teardown)
79
+ wait = lookup.delete(:wait) || true
76
80
  SoqlHandler.new("Query on #{self}").use
77
81
  instance_to_get = if lookup.key? :Id
78
82
  new("Lookup id: #{lookup[:Id]}", method: :get, suburl: "sobjects/#{soql_object_name}/#{lookup[:Id]}")
79
83
  else
80
- initial_query = query "SELECT Id FROM #{soql_object_name} #{soql_lookup_filter(lookup)}"
84
+ initial_query = query "SELECT Id FROM #{soql_object_name} #{soql_lookup_filter(lookup)}",
85
+ wait: wait
81
86
  data_from_url initial_query['$..url'], lookup
82
87
  end
83
88
  SoqlData.ids_to_delete[self] = instance_to_get[:id] if teardown
@@ -124,7 +129,7 @@ module SoqlGlobalObjectData
124
129
  # @return [Array] List of Soql objects matching criteria
125
130
  def each_with(lookup)
126
131
  ids = each_id_with lookup
127
- ids.collect { |id| get(Id: id) }
132
+ ids.collect { |id| find(Id: id) }
128
133
  end
129
134
 
130
135
  # Remove all ids from table that match lookup criteria
@@ -191,7 +196,7 @@ module SoqlGlobalObjectData
191
196
  rescue NoElementAtPath
192
197
  raise diagnose_error if error_message?
193
198
 
194
- @response = get.response
199
+ @response = find.response
195
200
  self[backend_name]
196
201
  end
197
202
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LeapSalesforce
4
+ # Container for information regarding a SoqlObject
5
+ class SoqlObject
6
+ # @return [String] Ruby class name
7
+ attr_accessor :class_name
8
+ # @return [String] Salesforce backend name
9
+ attr_accessor :backend_name
10
+ # @return [String] Snakecase version of ruby class. Name for methods / files to refer to class as
11
+ attr_accessor :reference
12
+ # @return [String] Description of Soql object from '.leap_salesforce' YAML
13
+ attr_accessor :description
14
+ # @return [Boolean] Whether to create enumerations for object
15
+ attr_accessor :create_enum
16
+
17
+ # Create a representation of a Soql object from a description (usually in .leap_salesforce.yml)
18
+ def initialize(description)
19
+ self.description = description
20
+ interpret_description
21
+ self.reference = @class_name.snakecase
22
+ end
23
+
24
+ private
25
+
26
+ # Set attributes based on description
27
+ def interpret_description
28
+ if description.is_a? Hash
29
+ interpret_hash_description
30
+ else
31
+ self.backend_name = description.to_s
32
+ self.class_name = backend_name.tr(" '/()-", '').tr('ā', 'a')
33
+ self.create_enum = true
34
+ end
35
+ end
36
+
37
+ # Set attributes based on description where description is a Hash
38
+ def interpret_hash_description
39
+ self.create_enum = create_enum?
40
+ self.class_name = description.keys[0]
41
+ self.backend_name = description.values[0] || description.keys[0]
42
+ end
43
+
44
+ # @return [Boolean] Whether to create enum. Default is true.
45
+ def create_enum?
46
+ description['create_enum'].nil? ? true : description['create_enum']
47
+ end
48
+ end
49
+ end
@@ -23,5 +23,17 @@ module LeapSalesforce
23
23
  def username
24
24
  ERB.new(@username).result(binding)
25
25
  end
26
+
27
+ # @param [Symbol, String] field Field to check
28
+ # @param [Object, Regex] criteria Either object with same value or regex that has a match anywhere in string
29
+ # @return [Boolean] Whether key and criteria match current user
30
+ def match?(field, criteria)
31
+ actual_value = send(field.to_s)
32
+ case criteria
33
+ when Regexp then !actual_value[criteria].nil?
34
+ else
35
+ actual_value == criteria
36
+ end
37
+ end
26
38
  end
27
39
  end
@@ -8,17 +8,27 @@ module LeapSalesforce
8
8
  @list = []
9
9
  class << self
10
10
  # @return [Array] List of test users
11
- attr_reader :list
11
+ attr_accessor :list
12
12
 
13
- # @param [LeapSalesforce::User]
13
+ # @param [LeapSalesforce::User] user Test user to add to leap salesforce
14
14
  def add(user)
15
- @list << user
15
+ return @list << user if user.is_a? LeapSalesforce::User
16
+
17
+ unless user.is_a? Array
18
+ raise LeapSalesforce::UserError, "Incorrect type #{user.class} for user. Expected either " \
19
+ 'type LeapSalesforce::User or Array'
20
+ end
21
+
22
+ @list << User.new(*user)
16
23
  end
17
24
 
18
25
  # Return a user that meets the criteria
19
26
  def where(filter)
20
27
  lookup_key, lookup_value = filter.first
21
- @list.find { |user| user.send(lookup_key) == lookup_value }
28
+ user = @list.find { |user_queried| user_queried.match?(lookup_key, lookup_value) }
29
+ raise LeapSalesforce::UserError, "Unable to find user based on filer #{filter}" unless user
30
+
31
+ user
22
32
  end
23
33
  end
24
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LeapSalesforce
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -3,13 +3,16 @@
3
3
  require 'leap_salesforce/version'
4
4
 
5
5
  require 'soaspec'
6
+ Soaspec::OAuth2.refresh_token = :once # Save access token and reuse it
7
+ Soaspec.log_warnings = false # Log any API warnings
6
8
  require 'active_support/core_ext/integer/time' # Creating time objects
7
9
  require 'leap_salesforce/parameters'
8
10
  require 'leap_salesforce/ext/string'
9
11
  require 'leap_salesforce/ext/time'
10
12
  require 'require_all'
11
13
  require 'rake'
12
- require 'factory_bot'
14
+ require 'factory_bot' # For mass production of data
15
+ require 'faker' # For fake data
13
16
 
14
17
  module LeapSalesforce
15
18
  class Error < StandardError; end
@@ -17,6 +20,9 @@ module LeapSalesforce
17
20
  class ResponseError < StandardError; end
18
21
  # Error related to setup of test automation suite
19
22
  class SetupError < Error; end
23
+ # Error related to Test Users
24
+ class UserError < Error;
25
+ end
20
26
  end
21
27
 
22
28
  LEAP_CONFIG_FILE = '.leap_salesforce.yml'
@@ -52,12 +58,16 @@ end
52
58
  raise LeapSalesforce::SetupError, "LeapSalesforce.#{param} not set" if LeapSalesforce.send(param).nil?
53
59
  end
54
60
 
55
- require File.join(Dir.pwd, LeapSalesforce.config_folder, 'general')
56
- require File.join(Dir.pwd, LeapSalesforce.config_folder, 'environments', LeapSalesforce.environment)
61
+ config_folder = File.join(Dir.pwd, LeapSalesforce.config_folder)
62
+ general_file = File.join(config_folder, 'general')
63
+ specific_environment_file = File.join(config_folder, 'environments', LeapSalesforce.environment)
64
+ require general_file if File.exist? "#{general_file}.rb"
65
+ require specific_environment_file if File.exist? "#{specific_environment_file}.rb"
57
66
 
58
67
  require 'leap_salesforce/soql_data/soql_data'
59
68
  require 'leap_salesforce/limits'
60
69
 
70
+ FileUtils.mkdir_p LeapSalesforce.lib_folder unless Dir.exist? LeapSalesforce.lib_folder
61
71
  require_all LeapSalesforce.lib_folder
62
72
 
63
73
  LeapSalesforce.objects_to_verify = SoqlData.descendants if LeapSalesforce.objects_to_verify.empty?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leap_salesforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - IQA
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-07-15 00:00:00.000000000 Z
12
+ date: 2019-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -25,20 +25,6 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '2.0'
28
- - !ruby/object:Gem::Dependency
29
- name: faker
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: pry
44
30
  requirement: !ruby/object:Gem::Requirement
@@ -54,41 +40,41 @@ dependencies:
54
40
  - !ruby/object:Gem::Version
55
41
  version: '0'
56
42
  - !ruby/object:Gem::Dependency
57
- name: rake
43
+ name: rspec
58
44
  requirement: !ruby/object:Gem::Requirement
59
45
  requirements:
60
46
  - - "~>"
61
47
  - !ruby/object:Gem::Version
62
- version: '10.0'
48
+ version: '3.0'
63
49
  type: :development
64
50
  prerelease: false
65
51
  version_requirements: !ruby/object:Gem::Requirement
66
52
  requirements:
67
53
  - - "~>"
68
54
  - !ruby/object:Gem::Version
69
- version: '10.0'
55
+ version: '3.0'
70
56
  - !ruby/object:Gem::Dependency
71
- name: rspec
57
+ name: topoisomerase
72
58
  requirement: !ruby/object:Gem::Requirement
73
59
  requirements:
74
- - - "~>"
60
+ - - ">="
75
61
  - !ruby/object:Gem::Version
76
- version: '3.0'
62
+ version: '0'
77
63
  type: :development
78
64
  prerelease: false
79
65
  version_requirements: !ruby/object:Gem::Requirement
80
66
  requirements:
81
- - - "~>"
67
+ - - ">="
82
68
  - !ruby/object:Gem::Version
83
- version: '3.0'
69
+ version: '0'
84
70
  - !ruby/object:Gem::Dependency
85
- name: topoisomerase
71
+ name: activerecord
86
72
  requirement: !ruby/object:Gem::Requirement
87
73
  requirements:
88
74
  - - ">="
89
75
  - !ruby/object:Gem::Version
90
76
  version: '0'
91
- type: :development
77
+ type: :runtime
92
78
  prerelease: false
93
79
  version_requirements: !ruby/object:Gem::Requirement
94
80
  requirements:
@@ -96,7 +82,7 @@ dependencies:
96
82
  - !ruby/object:Gem::Version
97
83
  version: '0'
98
84
  - !ruby/object:Gem::Dependency
99
- name: activerecord
85
+ name: factory_bot
100
86
  requirement: !ruby/object:Gem::Requirement
101
87
  requirements:
102
88
  - - ">="
@@ -110,7 +96,7 @@ dependencies:
110
96
  - !ruby/object:Gem::Version
111
97
  version: '0'
112
98
  - !ruby/object:Gem::Dependency
113
- name: factory_bot
99
+ name: faker
114
100
  requirement: !ruby/object:Gem::Requirement
115
101
  requirements:
116
102
  - - ">="
@@ -214,11 +200,13 @@ email:
214
200
  - samuel.garratt@integrationqa.com
215
201
  - leap.salesforce@integrationqa.com
216
202
  executables:
217
- - leap-salesforce
203
+ - leap_salesforce
218
204
  extensions: []
219
205
  extra_rdoc_files: []
220
206
  files:
221
207
  - ".gitignore"
208
+ - ".gitlab-ci.yml"
209
+ - ".idea/.rakeTasks"
222
210
  - ".idea/dictionaries/iqa.xml"
223
211
  - ".idea/leap-salesforce.iml"
224
212
  - ".idea/markdown-navigator.xml"
@@ -231,24 +219,39 @@ files:
231
219
  - ".rspec"
232
220
  - ".rubocop.yml"
233
221
  - CODE_OF_CONDUCT.md
222
+ - ChangeLog
234
223
  - Gemfile
235
224
  - LICENSE.txt
236
225
  - README.md
237
226
  - Rakefile
238
227
  - bin/console
239
228
  - bin/setup
240
- - exe/leap-salesforce
229
+ - config/environments/prod.rb
230
+ - config/general.rb
231
+ - exe/leap_salesforce
241
232
  - leap_salesforce.gemspec
242
233
  - lib/leap_salesforce.rb
243
234
  - lib/leap_salesforce/ext/string.rb
244
235
  - lib/leap_salesforce/ext/time.rb
245
- - lib/leap_salesforce/generator/default_fields.rb
236
+ - lib/leap_salesforce/generator/default.rb
237
+ - lib/leap_salesforce/generator/exe_helpers.rb
238
+ - lib/leap_salesforce/generator/generator.rb
246
239
  - lib/leap_salesforce/generator/soql_enums.rb
247
240
  - lib/leap_salesforce/generator/soql_objects.rb
241
+ - lib/leap_salesforce/generator/templates/.leap_salesforce.yml.erb
242
+ - lib/leap_salesforce/generator/templates/.rspec.erb
243
+ - lib/leap_salesforce/generator/templates/Gemfile.erb
244
+ - lib/leap_salesforce/generator/templates/Rakefile.erb
245
+ - lib/leap_salesforce/generator/templates/config/credentials/salesforce_oauth2.yml.erb
246
+ - lib/leap_salesforce/generator/templates/config/environments/specific_file.rb.erb
247
+ - lib/leap_salesforce/generator/templates/config/general.rb.erb
248
248
  - lib/leap_salesforce/generator/templates/factory.rb.erb
249
249
  - lib/leap_salesforce/generator/templates/picklist.rb.erb
250
250
  - lib/leap_salesforce/generator/templates/soql_object.rb.erb
251
251
  - lib/leap_salesforce/generator/templates/soql_object_field_names.rb.erb
252
+ - lib/leap_salesforce/generator/templates/spec/crud_eg_spec.rb.erb
253
+ - lib/leap_salesforce/generator/templates/spec/limit_spec.rb.erb
254
+ - lib/leap_salesforce/generator/templates/spec/spec_helper.rb.erb
252
255
  - lib/leap_salesforce/limits.rb
253
256
  - lib/leap_salesforce/parameters.rb
254
257
  - lib/leap_salesforce/rake.rb
@@ -262,6 +265,7 @@ files:
262
265
  - lib/leap_salesforce/soql_data/soql_handler.rb
263
266
  - lib/leap_salesforce/soql_data/soql_object_describe.rb
264
267
  - lib/leap_salesforce/soql_data/soql_settings.rb
268
+ - lib/leap_salesforce/soql_object.rb
265
269
  - lib/leap_salesforce/users/user.rb
266
270
  - lib/leap_salesforce/users/users.rb
267
271
  - lib/leap_salesforce/version.rb
@@ -284,8 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
288
  - !ruby/object:Gem::Version
285
289
  version: '0'
286
290
  requirements: []
287
- rubyforge_project:
288
- rubygems_version: 2.7.9
291
+ rubygems_version: 3.0.4
289
292
  signing_key:
290
293
  specification_version: 4
291
294
  summary: Helps with setting up integrated automated test frameworks against Salesforce.
data/exe/leap-salesforce DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'leap/salesforce'
5
-
6
- # Ask for test user details
7
- #
@@ -1,13 +0,0 @@
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