leap_salesforce 0.2.24 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b9311c1afc5593fb4b3428de805b3a2a9c5a6e8331d827dd40b9d5b60e09d8d
4
- data.tar.gz: 9532ceffad0924438eb87b97378faeadd6729e27bc396439a4934f2ee71f71e7
3
+ metadata.gz: 3d80eff87ab1c75f73d0f99c2556837698e418c3be87ba611fc044602c262add
4
+ data.tar.gz: 3a6090439223eeaafdc9194e7e19649ab805abd52885071ddbacc54d9bfd7431
5
5
  SHA512:
6
- metadata.gz: 1c81db35151f84596e6d0b80815bebfdcf3f582be9ee2457eb46fe90b06bf989af780be6e9333dbf1de5bae3797193605849f54d87c7652f352ed741ceeb0cfc
7
- data.tar.gz: a8998c522c93ed383524758d91dceac18fd6fdf8af41f5db8db3f9898a3be93e6e6f03cb63dd0277bd9a4e404403ebe5929636278c3b92878df89c081be4ac5a
6
+ metadata.gz: 247b89d8a5059f353cee60834a25aa9c7d480df6a71bf2d262fe99023cdc536e44b670ff874793478e55a75ddf9443a62445e124b138c44d9ec772efd613fbbc
7
+ data.tar.gz: e05ae5ffee8f34badabdda8a1cb8814ba336df63848ccdb662e85439a1e85c44a59ce179354ea2d9790f7b79afb6ce035dabd8fd5d215b0f70393cfbf6ffe253
@@ -1,7 +1,7 @@
1
1
  include:
2
2
  - template: Code-Quality.gitlab-ci.yml
3
3
 
4
- image: ruby:2.6
4
+ image: ruby:2.7
5
5
 
6
6
  stages:
7
7
  - test
@@ -18,7 +18,7 @@ variables:
18
18
  pages:
19
19
  stage: deploy
20
20
  dependencies:
21
- - test
21
+ - test_2.7
22
22
  script:
23
23
  - mv coverage/ public
24
24
  artifacts:
@@ -600,25 +600,49 @@ pages:
600
600
  done
601
601
  }
602
602
 
603
- test:
603
+ function setup_integration_env() {
604
+ # Decrypt server key
605
+ openssl aes-256-cbc -d -md md5 -in assets/server.key.enc -out assets/server.key -k $SERVER_KEY_PASSWORD
606
+ ls -la assets
607
+ install_jq
608
+ install_salesforce_cli
609
+ # Integrated test
610
+ gem install bundler rake
611
+ bundle install
612
+ sfdx force:auth:jwt:grant --clientid "$SF_CONSUMER_KEY" --jwtkeyfile assets/server.key --username "$SF_USERNAME" --setdefaultdevhubusername --setalias HubOrg
613
+ }
614
+
615
+ test_2.6:
616
+ image: ruby:2.6
604
617
  stage: test
618
+ script:
619
+ - *sfdx_helpers
620
+ - setup_integration_env
621
+ - bundle exec rake check_oauth # Check OAuth
622
+ - bundle exec rake leaps:create_soql_objects
623
+ - bundle exec rake leaps:create_enums
624
+ - bundle exec rspec
625
+
626
+ test_2.7:
605
627
  script:
606
628
  # Decrypt server key
607
629
  - *sfdx_helpers
608
- - openssl aes-256-cbc -d -md md5 -in assets/server.key.enc -out assets/server.key -k $SERVER_KEY_PASSWORD
609
- - ls -la assets
610
- - install_jq
611
- - install_salesforce_cli
612
- # Integrated test
613
- - ruby -v
614
- - which ruby
615
- - gem install bundler rake
616
- - bundle install
617
- - sfdx force:auth:jwt:grant --clientid "$SF_CONSUMER_KEY" --jwtkeyfile assets/server.key --username "$SF_USERNAME" --setdefaultdevhubusername --setalias HubOrg
630
+ - setup_integration_env
618
631
  - bundle exec rake check_oauth # Check OAuth
619
632
  - bundle exec rake leaps:create_soql_objects
620
633
  - bundle exec rake leaps:create_enums
621
- - bundle exec rspec_booster --job $CI_NODE_INDEX/$CI_NODE_TOTAL
634
+ - bundle exec rspec
622
635
  artifacts:
623
636
  paths:
624
637
  - coverage/
