module RestforceMock::Sandbox
Public Class Methods
add_object(name, id, values)
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 4 def self.add_object(name, id, values) if storage[name] && !storage[name][id].nil? raise "Object #{name} with #{id} exists" end storage[name].merge!({ id => values }) end
client()
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 67 def self.client ::Restforce.new end
find_object(query)
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 27 def self.find_object(query) # This will only support making queries in this format: # client.query("Select Id FROM Contact WHERE Email = 'debrah.obrian@yahoo.com'") split_query = query.split storage_name = split_query[3] key = "#{split_query[5]}".to_sym val = split_query.last .gsub(/^'|'$/, '') .gsub('\\', '') if storage[storage_name].has_value?( key => val) return storage[storage_name].keys.first end end
get_object(name, id)
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 19 def self.get_object(name, id) storage[name][id] end
initialize()
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 71 def self.initialize storage = Hash.new do |hash, object| hash[object]={} end storage[:schema] = Hash.new do |hash, object| hash[object]={} end end
reset!()
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 53 def self.reset! $restforce_mock_storage = initialize end
storage()
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 57 def self.storage $restforce_mock_storage ||= initialize end
update_object(name, id, attrs)
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 44 def self.update_object(name, id, attrs) current = storage[name][id] storage[name][id] = current.merge(attrs) end
update_schema(object_name)
click to toggle source
Private
# File lib/restforce_mock/sandbox.rb, line 62 def self.update_schema(object_name) s = RestforceMock::SchemaManager.new storage[:schema][object_name] = s.get_schema(object_name) end
validate_all_present_fields!(current, attrs)
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 80 def self.validate_all_present_fields!(current, attrs) missing = attrs.keys - current.keys unless missing.length == 0 raise Faraday::Error::ResourceNotFound.new( "INVALID_FIELD_FOR_INSERT_UPDATE: Unable to create/update fields: #{missing}." + " Please check the security settings of this field and verify that it is " + "read/write for your profile or permission set") end end
Public Instance Methods
add_object(name, id, values)
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 11 def add_object(name, id, values) RestforceMock::Sandbox.add_object(name, id, values) end
get_object(name, id)
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 15 def get_object(name, id) RestforceMock::Sandbox.get_object(name, id) end
get_object_from_query(query)
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 23 def get_object_from_query(query) RestforceMock::Sandbox.find_object(query) end
update_object(name, id, attrs)
click to toggle source
# File lib/restforce_mock/sandbox.rb, line 49 def update_object(name, id, attrs) RestforceMock::Sandbox.update_object(name, id, attrs) end