Class: LeapSalesforce::User
- Inherits:
-
Object
- Object
- LeapSalesforce::User
- Defined in:
- lib/leap_salesforce/users/user.rb
Overview
A test user used to execute tests TODO: Handle approach of assigning a profile including role hierarchy.
I.e, Sales user and Sales Manager have one role but different position
Instance Attribute Summary collapse
-
#description ⇒ String
Long form description of user.
-
#key ⇒ String
Name to identify user by.
-
#security_token ⇒ String
Security token of user.
-
#username ⇒ String
Username of User interpreted by ERB (in email address format).
Instance Method Summary collapse
-
#exists? ⇒ Boolean
Query for user in Salesforce instance.
-
#first_name ⇒ String
First name of user.
-
#initialize(*user_params, description: nil) ⇒ User
constructor
A new instance of User.
-
#match?(field, criteria) ⇒ Boolean
Whether key and criteria match current user.
- #password=(password) ⇒ Object
-
#reset_password(password = nil) ⇒ Object
Using developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_user_password.htm @todo: Setting temp password is currently not working.
-
#soql_object ⇒ User
Salesforce soql object for User.
Constructor Details
#initialize(*user_params, description: nil) ⇒ User
Returns a new instance of User.
23 24 25 26 27 28 |
# File 'lib/leap_salesforce/users/user.rb', line 23 def initialize(*user_params, description: nil) self.key = user_params[0] self.username = user_params[1] self.security_token = ENV["#{key}_token"] || nil self.description = description end |
Instance Attribute Details
#description ⇒ String
Returns Long form description of user. Could be used to reference them where a human readable format is required such as in a Cucumber test.
15 16 17 |
# File 'lib/leap_salesforce/users/user.rb', line 15 def description @description end |
#key ⇒ String
Returns Name to identify user by.
9 10 11 |
# File 'lib/leap_salesforce/users/user.rb', line 9 def key @key end |
#security_token ⇒ String
Returns Security token of user. Recommend this be set through ENV variable.
18 19 20 |
# File 'lib/leap_salesforce/users/user.rb', line 18 def security_token @security_token end |
#username ⇒ String
Returns Username of User interpreted by ERB (in email address format). Use ERB to define users that can vary according to environment.
48 49 50 51 52 |
# File 'lib/leap_salesforce/users/user.rb', line 48 def username raise LeapSalesforce::SetupError, "User #{inspect} has no username" if @username.nil? || @username.empty? ERB.new(@username).result(binding) end |
Instance Method Details
#exists? ⇒ Boolean
Query for user in Salesforce instance
42 43 44 |
# File 'lib/leap_salesforce/users/user.rb', line 42 def exists? admin_query_user { ::User.any?(username: username) } end |
#first_name ⇒ String
Returns First name of user.
36 37 38 |
# File 'lib/leap_salesforce/users/user.rb', line 36 def first_name admin_query_user { soql_object.first_name } end |
#match?(field, criteria) ⇒ Boolean
Returns Whether key and criteria match current user.
81 82 83 84 85 86 87 88 |
# File 'lib/leap_salesforce/users/user.rb', line 81 def match?(field, criteria) actual_value = send(field.to_s) case criteria when Regexp then !actual_value[criteria].nil? else actual_value == criteria end end |
#password=(password) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/leap_salesforce/users/user.rb', line 55 def password=(password) user = ::User.find(username: username) set = ::User.new("Set password for #{username}, #{user.id} to '#{password}'", method: :post, suburl: "sobjects/User/#{user.id}/password", body: { NewPassword: password }) set.successful? end |
#reset_password(password = nil) ⇒ Object
Using developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_user_password.htm @todo: Setting temp password is currently not working. Need to investigate
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/leap_salesforce/users/user.rb', line 66 def reset_password(password = nil) admin_query_user do user = ::User.find(username: username) params = { method: :delete, suburl: "sobjects/User/#{user.id}/password" } params.merge!(body: { NewPassword: password }) if password reset = ::User.new("Reset password for #{username}, #{user.id} to '#{password}'", **params) reset.successful? return reset[:NewPassword] end end |
#soql_object ⇒ User
Returns Salesforce soql object for User.
31 32 33 |
# File 'lib/leap_salesforce/users/user.rb', line 31 def soql_object admin_query_user { ::User.find username: username } end |