Sha256: 05dfc21c9b857f941237f71e373554ee84dad7825e93b003bf2ff25d1a6295a1

Contents?: true

Size: 1.36 KB

Versions: 10

Compression:

Stored size: 1.36 KB

Contents

class Zendesk2::Client
  class Real
    def create_organization(params={})
      request(
        :body   => {"organization" => params},
        :method => :post,
        :path   => "/organizations.json",
      )
    end
  end # Real

  class Mock
    def create_organization(_params={})
      params = Cistern::Hash.stringify_keys(_params)
      identity = self.class.new_id

      record = {
        "id"         => identity,
        "url"        => url_for("/organizations/#{identity}.json"),
        "created_at" => Time.now.iso8601,
        "updated_at" => Time.now.iso8601,
      }.merge(params)


      unless record["name"]
        error!(:invalid, details: { "name" => [ { "description" => "Name cannot be blank" } ]})
      end

      if self.data[:organizations].values.find { |o| o["name"] == record["name"]}
        error!(:invalid, details: {"name" => [ { "description" => "Name: has already been taken" } ]})
      end

      if record["external_id"] && self.data[:organizations].values.find { |o| o["external_id"] == record["external_id"] }
        error!(:invalid, details: {"name" => [ { "description" => "External has already been taken" } ]})
      end

      self.data[:organizations][identity] = record

      response(
        :method => :post,
        :body   => {"organization" => record},
        :path   => "/organizations.json"
      )
    end
  end # Mock
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
zendesk2-1.4.2 lib/zendesk2/client/requests/create_organization.rb
zendesk2-1.4.1 lib/zendesk2/client/requests/create_organization.rb
zendesk2-1.4.0 lib/zendesk2/client/requests/create_organization.rb
zendesk2-1.3.3 lib/zendesk2/client/requests/create_organization.rb
zendesk2-1.3.2 lib/zendesk2/client/requests/create_organization.rb
zendesk2-1.3.1 lib/zendesk2/client/requests/create_organization.rb
zendesk2-1.3.0 lib/zendesk2/client/requests/create_organization.rb
zendesk2-1.2.10 lib/zendesk2/client/requests/create_organization.rb
zendesk2-1.2.9 lib/zendesk2/client/requests/create_organization.rb
zendesk2-1.2.7 lib/zendesk2/client/requests/create_organization.rb