Class: Zendesk2::UpdateOrganization

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/zendesk2/update_organization.rb

Instance Attribute Summary

Attributes included from Request

#params

Instance Method Summary collapse

Methods included from Request

#call, cistern_included, #data, #delete!, #error!, #find!, #html_url_for, included, #mock_response, #page, #page_params!, #page_params?, #pluralize, #real, #real_request, #request_body, #request_params, #request_path, #resources, #response, #timestamp, #url_for

Instance Method Details

#mockObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

#organizationObject



13
14
15
# File 'lib/zendesk2/update_organization.rb', line 13

def organization
  params.fetch('organization')
end

#organization_idObject



17
18
19
# File 'lib/zendesk2/update_organization.rb', line 17

def organization_id
  organization.fetch('id').to_i
end

#organization_paramsObject



9
10
11
# File 'lib/zendesk2/update_organization.rb', line 9

def organization_params
  @_organization_params ||= Cistern::Hash.slice(organization, *Zendesk2::CreateOrganization.accepted_attributes)
end