class Zendesk2::UpdateOrganization

Public Instance Methods

mock() click to toggle source
# File lib/zendesk2/update_organization.rb, line 21
def mock
  record = find!(:organizations, organization_id)

  other_organizations = cistern.data[:organizations].dup
  other_organizations.delete(organization_id)

  other_named_organization = other_organizations.values.find do |o|
    o['name'].casecmp(organization['name'].to_s.downcase).zero?
  end

  if organization['name'] && other_named_organization
    error!(:invalid, details: { 'name' => [{ 'description' => 'Name: has already been taken' }] })
  end

  other_external_organization = other_organizations.values.find do |o|
    o['external_id'].to_s.casecmp(organization['external_id'].to_s.downcase).zero?
  end

  if organization['external_id'] && other_external_organization
    error!(:invalid, details: { 'name' => [{ 'description' => 'External has already been taken' }] })
  end

  record.merge!(organization_params)

  mock_response('organization' => record)
end
organization() click to toggle source
# File lib/zendesk2/update_organization.rb, line 13
def organization
  params.fetch('organization')
end
organization_id() click to toggle source
# File lib/zendesk2/update_organization.rb, line 17
def organization_id
  organization.fetch('id').to_i
end
organization_params() click to toggle source
# File lib/zendesk2/update_organization.rb, line 9
def organization_params
  @_organization_params ||= Cistern::Hash.slice(organization, *Zendesk2::CreateOrganization.accepted_attributes)
end