638
+
639
+ test_3.0:
640
+ image: ruby:3.0
641
+ script:
642
+ # Decrypt server key
643
+ - *sfdx_helpers
644
+ - setup_integration_env
645
+ - bundle exec rake check_oauth # Check OAuth
646
+ - bundle exec rake leaps:create_soql_objects
647
+ - bundle exec rake leaps:create_enums
648
+ - bundle exec rspec
@@ -6,9 +6,15 @@ soql_objects:
6
6
  - Contact
7
7
  - Document: ContentDocument
8
8
  - User:
9
- create_enum: true # Set this to false to not track enums for object
10
- - Group
9
+ create_enum:
10
+ exclude:
11
+ - Time
12
+ - Group:
13
+ create_enum: false # Set this to false to not track enums for object
11
14
  - Broker: Broker__c
12
- - Account
15
+ - Account:
16
+ create_enum:
17
+ exclude:
18
+ - Rating
13
19
  - Attachment
14
20
  - EventLogFile
@@ -1,3 +1,17 @@
1
1
  # Modifies RuboCop (Static analysis tool)
2
- Metrics/LineLength:
3
- Max: 160
2
+ Layout/LineLength:
3
+ Max: 160
4
+ Layout/SpaceAroundMethodCallOperator:
5
+ Enabled: true
6
+ Lint/RaiseException:
7
+ Enabled: true
8
+ Lint/StructNewOverride:
9
+ Enabled: true
10
+ Style/ExponentialNotation:
11
+ Enabled: true
12
+ Style/HashEachMethods:
13
+ Enabled: true
14
+ Style/HashTransformKeys:
15
+ Enabled: true
16
+ Style/HashTransformValues:
17
+ Enabled: true
data/ChangeLog CHANGED
@@ -1,3 +1,28 @@
1
+ Version 1.0.1
2
+ * Bug fix
3
+ * Fix #28 allowing !nil for query by non null values
4
+
5
+ Version 1.0.0
6
+ * Enhancement
7
+ * Disable rubocop output for pending ops when creating/fixing files
8
+ * Specify that working with Ruby 3 is a work in progress
9
+
10
+ Version 0.2.28
11
+ * Enhancement
12
+ * Make exclude method able to use class name in exclusion filter (hence easier to use)
13
+
14
+ Version 0.2.27
15
+ * Bug fix
16
+ * Patch to update deprecated `create_enum` method so it allows 1 parameter
17
+
18
+ Version 0.2.26
19
+ * Enhancement
20
+ * Create method to exclude picklists being created based on regexp in .leap_salesforce.yml
21
+
22
+ Version 0.2.25
23
+ * Enhancement
24
+ * `execute_as` user method that raises error if user not present
25
+
1
26
  Version 0.2.24
2
27
  * Bug fix
3
28
  * Handle metadata label name that is the same name as a method on SoqlData (which one would not want overwriting)
@@ -210,4 +235,4 @@ Version 0.1.1
210
235
  * Suggestions for generated factory
211
236
  * Begin unit tests
212
237
  * Handle Macrons by ensuring they're not copied into Ruby names / Modules
