Module: LeapSalesforce::Default::Factory
- Defined in:
- lib/leap_salesforce/generator/default.rb
Overview
Defaults for various objects within a Factory
Class Method Summary collapse
-
.set(value, use_quotes: nil) ⇒ String
String to set Factory field to value specified.
-
.value_for(field, class_name) ⇒ String
Default value for Factory.
Class Method Details
.set(value, use_quotes: nil) ⇒ String
Returns String to set Factory field to value specified.
9 10 11 12 13 14 15 |
# File 'lib/leap_salesforce/generator/default.rb', line 9 def set(value, use_quotes: nil) if use_quotes "#{@field['label'].unused_ruby_name} { '#{value}' }" else "#{@field['label'].unused_ruby_name} { #{value} }" end end |
.value_for(field, class_name) ⇒ String
Returns Default value for Factory.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/leap_salesforce/generator/default.rb', line 18 def value_for(field, class_name) @field = field case field['type'] when 'string' then set("Faker::Lorem.paragraph_by_chars(number: #{field['length']})") when 'id' then set('Best to not hard code this', use_quotes: true) when 'boolean' then set('true') when 'picklist' then set("#{class_name}::#{field['label'].to_class_name}.sample") when 'reference' return set(%{User.find(CreatedDate: "<#{0.days.ago}").id}) if field['name'] == 'OwnerId' soql_obj = LeapSalesforce.soql_objects.find { |so| so.backend_name == field['relationshipName'] }&.reference if soql_obj "association :#{@field['label'].unused_ruby_name}, factory: :#{soql_obj}" else "# Please add #{field['relationshipName']} to .leap_salesforce.yml (if it's a table) to create association for #{field['relationshipName']}" end else set("Content depending on #{field['type']}", use_quotes: true) end end |