213
- * Created executable
238
+ * Created executable
data/PITCHME.md CHANGED
@@ -80,7 +80,7 @@ metadata.
80
80
  @[3](Declare what it is you're testing)
81
81
  @[5](Define what 'it' is, a the object under test must do)
82
82
  @[6](Create an instance of the object class - nothing sent to Salesforce yet)
83
- @[7-8](Set the first and last name to random names)
83
+ @[4,7-8](Set the first and last name to random names)
84
84
  @[9](Create the object in Salesforce by sending request via API)
85
85
  @[10](Verify creation was successful)
86
86
  @[11](Verify first name set as expected)
@@ -92,8 +92,8 @@ metadata.
92
92
 
93
93
  ---?code=spec/integration/query_spec.rb&lang=ruby&title=Querying entities
94
94
 
95
- @[6](Find an object using a specific attribute specific value)
96
- @[19](Find an object using a comparator)
95
+ @[21](Find an object using a specific attribute specific value)
96
+ @[29-30](Find list of objects meeting condition)
97
97
 
98
98
  ---
99
99
 
data/README.md CHANGED
@@ -258,6 +258,10 @@ This method can be used directly with the backend name. E.g, `contact[:FieldName
258
258
  This method in turn sets a value of the `@override_parameters[:body]` variable within the entity.
259
259
  The value of request body can be interrogated with `entity.request_parameters.body`.
260
260
 
261
+ ##### Logging
262
+
263
+ By default, API traffic will be logged in a log file in a `logs` folder.
264
+
261
265
  ### CRUD of data
262
266
 
263
267
  To work data in Salesforce, an object inheriting from the `SoqlData` class is always used. The idea is
@@ -560,3 +564,5 @@ Everyone interacting in the LeapSalesforce project’s codebases, issue trackers
560
564
 
561
565
  * Presentation on this library [here](https://gitpitch.com/leap-dojo/leap_salesforce?grs=gitlab)
562
566
  * Example of this library within a CI/CD pipeline [here](https://gitlab.com/iqa_public/labs/salesforce_cicd_demo)
567
+ * Using `leap_salesforce` to download event log files [here](https://gitlab.com/samuel-garratt/leap_salesforce_event_log_files)
568
+
data/Rakefile CHANGED
@@ -34,3 +34,21 @@ YARD::Doctest::RakeTask.new do |task|
34
34
  # TODO: Get all examples working in this way
35
35
  task.pattern = 'lib/leap_salesforce/ext/string.rb'
36
36
  end
37
+
38
+ desc 'Task to enter pry terminal and types commands using the standard library code'
39
+ task :pry do
40
+ require 'pry'
41
+ Pry.start
42
+ end
43
+
44
+ desc 'Example of cleaning up data'
45
+ task :remove_contacts do
46
+ contacts = Contact.where first_name: '!null'
47
+ puts "Deleting #{contacts.size} contacts"
48
+ contacts.each do |contact|
49
+ contact.delete
50
+ print '.'
51
+ end
52
+ contacts = Contact.where first_name: '!null'
53
+ puts "#{contacts.size} contacts left"
54
+ end
@@ -28,7 +28,10 @@ module LeapSalesforce
28
28
  # @param [LeapSalesforce::SoqlData] entity An object representing an object in Salesforce
29
29
  # Object inheriting from SoqlData that has picklists underneath it
30
30
  def create_picklists_for(entity)
31
- unless entity.create_enum?
31
+ soql_object = LeapSalesforce.soql_objects.find { |so| so.class_name == entity.to_s }
32
+ raise "Could not find soql object for '#{entity}'" unless soql_object
33
+
34
+ unless soql_object.create_enum != false
32
35
  puts "Skipping picklists for #{entity}"
33
36
  return
34
37
  end
@@ -36,7 +39,13 @@ module LeapSalesforce
36
39
  @entity_name = entity
37
40
  picklists = entity.picklists
38
41
  puts "#{picklists.count} picklists found"
39
- picklists.each { |picklist| generate_picklist_file picklist }
42
+ picklists.each do |picklist|
43
+ if soql_object.excludes?(picklist)
44
+ puts "Excluding picklist '#{picklist}'"
45
+ else
46
+ generate_picklist_file picklist
47
+ end
48
+ end
40
49
  end
41
50
 
42
51
  # Generate file for a picklist from it's metadata
@@ -61,7 +70,7 @@ module LeapSalesforce
61
70
 
62
71
  # Clean up files generated for all picklists
63
72
  def cleanup_files_created
64
- `rubocop -a #{ENUM_FOLDER}`
73
+ `rubocop -a #{ENUM_FOLDER} --display-only-fail-level-offenses --enable-pending-cops`
65
74
  end
66
75
  end
67
76
  end
@@ -62,8 +62,8 @@ module LeapSalesforce
62
62
  generate_field_module
63
63
  generate_factory
64
64
  end
65
- `rubocop -a #{SOQL_OBJECT_FOLDER}`
66
- `rubocop -a #{FACTORY_FOLDER}`
65
+ `rubocop -a #{SOQL_OBJECT_FOLDER} --enable-pending-cops`
66
+ `rubocop -a #{FACTORY_FOLDER} --enable-pending-cops`
67
67
  end
68
68
 
69
69
  private
@@ -3,5 +3,4 @@ require_relative '<%= @field_name_file %>'
3
3
  class <%= @soql_object.class_name %> < SoqlData
4
4
  include <%= @soql_object.class_name %>::Fields
5
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
6
  end
@@ -4,8 +4,8 @@
4
4
  # Depending on validation rules and mandatory fields this may or may not work
5
5
 
6
6
  RSpec.describe 'Contact CRUD' do
7
- let(:uniq_value) { 'UNIQ FIRST NAME' }
8
- let(:updated_value) { 'New Value' }
7
+ let(:uniq_value) { "UNIQ #{Faker::Name.first_name} #{Faker::Name.middle_name}" }
8
+ let(:updated_value) { "New #{Faker::Name.first_name} #{Faker::Name.neutral_first_name}" }
9
9
  it 'Create using factory bot' do
10
10
  @contact = FactoryBot.create(:contact)
11
11
  end
@@ -150,7 +150,8 @@ module LeapSalesforce
150
150
  elsif value[0] == 'I' # 'N' not 2nd character
151
151
  ['=', value]
152
152
  elsif value[0] == '!'
153
- ['!=', value[1..-1]]
153
+ remaining = value[1..-1] == 'nil' ? 'null' : value[1..-1]
154
+ ['!=', remaining]
154
155
  else
155
156
  [value[0], value[1..-1]]
156
157
  end
@@ -14,18 +14,9 @@ module SoqlSettings
14
14
  @soql_object_name || to_s
15
15
  end
16
16
 
17
- # Whether to create enumerations for object when running generation tasks. By default this is true
18
- # For some objects you may want to use them without tracking their enumerations
19
- def create_enum(set)
20
- @create_enum = set
21
- end
22
-
23
- # @return [Boolean] Whether to create enum for object
24
- def create_enum?
25
- if @create_enum.nil?
26
- true # True by default
27
- else
28
- @create_enum
29
- end
17
+ # @deprecated Not used, setting in '.leap_salesforce.yml' controls this now
18
+ def create_enum(_set)
19
+ LeapSalesforce.logger.warn "Method 'create_enum' called when it is deprecated" \
20
+ " from #{caller_locations[0]}"
30
21
  end
31
22
  end
@@ -11,17 +11,42 @@ module LeapSalesforce
11
11
  attr_accessor :reference
12
12
  # @return [String] Description of Soql object from '.leap_salesforce' YAML
13
13
  attr_accessor :description
14
- # @return [Boolean] Whether to create enumerations for object
14
+ # @return [Boolean, Hash] Whether to create enumerations for object
15
15
  attr_accessor :create_enum
16
16
 
17
17
  # Create a representation of a Soql object from a description (usually in .leap_salesforce.yml)
18
- # @param [Hash, String]
18
+ # @example Specific Salesforce object 'Case' to be represented
19
+ # 'Case'
20
+ # @example Represent Broker object by class with different name
21
+ # { 'Broker' => Broker__c }
22
+ # @example Represent Group object, specifying to ignore enums
23
+ # {"Group"=>nil, "create_enum"=>true} }
24
+ # @example Represent User object, specifying to ignore enum with name of Timezone
25
+ # {"User"=>nil, "create_enum"=>{"exclude"=>["Timezone"]}}
26
+ # @param [Hash, String] description
19
27
  def initialize(description)
20
28
  self.description = description
21
29
  interpret_description
22
30
  self.reference = @class_name.snakecase
23
31
  end
24
32
 
33
+ # @param [String] picklist
34
+ # @return [Boolean] Whether picklist should be excluded from being generated
35
+ def excludes?(picklist)
36
+ if create_enum.is_a? Hash
37
+ if create_enum['exclude']
38
+ picklist_class = picklist.to_class_name
39
+ create_enum['exclude'].any? do |exclusion_list|
40
+ !picklist.to_s[Regexp.new(exclusion_list)].nil? || !picklist_class[Regexp.new(exclusion_list)].nil?
41
+ end
42
+ else
43
+ false
44
+ end
45
+ else
46
+ false
47
+ end
48
+ end
49
+
25
50
  private
26
51
 
27
52
  # Set attributes based on description
@@ -16,9 +16,9 @@ module LeapSalesforce
16
16
 
17
17
  # @param [String, Symbol] key Key used to identify a test user
18
18
  # @param [String] username Name used to login with user. In email address format.
19
- def initialize(key, username, description: nil)
20
- self.key = key
21
- self.username = username
19
+ def initialize(*user_params, description: nil)
20
+ self.key = user_params[0]
21
+ self.username = user_params[1]
22
22
  self.description = description
23
23
  end
24
24
 
@@ -23,18 +23,31 @@ module LeapSalesforce
23
23
  raise LeapSalesforce::UserError, "Incorrect type #{user.class} for user. Expected either " \
24
24
  'type LeapSalesforce::User or Array'
25
25
  end
26
+ if user[2]
27
+ desc = user[2].is_a?(Hash) ? user[2].values[0] : user[2].dup
28
+ user[2] = nil
29
+ end
26
30
 
27
- @list << User.new(*user)
31
+ @list << User.new(*user, description: desc)
28
32
  end
29
33
 
34
+ # @example Filter user by key of :admin
35
+ # where(key: :admin)
36
+ # @example Filter user by description containing Payroll
37
+ # where(description: /Payroll/)
38
+ # @example Filter user by username
39
+ # where(username: 'username@domain.com')
30
40
  # @param [Symbol, Hash, String, Regexp, LeapSalesforce::User] filter Filter to find users by
31
- # @param [Boolean] all Whether to return all users matching criteria, not just first
32
- # @return [LeapSalesforce::User, Array] A user that meets the criteria
33
- def where(filter, all: false)
34
- @all = all
41
+ # @param_key [Boolean] all Whether to return all users matching criteria, not just first
42
+ # @return [LeapSalesforce::User, Array] A user that meets the criteria.
43
+ # If all is true this returns array of users
44
+ def where(filter)
45
+ @all = false
35
46
  case filter
36
47
  when :default then list.first # Will then use first user defined
37
- when Hash then match_params filter
48
+ when Hash
49
+ @all = filter[:all] || false
50
+ match_params filter
38
51
  when String then match_params(username: filter)
39
52
  when Symbol then match_params(key: filter)
40
53
  when Regexp then match_params(description: filter)
@@ -49,7 +62,7 @@ module LeapSalesforce
49
62
  # Iterate through each user, narrowing on filter if provided
50
63
  def each(filter = nil)
51
64
  if filter
52
- where(filter, all: true).each { yield }
65
+ where({**filter, all: true}).each { yield }
53
66
  else
54
67
  list.each { yield }
55
68
  end
@@ -66,20 +79,26 @@ module LeapSalesforce
66
79
  @all ? users : users.first
67
80
  end
68
81
 
82
+ # @param [Symbol, Hash, String, Regexp, LeapSalesforce::User] filter Filter to find user by
83
+ # @return [Object] Result of block
84
+ def execute_as(filter)
85
+ current_user = LeapSalesforce.api_user
86
+ LeapSalesforce.api_user = LeapSalesforce::Users.where filter
87
+ result = yield
88
+ LeapSalesforce.api_user = current_user
89
+ result
90
+ end
91
+
69
92
  # Execute block as user matching filter if that user is present
70
93
  # If user is not present the current user will be used
71
94
  # @return [Object] Result of block
72
- def execute_as_if_present(filter)
95
+ def execute_as_if_present(user_filter)
73
96
  raise ArgumentError, 'Pass block to :execute_as_if_present method' unless block_given?
74
97
 
75
- current_user = LeapSalesforce.api_user
76
- if any? filter
77
- LeapSalesforce.api_user = LeapSalesforce::Users.where filter
78
- result = yield
79
- LeapSalesforce.api_user = current_user
80
- result
98
+ if any? user_filter
99
+ execute_as(user_filter) { yield }
81
100
  else
82
- LeapSalesforce.logger.warn "No user found user filter #{filter}, using '#{current_user}'"
101
+ LeapSalesforce.logger.warn "No user found user filter #{user_filter}, using '#{LeapSalesforce.api_user}'"
83
102
  yield
84
103
  end
85
104
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module LeapSalesforce
4
4
  # @return [String] Version of leap salesforce
5
- VERSION = '0.2.24'
5
+ VERSION = '1.0.1'
6
6
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leap_salesforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - IQA
8
8
  - Samuel Garratt
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-03-17 00:00:00.000000000 Z
12
+ date: 2021-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -355,7 +355,7 @@ homepage: https://gitlab.com/leap-dojo/leap_salesforce
355
355
  licenses:
356
356
  - MIT
357
357
  metadata: {}
358
- post_install_message:
358
+ post_install_message:
359
359
  rdoc_options: []
360
360
  require_paths:
361
361
  - lib
@@ -371,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
371
371
  version: '0'
372
372
  requirements: []
373
373
  rubygems_version: 3.0.6
374
- signing_key:
374
+ signing_key:
375
375
  specification_version: 4
376
376
  summary: Helps with setting up integrated automated test frameworks against Salesforce.
377
377
  test_files: []